id

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Sep 25, 2018 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// Length is the number of bytes in an ID, though actual representations may be shorter
	// (with the assumption that left-padded zero bytes can be omitted)
	Length = 32
)

Variables

View Source
var (
	// UpperBound is the upper bound of the ID space, i.e., all 256 bits on.
	UpperBound = FromBytes(bytes.Repeat([]byte{255}, Length))

	// LowerBound is the lower bound of the ID space, i.e., all 256 bits off.
	LowerBound = FromInt(big.NewInt(0))
)

Functions

func Hex

func Hex(val []byte) string

Hex returns the 64-char hex value of a 32-byte values.

func ShortHex

func ShortHex(val []byte) string

ShortHex returns the 16-char hex value of the first 8 butes of a value.

Types

type ID

type ID interface {
	fmt.Stringer

	// Bytes returns the byte representation
	Bytes() []byte

	// Int returns the big.Int representation
	Int() *big.Int

	// Cmp compares the ID to another
	Cmp(ID) int

	// Distance computes the XOR distance between two IDs
	Distance(ID) *big.Int
}

ID is an identifier of arbitrary byte length

func FromBytes

func FromBytes(value []byte) ID

FromBytes creates an ID from a big-endian byte array.

func FromInt

func FromInt(value *big.Int) ID

FromInt creates an ID from a *big.Int.

func FromInt64

func FromInt64(value int64) ID

FromInt64 creates an ID from an int64.

func FromPublicKey

func FromPublicKey(pubKey *ecdsa.PublicKey) ID

FromPublicKey returns an ID instance from an elliptic curve public key.

func FromString

func FromString(value string) (ID, error)

FromString creates an ID from a hex-encoded string.

func NewPseudoRandom

func NewPseudoRandom(rng *mrand.Rand) ID

NewPseudoRandom returns a pseudo-random ID from a random number generator.

func NewRandom

func NewRandom() ID

NewRandom returns a random 32-byte ID using local machine's local random number generator.

Jump to

Keyboard shortcuts

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