(patch) Minor cleanup and documentation. #4
4 changed files with 7 additions and 12 deletions
|
@ -52,8 +52,7 @@ given HexEncode[Array[Byte]] = new HexEncode[Array[Byte]] {
|
||||||
}
|
}
|
||||||
|
|
||||||
given HexDecode[Array[Byte]] = new HexDecode[Array[Byte]] {
|
given HexDecode[Array[Byte]] = new HexDecode[Array[Byte]] {
|
||||||
def fromHexString(data: String): Option[Array[Byte]] =
|
def fromHexString(data: String): Option[Array[Byte]] = Hex.fromHexString(data)
|
||||||
Hex.fromHexString(data)
|
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
@ -61,10 +60,10 @@ given HexDecode[Array[Byte]] = new HexDecode[Array[Byte]] {
|
||||||
|
|
||||||
```scala
|
```scala
|
||||||
def encode[A](data: A)(using HexEncode[A]): String =
|
def encode[A](data: A)(using HexEncode[A]): String =
|
||||||
data.toHex()
|
Hex.toHexString(dataToBytes(data))
|
||||||
|
|
||||||
def decode[A](data: String)(using HexDecode[A]): Option[A] =
|
def decode[A](data: String)(using HexDecode[A]): Option[A] =
|
||||||
data.fromHex()
|
Hex.fromHexString(data).map(dataFromBytes)
|
||||||
```
|
```
|
||||||
|
|
||||||
## Donate
|
## Donate
|
||||||
|
|
|
@ -13,8 +13,6 @@ trait HexDecode[A]:
|
||||||
*/
|
*/
|
||||||
def fromHexString(data: String): Option[A]
|
def fromHexString(data: String): Option[A]
|
||||||
|
|
||||||
extension (data: String) def fromHex(): Option[A] = fromHexString(data)
|
|
||||||
|
|
||||||
object HexDecode:
|
object HexDecode:
|
||||||
|
|
||||||
/** Retrieve the [[HexDecode]] instance for the given type.
|
/** Retrieve the [[HexDecode]] instance for the given type.
|
||||||
|
|
|
@ -12,8 +12,6 @@ trait HexEncode[A]:
|
||||||
*/
|
*/
|
||||||
def toHexString(data: A): String
|
def toHexString(data: A): String
|
||||||
|
|
||||||
extension (data: A) def toHex(): String = toHexString(data)
|
|
||||||
|
|
||||||
object HexEncode:
|
object HexEncode:
|
||||||
|
|
||||||
/** Retrieve the [[HexEncode]] instance for the given type.
|
/** Retrieve the [[HexEncode]] instance for the given type.
|
||||||
|
|
|
@ -89,15 +89,15 @@ class EncodeDecodeTests extends munit.FunSuite:
|
||||||
data: A
|
data: A
|
||||||
)(
|
)(
|
||||||
using
|
using
|
||||||
HexEncode[A]
|
H: HexEncode[A]
|
||||||
): String = data.toHex()
|
): String = H.toHexString(data)
|
||||||
|
|
||||||
private def decode[A](
|
private def decode[A](
|
||||||
data: String
|
data: String
|
||||||
)(
|
)(
|
||||||
using
|
using
|
||||||
HexDecode[A]
|
H: HexDecode[A]
|
||||||
): Option[A] = data.fromHex()
|
): Option[A] = H.fromHexString(data)
|
||||||
|
|
||||||
private def randomByteArray(): Array[Byte] =
|
private def randomByteArray(): Array[Byte] =
|
||||||
val length = Rng.nextInt(MaxLength) + MinLength
|
val length = Rng.nextInt(MaxLength) + MinLength
|
||||||
|
|
Loading…
Add table
Reference in a new issue