diff --git a/cache/Cache.scala b/cache/Cache.scala index 0cf5ccd12..238773b18 100644 --- a/cache/Cache.scala +++ b/cache/Cache.scala @@ -188,6 +188,22 @@ trait HListCacheImplicits } implicit def hNilCache: InputCache[HNil] = Cache.singleton(HNil : HNil) + + implicit def hConsFormat[H, T <: HList](implicit head: Format[H], tail: Format[T]): Format[H :+: T] = new Format[H :+: T] { + def reads(from: Input) = + { + val h = head.reads(from) + val t = tail.reads(from) + HCons(h, t) + } + def writes(to: Output, hc: H :+: T) + { + head.writes(to, hc.head) + tail.writes(to, hc.tail) + } + } + + implicit def hNilFormat: Format[HNil] = asSingleton(HNil) } trait UnionImplicits { diff --git a/cache/src/test/scala/CacheTest.scala b/cache/src/test/scala/CacheTest.scala index ad6085fc1..481bfb9b6 100644 --- a/cache/src/test/scala/CacheTest.scala +++ b/cache/src/test/scala/CacheTest.scala @@ -10,6 +10,8 @@ object CacheTest// extends Properties("Cache test") import Cache._ import FileInfo.hash._ + import Ordering._ + import sbinary.DefaultProtocol.FileFormat def test { lazy val create = new File("test")