xref: /aosp_15_r20/external/tensorflow/tensorflow/compiler/mlir/tensorflow/utils/import_utils.h (revision b6fb3261f9314811a0f4371741dbb8839866f948)
1 /* Copyright 2019 The TensorFlow Authors. All Rights Reserved.
2 
3 Licensed under the Apache License, Version 2.0 (the "License");
4 you may not use this file except in compliance with the License.
5 You may obtain a copy of the License at
6 
7     http://www.apache.org/licenses/LICENSE-2.0
8 
9 Unless required by applicable law or agreed to in writing, software
10 distributed under the License is distributed on an "AS IS" BASIS,
11 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 See the License for the specific language governing permissions and
13 limitations under the License.
14 ==============================================================================*/
15 
16 #ifndef TENSORFLOW_COMPILER_MLIR_TENSORFLOW_UTILS_IMPORT_UTILS_H_
17 #define TENSORFLOW_COMPILER_MLIR_TENSORFLOW_UTILS_IMPORT_UTILS_H_
18 
19 #include "absl/strings/string_view.h"
20 #include "tensorflow/core/lib/core/status.h"
21 #include "tensorflow/core/platform/protobuf.h"
22 
23 namespace tensorflow {
24 
25 // Reads text (.pbtext) or binary (.pb) format of a proto message from the given
26 // buffer. Returns error status of the file is not found or malformed proto.
27 // Note that text protos can only be parsed when full protobuf::Message protos
28 // are used, and will fail for protobuf::MessageLite protos.
29 Status LoadProtoFromBuffer(absl::string_view input, protobuf::Message* proto);
30 Status LoadProtoFromBuffer(absl::string_view input,
31                            protobuf::MessageLite* proto);
32 
33 // Reads text (.pbtext) or binary (.pb) format of a proto message from the given
34 // file path. Returns error status of the file is not found or malformed proto.
35 // Note that text protos can only be parsed when full protobuf::Message protos
36 // are used, and will fail for protobuf::MessageLite protos.
37 Status LoadProtoFromFile(absl::string_view input_filename,
38                          protobuf::Message* proto);
39 Status LoadProtoFromFile(absl::string_view input_filename,
40                          protobuf::MessageLite* proto);
41 
42 }  // namespace tensorflow
43 
44 #endif  // TENSORFLOW_COMPILER_MLIR_TENSORFLOW_UTILS_IMPORT_UTILS_H_
45