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_PLATFORM_PROTOBUF_H_ 17 #define TENSORFLOW_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 #if defined(PLATFORM_GOOGLE) && !defined(USE_DEFAULT_PROTOBUF) 29 #include "tensorflow/core/platform/google/protobuf.h" 30 #else 31 #include "tensorflow/core/platform/default/protobuf.h" 32 #endif 33 34 namespace tensorflow { 35 // Parses a protocol buffer contained in a string in the binary wire format. 36 // Returns true on success. Note: Unlike protobuf's builtin ParseFromString, 37 // this function has no size restrictions on the total size of the encoded 38 // protocol buffer. 39 bool ParseProtoUnlimited(protobuf::MessageLite* proto, 40 const string& serialized); 41 bool ParseProtoUnlimited(protobuf::MessageLite* proto, const void* serialized, 42 size_t size); 43 44 // Returns the string value for the value of a string or bytes protobuf field. 45 inline const string& ProtobufStringToString(const string& s) { return s; } 46 47 // Set <dest> to <src>. Swapping is allowed, as <src> does not need to be 48 // preserved. 49 inline void SetProtobufStringSwapAllowed(string* src, string* dest) { 50 dest->swap(*src); 51 } 52 53 } // namespace tensorflow 54 55 #endif // TENSORFLOW_PLATFORM_PROTOBUF_H_ 56