coder

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Jan 29, 2025 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Example
s, err := New()

if err != nil {
	panic(err)
}

for i := range int64(10) {
	enc := s.Encode(i)
	dec, _ := s.Decode(enc)

	fmt.Printf("%02d = %s = %02d\n", i, enc, dec)
}

fmt.Println(strings.Repeat("-", 24))

for i := int64(math.MaxInt64 - 10); i < math.MaxInt64; i++ {
	enc := s.Encode(i)
	dec, _ := s.Decode(enc)

	fmt.Printf("%02d = %s = %02d\n", i, enc, dec)
}
Output:

00 = 2ontTmrhpq11 = 00
01 = JIEAcqrt2PfP = 01
02 = VNHaJIAqtFQF = 02
03 = KOEzks0FIili = 03
04 = RTkGMcfOmbXb = 04
05 = 6cejEKvP39x9 = 05
06 = GZzM2rcEPUMU = 06
07 = ti5NXc3GV2P2 = 07
08 = fwZVorivaJVJ = 08
09 = CotWDE35aV0V = 09
------------------------
9223372036854775797 = 6KSOdrosiS37 = 9223372036854775797
9223372036854775798 = GRpehaxjbpyo = 9223372036854775798
9223372036854775799 = t67dYQuZ97vx = 9223372036854775799
9223372036854775800 = fGoh13EqUTMu = 9223372036854775800
9223372036854775801 = CtxYPsN825PE = 9223372036854775801
9223372036854775802 = 0fu1FjWnJMVN = 9223372036854775802
9223372036854775803 = BCEPiZwlVI0W = 9223372036854775803
9223372036854775804 = D0NFbqTyKOsw = 9223372036854775804
9223372036854775805 = LBWi985kRekT = 9223372036854775805
9223372036854775806 = rDwbUnM46dz5 = 9223372036854775806

Index

Examples

Constants

This section is empty.

Variables

View Source
var ErrInvalidString = errors.New("invalid string")

Functions

This section is empty.

Types

type Coder

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

Number encoder

func New

func New(a ...alpha.Alphabet) (*Coder, error)

func (*Coder) AppendEncoded

func (c *Coder) AppendEncoded(buf []byte, n int64) []byte

func (*Coder) Decode

func (c *Coder) Decode(s string) (n int64, err error)

func (*Coder) DecodeBytes

func (c *Coder) DecodeBytes(b []byte) (n int64, err error)

func (*Coder) Encode

func (c *Coder) Encode(n int64) string

func (*Coder) EncodedLength

func (c *Coder) EncodedLength() int

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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