Skip to content

Commit

Permalink
Merge pull request #151 from twitter/boolean-buff
Browse files Browse the repository at this point in the history
Add boolean bufferable
  • Loading branch information
ianoc committed Nov 20, 2013
2 parents d830a50 + 7749894 commit 6d17f90
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,12 @@ object Bufferable extends GeneratedTupleBufferable with Serializable {
}

// Primitives:
implicit val booleanBufferable: Bufferable[Boolean] =
buildCatchDuplicate[Boolean] { (bb, x) =>
val byte = if(x) 1:Byte else 0:Byte
reallocatingPut(bb){ _.put(byte) }
} { _.get == (1:Byte) }

implicit val byteBufferable: Bufferable[Byte] =
buildCatchDuplicate[Byte] { (bb, x) => reallocatingPut(bb){ _.put(x) } } { _.get }
implicit val charBufferable: Bufferable[Char] =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ object BufferableLaws extends Properties("Bufferable") with BaseBufferable {
}

implicit val laeq = itereq[List[Array[Byte]], Array[Byte]]

property("Bools roundtrip") = roundTrips[Boolean]
property("Ints roundtrip") = roundTrips[Int]
property("Doubles roundtrip") = roundTrips[Double]
property("Floats roundtrip") = roundTrips[Float]
Expand Down

0 comments on commit 6d17f90

Please sign in to comment.