uuid

package
v0.0.0-...-96a7984 Latest Latest
Warning

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

Go to latest
Published: Jan 2, 2025 License: MIT Imports: 7 Imported by: 1

Documentation

Overview

Package uuid implements Universally Unique Identifier (UUID) handling, as specified by RFC 4122.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type UUID

type UUID [16]byte

UUID is an Universally Unique IDentifier, as defined by RFC 4122. The UUID represents the UUID in its binary encoding. The RFC 4122 specifies the encoding and fields as follows.

The fields are encoded as 16 octets, with the sizes and order of the fields defined above, and with each field encoded with the Most Significant Byte first (known as network byte order). Note that the field names, particularly for multiplexed fields, follow historical practice.

0 1 2 3

0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1

+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | time_low | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | time_mid | time_hi_and_version | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |clk_seq_hi_res | clk_seq_low | node (0-1) | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | node (2-5) | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

If the UUID variant is `Microsoft', the first 3 elements are encoded in little-endian format. This has practically no affect unless you have to match ASCII and binary UUIDs in which case the equality differs between variants.

var Nil UUID

Nil UUID is a special case UUID which has all bits set to zero.

func MustParse

func MustParse(value string) UUID

MustParse parses the UUID string. The function panics if the argument string is not a valid UUID.

func New

func New() (UUID, error)

New returns new version 4 UUID (random UUID).

func Parse

func Parse(value string) (UUID, error)

Parse parses the string as an UUID.

func ParseData

func ParseData(data []byte) (UUID, error)

ParseData parses the UUID data.

func (UUID) ClkSeq

func (id UUID) ClkSeq() uint16

ClkSeq returns the UUID clock sequence as an uint16 number.

func (UUID) ClkSeqHiAndVariant

func (id UUID) ClkSeqHiAndVariant() (uint8, Variant)

ClkSeqHiAndVariant returns the clock sequence hi-order bits and variant.

func (UUID) ClkSeqLow

func (id UUID) ClkSeqLow() uint8

ClkSeqLow returns the 8 low-order bits of the clock sequence.

func (UUID) Compare

func (id UUID) Compare(id2 UUID) int

Compare compares the UUID to the argument UUID. The function returns -1, 0, 1 if this UUID is smaller, equal, or greater than the argument UUID respectively.

func (UUID) Node

func (id UUID) Node() []byte

Node returns the node part of the UUID.

func (*UUID) Set

func (id *UUID) Set(data []byte)

Set sets the UUIDs content from the raw binary data.

func (UUID) String

func (id UUID) String() string

func (UUID) Time

func (id UUID) Time() uint64

Time returns the UUID timestamp.

func (UUID) TimeHiAndVersion

func (id UUID) TimeHiAndVersion() uint16

TimeHiAndVersion returns the timestamp high-order bits and version number.

func (UUID) TimeLow

func (id UUID) TimeLow() uint32

TimeLow returns the timestamp low-order bits.

func (UUID) TimeMid

func (id UUID) TimeMid() uint16

TimeMid returns the mid-part of the timestamp.

func (UUID) Version

func (id UUID) Version() uint8

Version returns the UUID version.

type Variant

type Variant uint8

Variant defines the UUID variant.

const (
	ReservedNCS Variant = iota
	RFC4122
	Microsoft
	ReservedFuture
)

UUID variants.

func (Variant) String

func (v Variant) String() string

Jump to

Keyboard shortcuts

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