| 43 | |
| 44 | template <typename T> |
| 45 | Status ReadProtoFile(Env* env, const string& fname, T* proto, |
| 46 | bool binary_first) { |
| 47 | string out; |
| 48 | Status s = ReadFileToString(env, fname, &out); |
| 49 | if (!s.ok()) return s; |
| 50 | |
| 51 | if (binary_first) { |
| 52 | if (ReadBinaryProto(tensorflow::Env::Default(), fname, proto).ok()) { |
| 53 | return Status(); |
| 54 | } else if (protobuf::TextFormat::ParseFromString(out, proto)) { |
| 55 | return Status(); |
| 56 | } |
| 57 | } else { |
| 58 | if (protobuf::TextFormat::ParseFromString(out, proto)) { |
| 59 | return Status(); |
| 60 | } else if (ReadBinaryProto(tensorflow::Env::Default(), fname, proto).ok()) { |
| 61 | return Status(); |
| 62 | } |
| 63 | } |
| 64 | return errors::InvalidArgument("Cannot parse proto file."); |
| 65 | } |
| 66 | |
| 67 | void PrintHelp(); |
| 68 | |