-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdoc_test.go
54 lines (43 loc) · 1.37 KB
/
doc_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
// Copyright (c) 2022 Teal.Finance contributors
// This file is part of Teal.Finance/BaseXX licensed under the MIT License.
// SPDX-License-Identifier: MIT
package base91_test
import (
"fmt"
"github.com/teal-finance/BaseXX/base91"
)
// Encode any binary data to a Base91 string.
func ExampleEncoding_Encode() {
bin := []byte{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 255}
str := base91.StdEncoding.EncodeToString(bin)
fmt.Println("Binary input: ", bin)
fmt.Println("Base91 string:", str)
// Output:
// Binary input: [0 1 2 3 4 5 6 7 8 9 255]
// Base91 string: !#B6*yOw]cPi5
}
// Decode back the encoded Base91 string.
func ExampleEncoding_DecodeString() {
bin, err := base91.StdEncoding.DecodeString("!#B6*yOw]cPi5")
fmt.Println("Binary:", bin)
fmt.Println("Error: ", err)
// Output:
// Binary: [0 1 2 3 4 5 6 7 8 9 255]
// Error: <nil>
}
// With custom alphabet.
func ExampleEncoding_EncodeToString() {
noSingleDoubleQuotes := base91.NewEncoding("" +
"abcdefghijklmnopqrstuvwxyz[]^_`!@#$%&()*+-<=>" +
"ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789/{|}~.,:;?")
bin := []byte{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 255}
str := noSingleDoubleQuotes.EncodeToString(bin)
bin, err := noSingleDoubleQuotes.DecodeString(str)
fmt.Println("Binary:", bin)
fmt.Println("Base91:", str)
fmt.Println("Error: ", err)
// Output:
// Binary: [0 1 2 3 4 5 6 7 8 9 255]
// Base91: ab!ui~>|MSAYt
// Error: <nil>
}