Encoders - craterdog/go-component-framework GitHub Wiki
Overview
An encoder is an agent that is used for encoding and decoding byte streams using the following character sets:
- base 16 -
['0..9' 'a'..'f']
- base 32 -
['0..9' 'A'..'D' 'F'..'H' 'J'..'N' 'P'..'T' 'V'..'Z']
- base 64 -
['A..Z' 'a..z' '0..9' '+' '/']
A Quick Example
To whet your appetite, here is some short example code that demonstrates the use of encoder agents.
package main
import (
fmt "fmt"
fra "github.com/craterdog/go-component-framework/v7"
)
func main() {
// Define a byte array.
var bytes = []byte{10, 20, 30, 40, 50, 60, 70, 80}
// Create a new encoder using the module level constructor shortcut.
var encoder = fra.Encoder()
// Perform base 16 encoding.
var base16 = encoder.Base16Encode(bytes)
fmt.Println("Base 16:", base16)
fmt.Println(encoder.Base16Decode(base16))
// Perform base 32 encoding.
var base32 = encoder.Base32Encode(bytes)
fmt.Println("Base 32:", base32)
fmt.Println(encoder.Base32Decode(base32))
// Perform base 64 encoding.
var base64 = encoder.Base64Encode(bytes)
fmt.Println("Base 64:", base64)
fmt.Println(encoder.Base64Decode(base64))
}