I need to store a sequence of bytes (a hash) in a case class.
My first approach has been to use an Array[Byte]
but it breaks the equality property of the case class. The next example fails.
"compare arrays" in {
case class CaseClassWithHash(id: Int, hash: Array[Byte])
CaseClassWithHash(0, Array[Byte](192.toByte, 168.toByte)) == CaseClassWithHash(0, Array[Byte](192.toByte, 168.toByte)) shouldBe true
}
So my question is, which is the best way to represent the array of bytes:
- I'm not going to manipulate it.
- I need == working in the case class (previous unit test).
- Memory usage is critical.
- It is going to be always 32 bytes (sha256).
P.S. Case Class equality for Arrays is not an answer to my question. I'm asking for the right replacement of an Array to represent a SHA256 value and of course, overwrite the equals function is not the way.