uuid

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

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

Go to latest
Published: Apr 4, 2020 License: ISC Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// UUID version is unknown
	VersionUnknown byte = iota
	// UUID is based on date-time and MAC address.
	Version1
	// UUID is based on date-time and MAC address,
	// DCE security version. Although the RFC does
	// specify the DCE version, the implementation
	// for the DCE version is omitted by this package.
	Version2
	// UUID is based on namespace-name (MD5 hashed).
	Version3
	// UUID is based on random secure octets.
	Version4
	// UUID is based on namespace-name (SHA1 hashed).
	Version5
)

UUID versions as defined in RFC 4122; Section 4.1.3 "Version". Only active and representative if UUID variant is `VariantRFC`.

View Source
const (
	// UUID variant is NCS reserved.
	VariantNCS byte = iota
	// UUID variant is RFC compliant.
	VariantRFC
	// UUID variant is Microsoft reserved.
	VariantMicrosoft
	// UUID variant is reserved for future definitions.
	VariantFuture
	// UUID variant is unknown.
	VariantUnknown = 255
)

UUID layout variants as defined in RFC 4122; Section 4.1.2 "Variant".

Variables

This section is empty.

Functions

func DecodeNodeID

func DecodeNodeID(octets []byte) ([]byte, error)

DecodeNodeID decodes the node ID of a apparent UUID byte slice of version one. Is guaranteed to return an error if the passed byte slice is subceeding or exceeding the required amount of octets, or, when the version of the apparent UUID byte slice does not match const `Version1`.

func DecodeVariant

func DecodeVariant(octets []byte) byte

DecodeVariant decodes the variant of a apparent UUID byte slice. Returns const `VariantFuture` if the variant could not be matched against known variants. Is guaranteed to return const `VariantUnknown` if the passed byte slice is subceeding or exceeding the required amount of octets.

func DecodeVariantOrFail

func DecodeVariantOrFail(octets []byte) (byte, error)

DecodeVariantOrFail relinquishes the passed byte slice to `DecodeVariant`. Returns decoded variant and an error. 'OrFail' implies an error being returned if `DecodeVariant` returns const `VariantUnknown`.

func DecodeVersion

func DecodeVersion(octets []byte) byte

DecodeVersion decodes the version of a apparent UUID byte slice. Is guaranteed to return const `VersionUnknown` if the passed byte slice is subceeding or exceeding the required amount of octets.

func DecodeVersionOrFail

func DecodeVersionOrFail(octets []byte) (byte, error)

DecodeVersionOrFail relinquishes the passed byte slice to `DecodeVersion`. Returns decoded version and an error. 'OrFail' implies an error being returned if `DecodeVersion` returns const `VersionUnknown`.

func EncodeVariant

func EncodeVariant(octets []byte, variant byte) error

EncodeVariant encodes the specified version into a apparent UUID byte slice. Is guaranteed to return an error if the passed byte slice is subceeding or exceeding the required amount of octets.

func EncodeVersion

func EncodeVersion(octets []byte, version byte) error

EncodeVersion encodes the specified version into a apparent UUID byte slice. Is guaranteed to return an error if the passed byte slice is subceeding or exceeding the required amount of octets.

func Equal

func Equal(a UUID, b UUID) bool

Equal reports whether a and b contain the same octets. Value-based.

func EqualP

func EqualP(a *UUID, b *UUID) bool

EqualP reports whether a and b contain the same octets. Pointer-based.

func HasNamespaceInitError

func HasNamespaceInitError() bool

HasNamespaceInitError reports whether an error occurred whilst initializing all namespace UUIDs. If you rely on namespace UUID encoding and `HasNamespaceInitError` returns `true`, please ensure to handle the error or exit gracefully.

func IsMalformedFormat

func IsMalformedFormat(err error) bool

IsMalformedFormat returns a boolean indicating whether the error is known to report that a apparent UUID string format is malformed. That is, if the faulty text does not match any of the format lengths or if the faulty text contains an invalid character.

func IsMalformedOctets

func IsMalformedOctets(err error) bool

IsMalformedOctets returns a boolean indicating whether the error is known to report that a apparent UUID byte slice is subceeding or exceeding the required amount of octets.

func MarshalBraced

func MarshalBraced(octets []byte) ([]byte, error)

MarshalBraced marshals a apparent UUID byte slice into a hyphened UUID string representation encapsulated with opening and closing curly braces. Is guaranteed to return an error if the passed byte slice is subceeding or exceeding the required amount of octets.

func MarshalHyphened

func MarshalHyphened(octets []byte) ([]byte, error)

MarshalHyphened marshals a apparent UUID byte slice into a hyphened UUID string representation. Is guaranteed to return an error if the passed byte slice is subceeding or exceeding the required amount of octets.

func MarshalHyphenless

func MarshalHyphenless(octets []byte) ([]byte, error)

MarshalHyphenless marshals a apparent UUID byte slice into a hyphenless UUID string representation. Is guaranteed to return an error if the passed byte slice is subceeding or exceeding the required amount of octets.

func MarshalShortened

func MarshalShortened(octets []byte) ([]byte, error)

MarshalShortened marshals a apparent UUID byte slice into a shortened UUID string representation. Is guaranteed to return an error if the passed byte slice is subceeding or exceeding the required amount of octets.

func MarshalURN

func MarshalURN(octets []byte) ([]byte, error)

MarshalURN marshals a apparent UUID byte slice into a hyphened UUID string representation prefixed with `urn:uuid:`. Is guaranteed to return an error if the passed byte slice is subceeding or exceeding the required amount of octets.

func NamespaceInitError

func NamespaceInitError() error

NamespaceInitError yields the unexported `namespaceInitError` variable. See `HasNamespaceInitError` for further details.

func UnmarshalInto

func UnmarshalInto(destination []byte, text []byte) error

UnmarshalInto unmarshalls an apparent UUID string to the specified destination buffer. Supports all canonical known UUID formattings such as the hyphened, hyphenless braced and URN-prefixed. Is guaranteed to return an error if none of the named formats can be match. That is, if the input string does not match any of the given lengths: 32/hyphened, 36/hyphenless, 38/braced and 45/URN-prefixed.

Types

type MalformedFormatError

type MalformedFormatError struct {
	Text []byte
}

MalformedFormatError occurs if a apparent UUID string subceeds or exceeds in its length. That is, if the string length does not match either 32, 36, 38, 45. Also occurs if the apparent UUID string contains invalid characters.

func (MalformedFormatError) Error

func (e MalformedFormatError) Error() string

Error returns a string representation with a exhaustive message telling what the cause of this error is. If the faulty text does not match any of the format lengths, it prints current and required length. If the faulty text contains an invalid character, it prints the UUID string with the invalid character encapsulated.

type MalformedOctetsError

type MalformedOctetsError struct {
	Octets []byte
}

MalformedOctetsError occurs if a apparent UUID byte slice subceeds or exceeds the required amount of octets.

func (MalformedOctetsError) Error

func (e MalformedOctetsError) Error() string

Error returns a string representation with a exhaustive message telling whether the apparent UUID byte slice subceeds or exceeds the amount of octets.

func (MalformedOctetsError) ExceedsLength

func (e MalformedOctetsError) ExceedsLength() bool

ExceedsLength determines if the apparent UUID byte slice is subceeding or exceeding the required amount of octets.

func (MalformedOctetsError) RequiredOctets

func (e MalformedOctetsError) RequiredOctets() int

RequiredOctets yields the required octet amount of a UUID byte slice.

func (MalformedOctetsError) SubceedsLength

func (e MalformedOctetsError) SubceedsLength() bool

SubceedsLength determines if the apparent UUID byte slice is subceeding or exceeding the required amount of octets.

type UUID

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

