TensorFlow Serving C++ API Documentation
status_util.cc
1 /* Copyright 2018 Google Inc. 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 #include "tensorflow_serving/util/status_util.h"
17 
18 #include <string>
19 
20 namespace tensorflow {
21 namespace serving {
22 
23 StatusProto ToStatusProto(const Status& status) {
24  StatusProto status_proto;
25  status_proto.set_error_code(
26  static_cast<tensorflow::error::Code>(status.code()));
27  if (!status.ok()) {
28  status_proto.set_error_message(std::string(status.message()));
29  }
30  return status_proto;
31 }
32 
33 Status FromStatusProto(const StatusProto& status_proto) {
34  return status_proto.error_code() == tensorflow::error::OK
35  ? Status()
36  : Status(static_cast<absl::StatusCode>(status_proto.error_code()),
37  status_proto.error_message());
38 }
39 
40 } // namespace serving
41 } // namespace tensorflow