Reads a tag-delimited field (TYPE_GROUP) from a serialized proto, as a bytestring.
| 361 | // Reads a tag-delimited field (TYPE_GROUP) from a serialized proto, |
| 362 | // as a bytestring. |
| 363 | inline Status ReadGroupBytes(CodedInputStream* input, int field_number, |
| 364 | int index, void* datap) { |
| 365 | // WireFormatLite::SkipField has an option to emit the |
| 366 | // skipped bytes to an output stream. We could do better by implementing our |
| 367 | // own scanner but this is simpler for now. |
| 368 | // TODO(nix): there is a faster way to grab TYPE_GROUP bytes by relying |
| 369 | // on input->IsFlat() == true and using input->GetDirectBufferPointer() |
| 370 | // with input->CurrentPosition(). |
| 371 | tstring* data = reinterpret_cast<tstring*>(datap) + index; |
| 372 | #ifdef USE_TSTRING |
| 373 | // TODO(dero): To mitigate the string to tstring copy, we can implement our |
| 374 | // own scanner as described above. We would first need to obtain the length |
| 375 | // in an initial pass and resize/reserve the tstring. But, given that |
| 376 | // TYPE_GROUP is deprecated and currently no tests in |
| 377 | // tensorflow/python/kernel_tests/proto:decode_proto_op_test target a |
| 378 | // TYPE_GROUP tag, we use std::string as a read buffer. |
| 379 | string buf; |
| 380 | StringOutputStream string_stream(&buf); |
| 381 | #else // USE_TSTRING |
| 382 | StringOutputStream string_stream(data); |
| 383 | #endif // USE_TSTRING |
| 384 | CodedOutputStream out(&string_stream); |
| 385 | if (!WireFormatLite::SkipField( |
| 386 | input, |
| 387 | WireFormatLite::MakeTag(field_number, |
| 388 | WireFormatLite::WIRETYPE_START_GROUP), |
| 389 | &out)) { |
| 390 | return errors::DataLoss("Failed reading group"); |
| 391 | } |
| 392 | #ifdef USE_TSTRING |
| 393 | *data = buf; |
| 394 | #endif // USE_TSTRING |
| 395 | return Status::OK(); |
| 396 | } |
| 397 | |
| 398 | // Reads a single field value from a CodedInputStream into a tensor. |
| 399 | inline Status ReadValue(CodedInputStream* input, |