aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/java/com/google/devtools/build/lib/rules/apple/DottedVersion.java
diff options
context:
space:
mode:
authorGravatar michajlo <michajlo@google.com>2018-02-11 09:23:55 -0800
committerGravatar Copybara-Service <copybara-piper@google.com>2018-02-11 09:25:41 -0800
commite45c0555cfb15ce403ff2f447edb74495a633ec1 (patch)
tree28c7a697306b91d00a49602b991aea9476c65892 /src/main/java/com/google/devtools/build/lib/rules/apple/DottedVersion.java
parente3bbfdb839a483f1a418a94d857c25794006fbe0 (diff)
Add context argument to ObjectCodec.{serialize,deserialize}
Context implementations are currently empty, just doing the plumbing in this change. Once this is in we can start passing along the ObjectCodecRegistry, which will allow runtime codec resolution for classes not known at compile time. We'll also inevitably add some memoization helpers, allowing us to optimize the serialization process further. PiperOrigin-RevId: 185305674
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib/rules/apple/DottedVersion.java')
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/apple/DottedVersion.java30
1 files changed, 19 insertions, 11 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/rules/apple/DottedVersion.java b/src/main/java/com/google/devtools/build/lib/rules/apple/DottedVersion.java
index 569c8e1c4a..12e236c2fa 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/apple/DottedVersion.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/apple/DottedVersion.java
@@ -21,7 +21,9 @@ import com.google.common.collect.ComparisonChain;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Ordering;
import com.google.devtools.build.lib.concurrent.ThreadSafety.Immutable;
+import com.google.devtools.build.lib.skyframe.serialization.DeserializationContext;
import com.google.devtools.build.lib.skyframe.serialization.ObjectCodec;
+import com.google.devtools.build.lib.skyframe.serialization.SerializationContext;
import com.google.devtools.build.lib.skylarkinterface.SkylarkCallable;
import com.google.devtools.build.lib.skylarkinterface.SkylarkModule;
import com.google.devtools.build.lib.skylarkinterface.SkylarkModuleCategory;
@@ -161,9 +163,12 @@ public final class DottedVersion implements Comparable<DottedVersion>, SkylarkVa
}
@Override
- @SkylarkCallable(name = "compare_to",
- doc = "Compares based on most signifigant (first) not-matching version component. "
- + "So, for example, 1.2.3 < 1.2.4")
+ @SkylarkCallable(
+ name = "compare_to",
+ doc =
+ "Compares based on most signifigant (first) not-matching version component. "
+ + "So, for example, 1.2.3 < 1.2.4"
+ )
public int compareTo(DottedVersion other) {
int maxComponents = Math.max(components.size(), other.components.size());
for (int componentIndex = 0; componentIndex < maxComponents; componentIndex++) {
@@ -180,16 +185,16 @@ public final class DottedVersion implements Comparable<DottedVersion>, SkylarkVa
/**
* Returns the string representation of this dotted version, padded to a minimum number of
* components if the string representation does not already contain that many components.
- *
+ *
* <p>For example, a dotted version of "7.3" will return "7.3" with either one or two components
* requested, "7.3.0" if three are requested, and "7.3.0.0" if four are requested.
- *
+ *
* <p>Trailing zero components at the end of a string representation will not be removed. For
- * example, a dotted version of "1.0.0" will return "1.0.0" if only one or two components
- * are requested.
+ * example, a dotted version of "1.0.0" will return "1.0.0" if only one or two components are
+ * requested.
*
- * @param numMinComponents the minimum number of dot-separated numbers that should be present
- * in the returned string representation
+ * @param numMinComponents the minimum number of dot-separated numbers that should be present in
+ * the returned string representation
*/
public String toStringWithMinimumComponents(int numMinComponents) {
ImmutableList.Builder<Component> stringComponents = ImmutableList.builder();
@@ -260,7 +265,9 @@ public final class DottedVersion implements Comparable<DottedVersion>, SkylarkVa
public static final ObjectCodec<DottedVersion> CODEC =
new ObjectCodec<DottedVersion>() {
@Override
- public void serialize(DottedVersion obj, CodedOutputStream codedOut) throws IOException {
+ public void serialize(
+ SerializationContext context, DottedVersion obj, CodedOutputStream codedOut)
+ throws IOException {
codedOut.writeInt32NoTag(obj.components.size());
for (Component component : obj.components) {
component.serialize(codedOut);
@@ -270,7 +277,8 @@ public final class DottedVersion implements Comparable<DottedVersion>, SkylarkVa
}
@Override
- public DottedVersion deserialize(CodedInputStream codedIn) throws IOException {
+ public DottedVersion deserialize(DeserializationContext context, CodedInputStream codedIn)
+ throws IOException {
int numComponents = codedIn.readInt32();
// TODO(janakr: Presize this if/when https://github.com/google/guava/issues/196 is
// resolved.