xtid

package module
v0.0.0-...-f2ff261 Latest Latest
Warning

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

Go to latest
Published: Mar 11, 2023 License: MIT Imports: 11 Imported by: 0

README

xtid

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Compare

func Compare(a, b XTID) int

Implements comparison for XTID type

func IDGen

func IDGen(typ uint16) func() XTID

func SetSource

func SetSource(src io.Reader)

Sets the global source of random bytes for XTID 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 XTID

type XTID [byteLength]byte

XTIDs are 20 bytes:

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

var (

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

func FromBytes

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

Constructs a XTID from a 20-byte binary representation

func FromBytesOrNil

func FromBytesOrNil(b []byte) XTID

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

func Make

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

Make a new XTID using custome time and type

func Must

func Must(id XTID, err error) XTID

func NewOrNil

func NewOrNil() (id XTID)

func NewWithType

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

func Parse

func Parse(s string) (XTID, error)

Parse decodes a string-encoded representation of a XTID object

func ParseOrNil

func ParseOrNil(s string) XTID

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

func (XTID) Append

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

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

func (XTID) Bytes

func (i XTID) Bytes() []byte

Raw byte representation of XTID

func (XTID) Get

func (i XTID) Get() any

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

func (XTID) IsNil

func (i XTID) IsNil() bool

IsNil returns true if this is a "nil" XTID

func (XTID) MarshalBinary

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

func (XTID) MarshalGQL

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

MarshalGQL implements the graphql.Marshaler interface

func (XTID) MarshalJSON

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

func (XTID) MarshalText

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

func (*XTID) Scan

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

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

func (*XTID) Set

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

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

func (XTID) String

func (i XTID) String() string

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

func (XTID) Time

func (i XTID) Time() time.Time

The timestamp portion of the ID as a Time object

func (XTID) Timestamp

func (i XTID) Timestamp() uint64

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

func (XTID) Type

func (i XTID) Type() uint16

func (*XTID) UnmarshalBinary

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

func (*XTID) UnmarshalGQL

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

UnmarshalGQL implements the graphql.UnMarshaler interface

func (*XTID) UnmarshalJSON

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

func (*XTID) UnmarshalText

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

func (XTID) Value

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

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

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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