xaid

package module
v0.0.11 Latest Latest
Warning

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

Go to latest
Published: Feb 14, 2023 License: MIT Imports: 11 Imported by: 1

README

xaid

Documentation

Index

Constants

View Source
const (
	Length = stringEncodedLength
)
View Source
const (
	SQLType = "CHAR"
)

Variables

This section is empty.

Functions

func Compare

func Compare(a, b XAID) int

Implements comparison for XAID type

func GenByType added in v0.0.10

func GenByType(typ uint16) func() XAID

func SetSource added in v0.0.10

func SetSource(src EntropySourcer)

Sets the global source of random bytes for XAID generation. This should probably only be set once globally. While this is technically thread-safe as in it won't cause corruption, there's no guarantee on ordering.

Types

type EntropySourcer added in v0.0.10

type EntropySourcer interface {
	io.Reader
}

type XAID

type XAID [byteLength]byte

XAIDs are 20 bytes:

00-07 byte: uint64 timestamp 08~11 byte: uint32 type 12-19 byte: random "payload"

var (

	// Represents a completely empty (invalid) XAID
	Nil XAID
	// Represents the highest value a XAID can have
	Max = XAID{255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255}
)

func Batch added in v0.0.10

func Batch(typ uint16, n int) []XAID

func FromBytes

func FromBytes(b []byte) (XAID, error)

Constructs a XAID from a 20-byte binary representation

func FromBytesOrNil

func FromBytesOrNil(b []byte) XAID

Constructs a XAID from a 20-byte binary representation. Same behavior as FromBytes, but returns a Nil XAID on error.

func Make added in v0.0.3

func Make(t time.Time, typ uint16) (id XAID, err error)

Make a new XAID using custome time and type

func Must

func Must(id XAID, err error) XAID

func New added in v0.0.3

func New() (id XAID, err error)

func NewOrNil added in v0.0.10

func NewOrNil() (id XAID)

func NewWithType added in v0.0.3

func NewWithType(typ uint16) (id XAID, err error)

func Parse

func Parse(s string) (XAID, error)

Parse decodes a string-encoded representation of a XAID object

func ParseOrNil

func ParseOrNil(s string) XAID

Parse decodes a string-encoded representation of a XAID object. Same behavior as Parse, but returns a Nil XAID on error.

func (XAID) Append

func (i XAID) Append(b []byte) []byte

Append appends the string representation of i to b, returning a slice to a potentially larger memory area.

func (XAID) Bytes

func (i XAID) Bytes() []byte

Raw byte representation of XAID

func (XAID) Get

func (i XAID) Get() any

Get satisfies the flag.Getter interface, making it possible to use XAIDs as part of of the command line options of a program.

func (XAID) IsNil

func (i XAID) IsNil() bool

IsNil returns true if this is a "nil" XAID

func (XAID) MarshalBinary

func (i XAID) MarshalBinary() ([]byte, error)

func (XAID) MarshalGQL added in v0.0.2

func (i XAID) MarshalGQL(w io.Writer)

MarshalGQL implements the graphql.Marshaler interface

func (XAID) MarshalJSON added in v0.0.3

func (i XAID) MarshalJSON() ([]byte, error)

func (XAID) MarshalText

func (i XAID) MarshalText() ([]byte, error)

func (*XAID) Scan

func (i *XAID) Scan(src any) error

Scan implements the sql.Scanner interface. It supports converting from string, []byte, or nil into a XAID value. Attempting to convert from another type will return an error.

func (*XAID) Set

func (i *XAID) Set(s string) error

Set satisfies the flag.Value interface, making it possible to use XAIDs as part of of the command line options of a program.

func (XAID) String

func (i XAID) String() string

String-encoded representation that can be passed through Parse()

func (XAID) Time

func (i XAID) Time() time.Time

The timestamp portion of the ID as a Time object

func (XAID) Timestamp

func (i XAID) Timestamp() uint64

The timestamp portion of the ID as a bare integer which is uncorrected for XAID's special epoch.

func (XAID) Type

func (i XAID) Type() uint16

func (*XAID) UnmarshalBinary

func (i *XAID) UnmarshalBinary(b []byte) error

func (*XAID) UnmarshalGQL added in v0.0.2

func (i *XAID) UnmarshalGQL(v any) error

UnmarshalGQL implements the graphql.UnMarshaler interface

func (*XAID) UnmarshalJSON added in v0.0.3

func (i *XAID) UnmarshalJSON(v []byte) error

func (*XAID) UnmarshalText

func (i *XAID) UnmarshalText(b []byte) error

func (XAID) Value

func (i XAID) Value() (driver.Value, error)

Value converts the XAID into a SQL driver value which can be used to directly use the XAID as parameter to a SQL query.

type XAIDCreateInput added in v0.0.10

type XAIDCreateInput struct {
	Typ  uint16
	Size int
}

type XAIDCreateResult added in v0.0.10

type XAIDCreateResult struct {
	Typ    uint16
	Size   int
	Tokens []string
}

func CreateTokenN added in v0.0.10

func CreateTokenN(input XAIDCreateInput) *XAIDCreateResult

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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