| 503 | } |
| 504 | |
| 505 | Status ReadBinaryProto(Env* env, const string& fname, |
| 506 | ::tensorflow::protobuf::MessageLite* proto) { |
| 507 | std::unique_ptr<RandomAccessFile> file; |
| 508 | TF_RETURN_IF_ERROR(env->NewRandomAccessFile(fname, &file)); |
| 509 | std::unique_ptr<FileStream> stream(new FileStream(file.get())); |
| 510 | |
| 511 | ::tensorflow::protobuf::io::CodedInputStream coded_stream(stream.get()); |
| 512 | |
| 513 | if (!proto->ParseFromCodedStream(&coded_stream) || |
| 514 | !coded_stream.ConsumedEntireMessage()) { |
| 515 | TF_RETURN_IF_ERROR(stream->status()); |
| 516 | return errors::DataLoss("Can't parse ", fname, " as binary proto"); |
| 517 | } |
| 518 | return Status::OK(); |
| 519 | } |
| 520 | |
| 521 | Status WriteTextProto(Env* env, const string& fname, |
| 522 | const ::tensorflow::protobuf::Message& proto) { |