summaryrefslogtreecommitdiff
path: root/core/src
diff options
context:
space:
mode:
authorLi Haoyi <haoyi.sg@gmail.com>2018-05-25 19:39:18 -0700
committerLi Haoyi <haoyi.sg@gmail.com>2018-05-25 20:36:05 -0700
commit20468be1ddb46a115fbc0c364d7a1dfbd01235e2 (patch)
treeb47743c5e8c5a586d160c1df527cbb4b1702a979 /core/src
parentf2266581f207fa2663702ed07cc631d32630ab10 (diff)
downloadmill-20468be1ddb46a115fbc0c364d7a1dfbd01235e2.tar.gz
mill-20468be1ddb46a115fbc0c364d7a1dfbd01235e2.tar.bz2
mill-20468be1ddb46a115fbc0c364d7a1dfbd01235e2.zip
use a custom, compact format for serializing PathRefs to JSON
Diffstat (limited to 'core/src')
-rw-r--r--core/src/mill/eval/PathRef.scala20
1 files changed, 18 insertions, 2 deletions
diff --git a/core/src/mill/eval/PathRef.scala b/core/src/mill/eval/PathRef.scala
index 5bac93b2..118d98fe 100644
--- a/core/src/mill/eval/PathRef.scala
+++ b/core/src/mill/eval/PathRef.scala
@@ -61,6 +61,22 @@ object PathRef{
}
new PathRef(path, quick, sig)
}
- private implicit val pathFormat: RW[Path] = JsonFormatters.pathReadWrite
- implicit def jsonFormatter: RW[PathRef] = upickle.default.macroRW
+
+ implicit def jsonFormatter: RW[PathRef] = upickle.default.readwriter[String].bimap[PathRef](
+ p => {
+ (if (p.quick) "qref" else "ref") + ":" +
+ String.format("%08x", p.sig: Integer) + ":" +
+ p.path.toString()
+ },
+ s => {
+ val Array(prefix, hex, path) = s.split(":", 3)
+ PathRef(
+ Path(path),
+ prefix match{ case "qref" => true case "ref" => false},
+ // Parsing to a long and casting to an int is the only way to make
+ // round-trip handling of negative numbers work =(
+ java.lang.Long.parseLong(hex, 16).toInt
+ )
+ }
+ )
}