Documentation
¶
Overview ¶
Package anybase provides utilities for converting bytes to base-n
Example ¶
package main import ( "fmt" "github.com/spenserblack/anybase" ) func main() { encoder := anybase.Encoder("0123456789abcdef") // It will often be useful to create an encoder-decoder pair decoder := encoder.Decoder() src1 := []byte{0xAB, 0xCD} dst := make([]byte, encoder.EncodedLen(len(src1))) encoder.Encode(src1, dst) fmt.Printf("%s\n", dst) src2 := make([]byte, decoder.DecodedLen(len(dst))) decoder.Decode(dst, src2) fmt.Printf("[%X, %X]\n", src2[0], src2[1]) }
Output: abcd [AB, CD]
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Decoder ¶
Decoder decodes from the source bytes to a destination byte slice.
Example ¶
package main import ( "fmt" "github.com/spenserblack/anybase" ) func main() { // Base-3, where the digits are 1, 2, and 3. decoder := anybase.Decoder{ '1': 0, '2': 1, '3': 2, } dst := []byte("111123") src := make([]byte, decoder.DecodedLen(len(dst))) decoder.Decode(dst, src) fmt.Printf("%v", src) }
Output: [5]
func (Decoder) DecodedLen ¶
DecodedLen returns the number of bytes that the decoded destination would be.
type Encoder ¶
type Encoder []byte
Encoder encodes source bytes to a destination byte slice.
Example ¶
package main import ( "fmt" "github.com/spenserblack/anybase" ) func main() { // Base-2, where the digits are "a" and "b" encoder := anybase.Encoder("ab") src := []byte{0b01011001} dst := make([]byte, encoder.EncodedLen(len(src))) encoder.Encode(src, dst) fmt.Printf("%s", dst) }
Output: ababbaab
func (Encoder) EncodedLen ¶
EncodedLen returns the length of an encoded dst.
type ErrBadEncodedByte ¶
type ErrBadEncodedByte byte
ErrBadEncodedByte is an error type for an invalid encoded byte.
func (ErrBadEncodedByte) Error ¶
func (err ErrBadEncodedByte) Error() string
Click to show internal directories.
Click to hide internal directories.