forked from bazelbuild/bazel
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Serializer implementation for NestedSet
Adds some logging to test helpers for size of serialized data. Jan 25, 2018 7:16:25 AM com.google.devtools.build.lib.skyframe.serialization.testutils.SerializerTester testSerializeDeserialize INFO: total serialized bytes = 70 Jan 25, 2018 7:16:25 AM com.google.devtools.build.lib.skyframe.serialization.testutils.ObjectCodecTester testSerializeDeserialize INFO: total serialized bytes = 208 Kryo output is significantly smaller. PiperOrigin-RevId: 183300353
- Loading branch information
Showing
5 changed files
with
122 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
src/main/java/com/google/devtools/build/lib/collect/nestedset/NestedSetSerializer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
// Copyright 2018 The Bazel 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. | ||
|
||
package com.google.devtools.build.lib.collect.nestedset; | ||
|
||
import com.esotericsoftware.kryo.Kryo; | ||
import com.esotericsoftware.kryo.Serializer; | ||
import com.esotericsoftware.kryo.io.Input; | ||
import com.esotericsoftware.kryo.io.Output; | ||
|
||
/** | ||
* {@link Serializer} for {@link NestedSet}. | ||
* | ||
* <p>Needed to handle {@link NestedSet}'s sentinel values correctly. | ||
*/ | ||
public class NestedSetSerializer extends Serializer<NestedSet<Object>> { | ||
|
||
@Override | ||
public void write(Kryo kryo, Output output, NestedSet<Object> nestedSet) { | ||
kryo.writeObject(output, nestedSet.getOrder()); | ||
Object children = nestedSet.rawChildren(); | ||
if (children == NestedSet.EMPTY_CHILDREN) { | ||
output.writeBoolean(false); | ||
} else { | ||
output.writeBoolean(true); | ||
kryo.writeClassAndObject(output, children); | ||
} | ||
} | ||
|
||
@Override | ||
public NestedSet<Object> read(Kryo kryo, Input input, Class<NestedSet<Object>> unusedType) { | ||
Order order = kryo.readObject(input, Order.class); | ||
if (input.readBoolean()) { | ||
return new NestedSet<>(order, kryo.readClassAndObject(input)); | ||
} else { | ||
return new NestedSet<>(order, NestedSet.EMPTY_CHILDREN); | ||
} | ||
} | ||
|
||
public static void registerSerializers(Kryo kryo) { | ||
kryo.register(NestedSet.class, new NestedSetSerializer()); | ||
kryo.register(Order.class); | ||
kryo.register(Object[].class); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters