Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type BitReader ¶
type BitReader struct {
// contains filtered or unexported fields
}
BitReader reads a constant number of bits from an io.Reader
func NewBitReader ¶
NewBitReader returns a BitReader that reads chunkLen bits at a time from in.
func NewBitReaderSize ¶
NewBitReaderSize is like NewBitReader but allows setting the internal buffer size
type BitWriter ¶
type BitWriter struct {
// contains filtered or unexported fields
}
BitWriter writes a constant number of bits to an io.Writer
func NewBitWriter ¶
NewBitWriter returns a BitWriter that writes chunkLen bits at a time to out.
func NewBitWriterSize ¶
NewBitWriterSize is like NewBitWriter but allows setting the internal buffer size
type Coding ¶
type Coding interface { // SetBufferSize sets internal buffer sizes SetBufferSize(size int) // SetByteChunkSize sets the number of bytes whose base is converted at time if the character set does not have a // length that is a power of 2. Encoding and decoding must be done with the same byte chunk size. The size must be // greater than 0 and less than 256. SetByteChunkSize(size int) // Encode reads from src and encodes to dst Encode(dst io.Writer, src io.Reader) error // Decode reads from src and decodes to dst Decode(dst io.Writer, src io.Reader) error }
Coding represents an encoding scheme for a character set. See NewCoding for more detail.
func NewCoding ¶
NewCoding creates a new coding with the given character set.
For example,
NewCoding([]rune("0123456789abcdef"))
creates a hex encoding scheme, and
NewCoding([]rune(" ❗"))
creates a binary encoding scheme: 0s are represented by a space and 1s are represented by an exclamation mark.
While a character set of any length can be used, those with power of 2 lengths (2, 4, 8, 16, 32, 64, 128, 256) use a more optimized algorithm.
Sets that are not power of 2 in length use an algorithm that may not have the same output as other encoders with the same character set. For example, using the base58 character set does not mean that the output will be the same as a base58-specific encoder.
This is because most encoders interpret data as a number and use a base conversion algorithm to convert it to the character set. For non-power-of-2 charsets, this requires all data to be read before encoding, which is not possible with streams. To enable stream encoding for non-power-of-2 charsets, Aces converts a default of 4 bytes (adjustable with Coding.SetByteChunkSize) of data at a time, which is not the same as converting the base of the entire data. If stream encoding is not necessary, use StaticCoding, for which using the base58 character set, for example, will produce the same output as a base58-specific encoder.
type StaticCoding ¶
type StaticCoding struct {
// contains filtered or unexported fields
}
func NewStaticCoding ¶
func NewStaticCoding(charset []rune) (*StaticCoding, error)
NewStaticCoding creates a StaticCoding with the given character set, which must be a set of unique runes. StaticCoding differs from Coding in that it does not accept streamed input, but instead requires the entire input to be provided at once. So, StaticCoding is not recommended for very large inputs. It encodes by changing the mathematical base of the input (interpreted as a binary number) to the length of the charset. Each null byte at the beginning of the input are encoded as the first character in the charset.
For example,
NewStaticCoding([]rune("123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"))
creates the base58 encoding scheme compatible with Bitcoin's implementation.