(patch) Minor cleanup and documentation. (#4)
All checks were successful
/ Build and Release Library (push) Successful in 1m24s
All checks were successful
/ Build and Release Library (push) Successful in 1m24s
Reviewed-on: #4
This commit is contained in:
parent
bea436cfb3
commit
b9ca2b5b11
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]] {
|
||||
def fromHexString(data: String): Option[Array[Byte]] =
|
||||
Hex.fromHexString(data)
|
||||
def fromHexString(data: String): Option[Array[Byte]] = Hex.fromHexString(data)
|
||||
}
|
||||
```
|
||||
|
||||
|
@ -61,10 +60,10 @@ given HexDecode[Array[Byte]] = new HexDecode[Array[Byte]] {
|
|||
|
||||
```scala
|
||||
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] =
|
||||
data.fromHex()
|
||||
Hex.fromHexString(data).map(dataFromBytes)
|
||||
```
|
||||
|
||||
## Donate
|
||||
|
|
|
@ -13,8 +13,6 @@ trait HexDecode[A]:
|
|||
*/
|
||||
def fromHexString(data: String): Option[A]
|
||||
|
||||
extension (data: String) def fromHex(): Option[A] = fromHexString(data)
|
||||
|
||||
object HexDecode:
|
||||
|
||||
/** Retrieve the [[HexDecode]] instance for the given type.
|
||||
|
|
|
@ -12,8 +12,6 @@ trait HexEncode[A]:
|
|||
*/
|
||||
def toHexString(data: A): String
|
||||
|
||||
extension (data: A) def toHex(): String = toHexString(data)
|
||||
|
||||
object HexEncode:
|
||||
|
||||
/** Retrieve the [[HexEncode]] instance for the given type.
|
||||
|
|
|
@ -89,15 +89,15 @@ class EncodeDecodeTests extends munit.FunSuite:
|
|||
data: A
|
||||
)(
|
||||
using
|
||||
HexEncode[A]
|
||||
): String = data.toHex()
|
||||
H: HexEncode[A]
|
||||
): String = H.toHexString(data)
|
||||
|
||||
private def decode[A](
|
||||
data: String
|
||||
)(
|
||||
using
|
||||
HexDecode[A]
|
||||
): Option[A] = data.fromHex()
|
||||
H: HexDecode[A]
|
||||
): Option[A] = H.fromHexString(data)
|
||||
|
||||
private def randomByteArray(): Array[Byte] =
|
||||
val length = Rng.nextInt(MaxLength) + MinLength
|
||||
|
|
Loading…
Add table
Reference in a new issue