in chill-scala/src/main/scala/com/twitter/chill/BitSetSerializer.scala [22:38]
def write(k: Kryo, o: Output, v: BitSet): Unit = {
val size = v.size
o.writeInt(size, true)
// Duplicates some data, but helps size on the other end:
if (size > 0) {
o.writeInt(v.max, true)
}
var previous: Int = -1
v.foreach { vi =>
if (previous >= 0) {
o.writeInt(vi - previous, true)
} else {
o.writeInt(vi, true) // first item
}
previous = vi
}
}