An UUID is an universally unique identifier consisting of 16 octets representing either MAC & timestamp or namespace information. An UUID is usually formatted in a 36 character wide hexadecimal string representation, split apart in five groups using hyphens.

var (
	NamespaceDNS  *UUID
	NamespaceURL  *UUID
	NamespaceOID  *UUID
	NamespaceX500 *UUID
	NamespaceNil  *UUID
)

Predefined and commonly known namespace UUIDs.

func EncodeNamespaceMD5

func EncodeNamespaceMD5(namespace *UUID, data []byte) *UUID

EncodeNamespaceMD5 encodes a new UUID of version three, based on the given namespace and domain. Supplied data will be hashed using MD5.

func EncodeNamespaceSHA1

func EncodeNamespaceSHA1(namespace *UUID, data []byte) *UUID

EncodeNamespaceSHA1 encodes a new UUID of version five, based on the given namespace and domain. Supplied data will be hashed using SHA1.

func EncodeNil

func EncodeNil() *UUID

EncodeNil encodes a new UUID with all underlying octets zeroed out. See RFC 4122; Section 4.1.7 "Nil UUID".

func EncodeRandom

func EncodeRandom() (*UUID, error)

EncodeRandom encodes a new UUID using random octets. Returned UUID is guaranteed to be always of version `Version4` and variant `VariantRFC`.

func EncodeRandomUsingReader

func EncodeRandomUsingReader(source io.Reader) (*UUID, error)

EncodeRandomUsingReader encodes a new UUID using random octets. Reads octets from the given `io.Reader`. Is guaranteed to return an error if the given reader does not fully read 16 octets as the underlying implementation calls `io.ReadFull` on the supplied `io.Reader`.

func EncodeTimebased

func EncodeTimebased() (*UUID, error)

EncodeTimebased encodes a new UUID of version one, based on the current node ID (MAC address), clock sequence as well as the current time.

func New

func New(octets []byte) (*UUID, error)

New creates a UUID struct from a apparent UUID byte slice. Is guaranteed to return an error if the passed byte slice is subceeding or exceeding the required amount of octets.

func Unmarshal

func Unmarshal(text []byte) (*UUID, error)

Unmarshal unmarshalls an apparent UUID string to a UUID struct. Supports all canonical known UUID formattings such as the hyphened, hyphenless braced and URN-prefixed. Is guaranteed to return an error if none of the named formats can be match. That is, if the input string does not match any of the given lengths: 32/hyphened, 36/hyphenless, 38/braced and 45/URN-prefixed.

func (*UUID) Braced

func (u *UUID) Braced() []byte

Braced marshals this UUID's underlying octets into a hyphened UUID string representation encapsulated with opening and closing curly braces.

func (*UUID) GoString

func (u *UUID) GoString() string

GoString implements `fmt.GoStringer`.

func (*UUID) Hyphened

func (u *UUID) Hyphened() []byte

Hyphened marshals this UUID's underlying octets into a hyphened UUID string representation.

func (*UUID) Hyphenless

func (u *UUID) Hyphenless() []byte

Hyphenless marshals this UUID's underlying octets into a hyphenless UUID string representation.

func (UUID) Octets

func (u UUID) Octets() []byte

Octets yields the byte slice of this UUID.

func (*UUID) Shortened

func (u *UUID) Shortened() []byte

Shortened marshals this UUID's underlying octets into a shortened UUID string representation.

func (*UUID) String

func (u *UUID) String() string

String implements `fmt.Stringer`.

func (*UUID) URN

func (u *UUID) URN() []byte

URN marshals this UUID's underlying octets into a hyphened UUID string representation prefixed with `urn:uuid:`.

func (*UUID) Variant

func (u *UUID) Variant() byte

Variant yields the variant of this particular UUID.

func (*UUID) Version

func (u *UUID) Version() byte

Version yields the version of this particular UUID.

Jump to

Keyboard shortcuts

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