Skip to content

Commit

Permalink
Add CharSerializer. (#27)
Browse files Browse the repository at this point in the history
  • Loading branch information
aalexandrov authored and ankurdave committed Mar 11, 2017
1 parent 03f4173 commit 41db72c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -488,6 +488,7 @@ object IndexedRDD {
implicit val longSer = new LongSerializer
implicit val stringSer = new StringSerializer
implicit val shortSer = new ShortSerializer
implicit val charSer = new CharSerializer
implicit val intSet = new IntSerializer
implicit val bigintSer = new BigIntSerializer
implicit val uuidSer = new UUIDSerializer
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,15 @@ class ShortSerializer extends KeySerializer[Short] {
b(1).toInt & 0xFF).toShort
}

class CharSerializer extends KeySerializer[Char] {
override def toBytes(k: Char) = Array(
((k >> 8) & 0xFF).toByte,
( k & 0xFF).toByte)
override def fromBytes(b: Array[Byte]): Char =
((b(0).toInt << 8) & (0xFF << 8) |
b(1).toInt & 0xFF).toChar
}

class UUIDSerializer(val longSer: LongSerializer = new LongSerializer) extends KeySerializer[UUID] {
override def toBytes(k: UUID) =
(longSer.toBytes(k.getMostSignificantBits) ++
Expand Down

0 comments on commit 41db72c

Please sign in to comment.