aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/java/com/google/devtools/build/lib/vfs/RootedPath.java
diff options
context:
space:
mode:
authorGravatar tomlu <tomlu@google.com>2018-01-16 11:37:48 -0800
committerGravatar Copybara-Service <copybara-piper@google.com>2018-01-16 11:40:00 -0800
commitac4da4b96cfc6941f4203050f5fcd7aec20ad142 (patch)
tree6a304f7d0b13880e9bd8062224b85e021d885e59 /src/main/java/com/google/devtools/build/lib/vfs/RootedPath.java
parentcd1946183214af255017e35106fd87bd6186b674 (diff)
Move RootedPathCodec to an inner class of RootedPath.
PiperOrigin-RevId: 182087153
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib/vfs/RootedPath.java')
-rw-r--r--src/main/java/com/google/devtools/build/lib/vfs/RootedPath.java36
1 files changed, 36 insertions, 0 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/vfs/RootedPath.java b/src/main/java/com/google/devtools/build/lib/vfs/RootedPath.java
index 0e52406339..a704b37b73 100644
--- a/src/main/java/com/google/devtools/build/lib/vfs/RootedPath.java
+++ b/src/main/java/com/google/devtools/build/lib/vfs/RootedPath.java
@@ -14,6 +14,11 @@
package com.google.devtools.build.lib.vfs;
import com.google.common.base.Preconditions;
+import com.google.devtools.build.lib.skyframe.serialization.ObjectCodec;
+import com.google.devtools.build.lib.skyframe.serialization.SerializationException;
+import com.google.protobuf.CodedInputStream;
+import com.google.protobuf.CodedOutputStream;
+import java.io.IOException;
import java.io.Serializable;
import java.util.Objects;
@@ -126,4 +131,35 @@ public class RootedPath implements Serializable {
public String toString() {
return "[" + root + "]/[" + relativePath + "]";
}
+
+ /** Custom serialization for {@link RootedPath}s. */
+ public static class RootedPathCodec implements ObjectCodec<RootedPath> {
+
+ private final PathCodec pathCodec;
+
+ /** Create an instance which will deserialize RootedPaths on {@code fileSystem}. */
+ public RootedPathCodec(FileSystem fileSystem) {
+ this.pathCodec = new PathCodec(fileSystem);
+ }
+
+ @Override
+ public Class<RootedPath> getEncodedClass() {
+ return RootedPath.class;
+ }
+
+ @Override
+ public void serialize(RootedPath rootedPath, CodedOutputStream codedOut)
+ throws IOException, SerializationException {
+ pathCodec.serialize(rootedPath.getRoot(), codedOut);
+ PathFragment.CODEC.serialize(rootedPath.getRelativePath(), codedOut);
+ }
+
+ @Override
+ public RootedPath deserialize(CodedInputStream codedIn)
+ throws IOException, SerializationException {
+ Path root = pathCodec.deserialize(codedIn);
+ PathFragment relativePath = PathFragment.CODEC.deserialize(codedIn);
+ return toRootedPath(root, relativePath);
+ }
+ }
}