Reads a string, submessage, or other variable-length field from a serialized proto. May read all or part of a repeated field.
| 337 | // serialized proto. |
| 338 | // May read all or part of a repeated field. |
| 339 | inline Status ReadBytes(CodedInputStream* input, int index, void* datap) { |
| 340 | tstring* data = reinterpret_cast<tstring*>(datap) + index; |
| 341 | |
| 342 | #ifdef USE_TSTRING |
| 343 | uint32 length; |
| 344 | if (!input->ReadVarint32(&length)) { |
| 345 | return errors::DataLoss("Failed reading bytes"); |
| 346 | } |
| 347 | |
| 348 | data->resize_uninitialized(length); |
| 349 | |
| 350 | if (!input->ReadRaw(data->data(), length)) { |
| 351 | return errors::DataLoss("Failed reading bytes"); |
| 352 | } |
| 353 | #else // USE_TSTRING |
| 354 | if (!WireFormatLite::ReadBytes(input, data)) { |
| 355 | return errors::DataLoss("Failed reading bytes"); |
| 356 | } |
| 357 | #endif // USE_TSTRING |
| 358 | return Status::OK(); |
| 359 | } |
| 360 | |
| 361 | // Reads a tag-delimited field (TYPE_GROUP) from a serialized proto, |
| 362 | // as a bytestring. |
no test coverage detected