From 20468be1ddb46a115fbc0c364d7a1dfbd01235e2 Mon Sep 17 00:00:00 2001 From: Li Haoyi Date: Fri, 25 May 2018 19:39:18 -0700 Subject: use a custom, compact format for serializing PathRefs to JSON --- core/src/mill/eval/PathRef.scala | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) (limited to 'core/src') 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 + ) + } + ) } -- cgit v1.2.3