base62

package module
v0.3.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 30, 2021 License: MIT Imports: 4 Imported by: 0

README

base62

GoDoc Build Status Go Report Card Issues

base62 is a compact and fast implementation of Base62 encoding/decoding algorithm, which is inspired by the java implementation by glowfall.

As this package was written, I did not find good base62 implementation on github. The following packages can only encode/decode integers:

- https://github.com/gravityblast/go-base62/
- https://github.com/kare/base62
- https://github.com/catinello/base62

While this package encodes/decodes bytes of arbitrary length, as well as integers.

This Base62 implementation is much faster than big.Int based implementation, and is not much slower than typical Base64 implementations. See the following benchmark results.

Benchmark

Benchmark_Encode-12             10000000               193 ns/op
Benchmark_Decode-12             20000000                68.4 ns/op

Benchmark_Encode_BigInt-12       1000000              1070 ns/op

Benchmark_Encode_Base64-12      20000000                59.7 ns/op
Benchmark_Decode_Base64-12      20000000                62.3 ns/op

Benchmark_Encode_Integer-12     30000000                44.4 ns/op
Benchmark_Decode_Integer-12    200000000                 9.63 ns/op

Status

This is a maintenance fork from github.com/jxskiss/base62.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var StdEncoding = NewEncoding(encodeStd)

StdEncoding is an encoding/decoding scheme consisting of [A-Za-z0-9].

Functions

func AppendInt

func AppendInt(dst []byte, num int64) []byte

func AppendUint

func AppendUint(dst []byte, num uint64) []byte

func DecodeBytes added in v0.3.0

func DecodeBytes(src []byte) ([]byte, error)

Decode decodes src using StdEncoding.

func DecodeString

func DecodeString(src string) ([]byte, error)

Decode decodes src using StdEncoding.

func EncodeToBytes added in v0.3.0

func EncodeToBytes(src []byte) []byte

EncodeToBytes encodes src using StdEncoding.

func EncodeToString

func EncodeToString(src []byte) string

EncodeToString encodes src using StdEncoding.

func FormatInt

func FormatInt(num int64) []byte

func FormatUint

func FormatUint(num uint64) []byte

func ParseInt

func ParseInt(src []byte) (int64, error)

func ParseUint

func ParseUint(src []byte) (uint64, error)

Types

type CorruptInputError

type CorruptInputError int64

func (CorruptInputError) Error

func (e CorruptInputError) Error() string

type Encoding

type Encoding struct {
	// contains filtered or unexported fields
}

An Encoding is a radix 62 encoding/decoding scheme, defined by a 62-character alphabet.

func NewEncoding

func NewEncoding(encoder string) *Encoding

NewEncoding returns a new padded Encoding defined by the given alphabet. It will panic if the alphabet is not 62 bytes long.

func (*Encoding) AppendInt

func (enc *Encoding) AppendInt(dst []byte, num int64) []byte

func (*Encoding) AppendUint

func (enc *Encoding) AppendUint(dst []byte, num uint64) []byte

func (*Encoding) Decode

func (enc *Encoding) Decode(dest, src []byte) (int, error)

Decode decodes src using the encoding enc.

func (*Encoding) DecodeString

func (enc *Encoding) DecodeString(s string) ([]byte, error)

DecodeString returns the bytes represented by the base62 string s.

func (*Encoding) Encode

func (enc *Encoding) Encode(dest, src []byte) int

Encode encodes src using the encoding enc.

func (*Encoding) EncodeToString

func (enc *Encoding) EncodeToString(src []byte) string

EncodeToString returns the encoding of src.

func (*Encoding) FormatInt

func (enc *Encoding) FormatInt(num int64) []byte

func (*Encoding) FormatUint

func (enc *Encoding) FormatUint(num uint64) []byte

func (*Encoding) ParseInt

func (enc *Encoding) ParseInt(src []byte) (int64, error)

func (*Encoding) ParseUint

func (enc *Encoding) ParseUint(src []byte) (uint64, error)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL