• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* Copyright 2015 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_CORE_PLATFORM_PROTOBUF_H_
17 #define TENSORFLOW_CORE_PLATFORM_PROTOBUF_H_
18 
19 #include "tensorflow/core/platform/platform.h"
20 #include "tensorflow/core/platform/types.h"
21 
22 // Import whatever namespace protobuf comes from into the
23 // ::tensorflow::protobuf namespace.
24 //
25 // TensorFlow code should use the ::tensorflow::protobuf namespace to
26 // refer to all protobuf APIs.
27 
28 #ifndef TENSORFLOW_LITE_PROTOS
29 #include "google/protobuf/io/tokenizer.h"
30 #include "google/protobuf/descriptor.pb.h"
31 #include "google/protobuf/descriptor.h"
32 #include "google/protobuf/dynamic_message.h"
33 #include "google/protobuf/text_format.h"
34 #include "google/protobuf/util/json_util.h"
35 #include "google/protobuf/util/type_resolver_util.h"
36 #endif
37 
38 #include "google/protobuf/io/coded_stream.h"
39 #include "google/protobuf/io/zero_copy_stream.h"
40 #include "google/protobuf/io/zero_copy_stream_impl_lite.h"
41 #include "google/protobuf/arena.h"
42 #include "google/protobuf/map.h"
43 #include "google/protobuf/repeated_field.h"
44 
45 namespace tensorflow {
46 
47 namespace protobuf = ::google::protobuf;
48 using protobuf_int64 = ::google::protobuf::int64;
49 using protobuf_uint64 = ::google::protobuf::uint64;
50 extern const char* kProtobufInt64Typename;
51 extern const char* kProtobufUint64Typename;
52 
53 // Parses a protocol buffer contained in a string in the binary wire format.
54 // Returns true on success. Note: Unlike protobuf's builtin ParseFromString,
55 // this function has no size restrictions on the total size of the encoded
56 // protocol buffer.
57 bool ParseProtoUnlimited(protobuf::MessageLite* proto,
58                          const string& serialized);
59 bool ParseProtoUnlimited(protobuf::MessageLite* proto, const void* serialized,
60                          size_t size);
61 
62 // Returns the string value for the value of a string or bytes protobuf field.
ProtobufStringToString(const string & s)63 inline const string& ProtobufStringToString(const string& s) { return s; }
64 
65 // Set <dest> to <src>. Swapping is allowed, as <src> does not need to be
66 // preserved.
SetProtobufStringSwapAllowed(string * src,string * dest)67 inline void SetProtobufStringSwapAllowed(string* src, string* dest) {
68   *dest = std::move(*src);
69 }
70 
71 #if defined(TENSORFLOW_PROTOBUF_USES_CORD)
72 // These versions of ProtobufStringToString and SetProtobufString get used by
73 // tools/proto_text's generated code.  They have the same name as the versions
74 // in core/platform/protobuf.h, so the generation code doesn't need to determine
75 // if the type is Cord or string at generation time.
ProtobufStringToString(const Cord & s)76 inline string ProtobufStringToString(const Cord& s) { return s.ToString(); }
SetProtobufStringSwapAllowed(string * src,Cord * dest)77 inline void SetProtobufStringSwapAllowed(string* src, Cord* dest) {
78   dest->CopyFrom(*src);
79 }
80 #endif  // defined(TENSORFLOW_PROTOBUF_USES_CORD)
81 
82 }  // namespace tensorflow
83 
84 #endif  // TENSORFLOW_CORE_PLATFORM_PROTOBUF_H_
85