redeem

package
v0.0.0-...-012d1c6 Latest Latest
Warning

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

Go to latest
Published: Apr 19, 2021 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultABC = "ABCDEFGHJKLMNPQRSTUVWXYZ"

Variables

View Source
var (
	ErrBadChecksum = errors.New("bad checksum")
)
View Source
var (
	ErrBadData = errors.New("bad data")
)

Functions

This section is empty.

Types

type Alphabet

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

func NewAlphabet

func NewAlphabet(abc string, seed uint64) *Alphabet

NewAlphabet creates a new alphabet from the passed string.

func (*Alphabet) Decode

func (a *Alphabet) Decode(s string) (uint64, error)

func (*Alphabet) Encode

func (a *Alphabet) Encode(x uint64) string

type Generator

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

生成规则与限制 通过一个表格ID和自增序列生成唯一ID 要求表格ID大于0且不能超过65535,自增ID大于0且不超过2^30 默认没有随机 情况下通常占用5-9位字符,例如 1000000 -> URSVUQHEL 1000001 -> JYVTQZGWG 1000002 -> UMVUFLHWS 1000003 -> JYVTPHEDB 1000004 -> URSDGHEGL 1000005 -> JKHZFUCVU 1000006 -> URSDHAUSK 1000007 -> URSVUVTPB 1000008 -> UMAGWTZAX 1000009 -> UMAGLHWAL

func New

func New() *Generator

func NewEx

func NewEx(abc *Alphabet, randBits uint, injectBits uint) *Generator

func (*Generator) Build

func (g *Generator) Build(tabID, start, count uint) []string

func (*Generator) Decode

func (g *Generator) Decode(id uint64) (uint64, error)

func (*Generator) Encode

func (g *Generator) Encode(tabID, counter uint64) uint64

编码格式:counter(32bit) + tabID(4-16bit) + flag(2bit) + random(4) + checksum(2bit)

func (*Generator) Generate

func (g *Generator) Generate(tabId, counter uint64) string

func (*Generator) Verify

func (g *Generator) Verify(id string) (uint64, error)

验证ID是否合法,并返回隐含的TableID信息

Jump to

Keyboard shortcuts

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