diff options
author | Peter Hawkins <phawkins@google.com> | 2016-11-08 17:31:47 -0800 |
---|---|---|
committer | TensorFlower Gardener <gardener@tensorflow.org> | 2016-11-08 17:41:59 -0800 |
commit | f09265c145055341e69129d0f8aa938bf2f68acb (patch) | |
tree | d377587b9e2abc2a6cf893590f4b430b16f15031 | |
parent | 15360c986e325912942169d7f1ff3847aee6d19b (diff) |
Add a WriteTextProto method that is analogous to WriteBinaryProto but for textual protobufs.
Change: 138586949
-rw-r--r-- | tensorflow/core/platform/env.cc | 13 | ||||
-rw-r--r-- | tensorflow/core/platform/env.h | 4 |
2 files changed, 17 insertions, 0 deletions
diff --git a/tensorflow/core/platform/env.cc b/tensorflow/core/platform/env.cc index 114fef1489..772496520b 100644 --- a/tensorflow/core/platform/env.cc +++ b/tensorflow/core/platform/env.cc @@ -311,6 +311,19 @@ Status ReadBinaryProto(Env* env, const string& fname, return Status::OK(); } +Status WriteTextProto(Env* env, const string& fname, + const ::tensorflow::protobuf::Message& proto) { +#if !defined(TENSORFLOW_LITE_PROTOS) + string serialized; + if (!::tensorflow::protobuf::TextFormat::PrintToString(proto, &serialized)) { + return errors::FailedPrecondition("Unable to convert proto to text."); + } + return WriteStringToFile(env, fname, serialized); +#else + return errors::Unimplemented("Can't write text protos with protolite."); +#endif +} + Status ReadTextProto(Env* env, const string& fname, ::tensorflow::protobuf::Message* proto) { #if !defined(TENSORFLOW_LITE_PROTOS) diff --git a/tensorflow/core/platform/env.h b/tensorflow/core/platform/env.h index fbda05ade1..787ebe654b 100644 --- a/tensorflow/core/platform/env.h +++ b/tensorflow/core/platform/env.h @@ -374,6 +374,10 @@ Status WriteBinaryProto(Env* env, const string& fname, Status ReadBinaryProto(Env* env, const string& fname, ::tensorflow::protobuf::MessageLite* proto); +/// Write the text representation of "proto" to the named file. +Status WriteTextProto(Env* env, const string& fname, + const ::tensorflow::protobuf::Message& proto); + /// Read contents of named file and parse as text encoded proto data /// and store into `*proto`. Status ReadTextProto(Env* env, const string& fname, |