(patch) add direct support for vector encoding
All checks were successful
/ Build and Test Library Snapshot (pull_request) Successful in 2m12s
All checks were successful
/ Build and Test Library Snapshot (pull_request) Successful in 2m12s
This commit is contained in:
parent
52715a12bc
commit
fbd0b73be3
4 changed files with 22 additions and 3 deletions
|
|
@ -9,6 +9,7 @@ import java.util.Base64
|
|||
* Supports base64-url encoding as well.
|
||||
*/
|
||||
object Base64Encoder extends Encoder[B64]:
|
||||
|
||||
private lazy val e: Base64.Encoder = Base64.getEncoder()
|
||||
private lazy val eu: Base64.Encoder = Base64.getUrlEncoder()
|
||||
|
||||
|
|
@ -17,6 +18,11 @@ object Base64Encoder extends Encoder[B64]:
|
|||
override def encode(input: Array[Byte]): B64 =
|
||||
B64(e.encodeToString(input))
|
||||
|
||||
/** @inheritDocs
|
||||
*/
|
||||
override def encode(input: Vector[Byte]): B64 =
|
||||
B64(e.encodeToString(input.toArray))
|
||||
|
||||
/** Encode the given bytes using base64-url.
|
||||
*
|
||||
* @param input
|
||||
|
|
|
|||
|
|
@ -1,7 +1,5 @@
|
|||
package gs.std.v0.core
|
||||
|
||||
import java.util.Base64
|
||||
|
||||
/** Represents a blob -- some array of bytes.
|
||||
*
|
||||
* @param data
|
||||
|
|
@ -46,4 +44,4 @@ final class Blob(private val data: Array[Byte]) extends IndexedSeq[Byte]:
|
|||
/** @return
|
||||
* This byte array, encoded as a base64 string.
|
||||
*/
|
||||
def base64(): String = Base64.getEncoder().encodeToString(data)
|
||||
def base64(): B64 = Base64Encoder.encode(data)
|
||||
|
|
|
|||
|
|
@ -15,6 +15,15 @@ trait Encoder[+A <: EncodedString]:
|
|||
*/
|
||||
def encode(input: Array[Byte]): A
|
||||
|
||||
/** Encode an immutable array of bytes as a string.
|
||||
*
|
||||
* @param input
|
||||
* The bytes to encode.
|
||||
* @return
|
||||
* The encoded string.
|
||||
*/
|
||||
def encode(input: Vector[Byte]): A
|
||||
|
||||
/** Encode a string as a string.
|
||||
*
|
||||
* @param input
|
||||
|
|
|
|||
|
|
@ -5,9 +5,15 @@ import java.util.HexFormat
|
|||
/** Implementation of [[Encoder]] for Hexadecimal strings.
|
||||
*/
|
||||
object HexEncoder extends Encoder[Hex]:
|
||||
|
||||
private lazy val h: HexFormat = HexFormat.of()
|
||||
|
||||
/** @inheritDocs
|
||||
*/
|
||||
override def encode(input: Array[Byte]): Hex =
|
||||
Hex(h.formatHex(input))
|
||||
|
||||
/** @inheritDocs
|
||||
*/
|
||||
override def encode(input: Vector[Byte]): Hex =
|
||||
Hex(h.formatHex(input.toArray))
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue