aboutsummaryrefslogtreecommitdiffhomepage
path: root/tensorflow/core/lib/strings/proto_serialization.h
diff options
context:
space:
mode:
authorGravatar A. Unique TensorFlower <gardener@tensorflow.org>2018-03-08 12:01:23 -0800
committerGravatar TensorFlower Gardener <gardener@tensorflow.org>2018-03-08 12:12:23 -0800
commit25b970971a58f9e49008eecfce113b7d342dbec2 (patch)
treee39bb18c3105f8d70cd91bd700e929d498f1ea1e /tensorflow/core/lib/strings/proto_serialization.h
parent543454b282bbcffd63d1348204662dbfed82fb86 (diff)
Decoupling hash and protobuf. This simplifies a little bit the dependency chain as
we don't have to link protobuf libraries just to use basic hash functions. The case for deterministic serialization of protocol buffers if very specific and can be handled by a new header file. PiperOrigin-RevId: 188366713
Diffstat (limited to 'tensorflow/core/lib/strings/proto_serialization.h')
-rw-r--r--tensorflow/core/lib/strings/proto_serialization.h33
1 files changed, 33 insertions, 0 deletions
diff --git a/tensorflow/core/lib/strings/proto_serialization.h b/tensorflow/core/lib/strings/proto_serialization.h
new file mode 100644
index 0000000000..6664928e28
--- /dev/null
+++ b/tensorflow/core/lib/strings/proto_serialization.h
@@ -0,0 +1,33 @@
+/* Copyright 2018 The TensorFlow Authors. All Rights Reserved.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+==============================================================================*/
+#ifndef TENSORFLOW_CORE_LIB_STRINGS_PROTO_SERIALIZATION_H_
+#define TENSORFLOW_CORE_LIB_STRINGS_PROTO_SERIALIZATION_H_
+
+#include "tensorflow/core/platform/protobuf.h"
+
+namespace tensorflow {
+
+// Wrapper around protocol buffer serialization that requests deterministic
+// serialization, in particular for Map fields, which serialize in a random
+// order by default. Returns true on success.
+// Serialization is guaranteed to be deterministic for a given binary only.
+// See the following for more details:
+// https://github.com/google/protobuf/blob/a1bb147e96b6f74db6cdf3c3fcb00492472dbbfa/src/google/protobuf/io/coded_stream.h#L834
+bool SerializeToStringDeterministic(const protobuf::MessageLite& msg,
+ string* result);
+
+} // namespace tensorflow
+
+#endif // TENSORFLOW_CORE_LIB_STRINGS_PROTO_SERIALIZATION_H_