base62

package
v0.0.0-...-9e9e9bf Latest Latest
Warning

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

Go to latest
Published: Jul 25, 2025 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var StdEncoding = NewEncoding(encodeStd)

StdEncoding is the default base62 encoding using alphabet [A-Za-z0-9].

Functions

func AppendInt

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

AppendInt appends the base62 representation of the integer num using StdEncoding, to dst and returns the extended buffer.

func AppendUint

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

AppendUint appends the base62 representation of the unsigned integer num using StdEncoding, to dst and returns the extended buffer.

func Decode

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

Decode decodes src using StdEncoding, returns the decoded bytes.

If src contains invalid base62 data, it will return nil and CorruptInputError.

func DecodeString

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

DecodeString returns the bytes represented by the base62 string src using StdEncoding.

func DecodeToBuf

func DecodeToBuf(dst []byte, src []byte) ([]byte, error)

DecodeToBuf decodes src using StdEncoding, appending the decoded bytes to dst. If dst has not enough capacity, it copies dst and returns the extended buffer.

If src contains invalid base62 data, it will return nil and CorruptInputError.

func Encode

func Encode(src []byte) []byte

Encode encodes src using StdEncoding, returns the encoded bytes.

func EncodeToBuf

func EncodeToBuf(dst []byte, src []byte) []byte

EncodeToBuf encodes src using StdEncoding, appending the encoded bytes to dst. If dst has not enough capacity, it copies dst and returns the extended buffer.

func EncodeToString

func EncodeToString(src []byte) string

EncodeToString returns a base62 string representation of src using StdEncoding.

func FormatInt

func FormatInt(num int64) []byte

FormatInt encodes an integer num to base62 using StdEncoding.

func FormatUint

func FormatUint(num uint64) []byte

FormatUint encodes an unsigned integer num to base62 using StdEncoding.

func ParseInt

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

ParseInt returns an integer from its base62 representation using StdEncoding.

If src contains invalid base62 data, it returns 0 and CorruptInputError.

func ParseUint

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

ParseUint returns an unsigned integer from its base62 representation using StdEncoding.

If src contains invalid base62 data, it returns 0 and CorruptInputError.

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 Encoding defined by the given alphabet, which must be a 62-byte string that does not contain CR / LF ('\r', '\n').

func (*Encoding) AppendInt

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

AppendInt appends the base62 representation of the integer num, as generated by FormatInt, to dst and returns the extended buffer.

func (*Encoding) AppendUint

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

AppendUint appends the base62 representation of the unsigned integer num, as generated by FormatUint, to dst and returns the extended buffer.

func (*Encoding) Decode

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

Decode decodes src using the encoding enc, returns the decoded bytes.

If src contains invalid base62 data, it will return nil and CorruptInputError.

func (*Encoding) DecodeString

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

DecodeString returns the bytes represented by the base62 string src.

func (*Encoding) DecodeToBuf

func (enc *Encoding) DecodeToBuf(dst []byte, src []byte) ([]byte, error)

DecodeToBuf decodes src using the encoding enc, appending the decoded bytes to dst. If dst has not enough capacity, it copies dst and returns the extended buffer.

If src contains invalid base62 data, it will return nil and CorruptInputError.

func (*Encoding) Encode

func (enc *Encoding) Encode(src []byte) []byte

Encode encodes src using the encoding enc, returns the encoded bytes.

func (*Encoding) EncodeToBuf

func (enc *Encoding) EncodeToBuf(dst []byte, src []byte) []byte

EncodeToBuf encodes src using the encoding enc, appending the encoded bytes to dst. If dst has not enough capacity, it copies dst and returns the extended buffer.

func (*Encoding) EncodeToString

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

EncodeToString returns a base62 string representation of src.

func (*Encoding) FormatInt

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

FormatInt encodes an integer num to base62 using the encoding enc.

func (*Encoding) FormatUint

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

FormatUint encodes an unsigned integer num to base62 using the encoding enc.

func (*Encoding) ParseInt

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

ParseInt returns an integer from its base62 representation.

If src contains invalid base62 data, it returns 0 and CorruptInputError.

func (*Encoding) ParseUint

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

ParseUint returns an unsigned integer from its base62 representation.

If src contains invalid base62 data, it returns 0 and CorruptInputError.

Jump to

Keyboard shortcuts

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