From 9086d9643903c608ab015b0b7d903547a4e7b6f3 Mon Sep 17 00:00:00 2001 From: Feng Xiao Date: Wed, 13 Jul 2016 13:47:51 -0700 Subject: Integrate from internal code base. --- .../com/google/protobuf/CodedOutputStream.java | 38 ++++++++++++++++++++++ 1 file changed, 38 insertions(+) (limited to 'java/core/src/main/java/com/google/protobuf/CodedOutputStream.java') diff --git a/java/core/src/main/java/com/google/protobuf/CodedOutputStream.java b/java/core/src/main/java/com/google/protobuf/CodedOutputStream.java index 576a350f..4f5a9b77 100644 --- a/java/core/src/main/java/com/google/protobuf/CodedOutputStream.java +++ b/java/core/src/main/java/com/google/protobuf/CodedOutputStream.java @@ -144,6 +144,44 @@ public abstract class CodedOutputStream extends ByteOutput { return new NioEncoder(byteBuffer); } + /** + * Configures serialization to be deterministic. + * + *

The deterministic serialization guarantees that for a given binary, equal (defined by the + * {@code equals()} methods in protos) messages will always be serialized to the same bytes. This + * implies: + * + *

+ * + *

Note the deterministic serialization is NOT canonical across languages; it is also unstable + * across different builds with schema changes due to unknown fields. Users who need canonical + * serialization, e.g. persistent storage in a canonical form, fingerprinting, etc, should define + * their own canonicalization specification and implement the serializer using reflection APIs + * rather than relying on this API. + * + *

Once set, the serializer will: (Note this is an implementation detail and may subject to + * change in the future) + * + *

+ */ + public final void useDeterministicSerialization() { + serializationDeterministic = true; + } + + boolean isSerializationDeterministic() { + return serializationDeterministic; + } + private boolean serializationDeterministic; + /** * Create a new {@code CodedOutputStream} that writes to the given {@link ByteBuffer}. * -- cgit v1.2.3