uuidpb

package
v0.20.0 Latest Latest
Warning

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

Go to latest
Published: Jan 29, 2026 License: MIT Imports: 12 Imported by: 6

Documentation

Overview

Package uuidpb provides the "well-known" UUID type for representing RFC 9562 (and formerly RFC 4122) UUIDs as Protocol Buffers messages.

Index

Constants

This section is empty.

Variables

View Source
var File_github_com_dogmatiq_enginekit_protobuf_uuidpb_uuid_proto protoreflect.FileDescriptor

Functions

func AsByteArray

func AsByteArray[T ~[16]B, B ~byte](x *UUID) T

AsByteArray returns the UUID as a byte array.

func CopyBytes added in v0.17.0

func CopyBytes[T ~[]B, B byte](x *UUID, dst T) int

CopyBytes copies the binary representation of x into dst.

It returns the number of elements copied, which will be the minimum of 16 and len(dst).

func MustParseAsByteArray added in v0.19.7

func MustParseAsByteArray(str string) [16]byte

MustParseAsByteArray parses an RFC 9562 "hex-and-dash" UUID string directly to its byte array representation, or panics if unable to do so.

This is equivalent to calling MustParse(str).AsByteArray(), but avoids all allocations.

func MustParseAsBytes added in v0.19.7

func MustParseAsBytes(str string) []byte

MustParseAsBytes parses an RFC 9562 "hex-and-dash" UUID string directly to its byte slice representation, or panics if unable to do so.

This is equivalent to calling MustParse(str).AsBytes(), but avoids allocation of the intermediate UUID struct.

func MustParseIntoBytes added in v0.19.7

func MustParseIntoBytes(str string, dst []byte)

MustParseIntoBytes parses an RFC 9562 "hex-and-dash" UUID string into the given byte slice, or panics if unable to do so.

This is equivalent to calling CopyBytes on the result of MustParse, but avoids all allocations.

func ParseAsByteArray added in v0.19.7

func ParseAsByteArray(str string) ([16]byte, error)

ParseAsByteArray parses an RFC 9562 "hex-and-dash" UUID string directly to its byte array representation.

This is equivalent to calling AsByteArray() on the result of Parse(str), but avoids all allocations.

func ParseAsBytes added in v0.19.7

func ParseAsBytes(str string) ([]byte, error)

ParseAsBytes parses an RFC 9562 "hex-and-dash" UUID string directly to its byte slice representation.

This is equivalent to calling AsBytes() on the result of Parse(str), but avoids allocation of the intermediate UUID struct.

func ParseIntoBytes added in v0.19.7

func ParseIntoBytes(str string, dst []byte) error

ParseIntoBytes parses an RFC 9562 "hex-and-dash" UUID string into the given byte slice.

This is equivalent to calling CopyBytes on the result of Parse, but avoids all allocations.

Types

type Map

type Map[T any] struct {
	// contains filtered or unexported fields
}

Map is a map from UUID to values of type T.

func (*Map[T]) All added in v0.11.0

func (m *Map[T]) All() iter.Seq2[*UUID, T]

All yields all key/value pairs in the map.

func (*Map[T]) Clear added in v0.19.18

func (m *Map[T]) Clear()

Clear removes all elements from the map.

func (*Map[T]) Clone added in v0.19.18

func (m *Map[T]) Clone() *Map[T]

Clone returns a shallow copy of the map.

func (*Map[T]) Delete

func (m *Map[T]) Delete(k *UUID)

Delete removes the value associated with the given key.

func (*Map[T]) Get

func (m *Map[T]) Get(k *UUID) (T, bool)

Get returns the value associated with the given key.

func (*Map[T]) Has added in v0.10.2

func (m *Map[T]) Has(k *UUID) bool

Has reports whether the map contains a value for the given key.

func (*Map[T]) Keys added in v0.11.0

func (m *Map[T]) Keys() iter.Seq[*UUID]

Keys yields all keys in the map.

func (*Map[T]) Len added in v0.11.0

func (m *Map[T]) Len() int

Len returns the number of elements in the map.

func (*Map[T]) Set

func (m *Map[T]) Set(k *UUID, v T)

Set sets the value associated with the given key.

func (*Map[T]) Values added in v0.11.0

func (m *Map[T]) Values() iter.Seq[T]

Values yields all values in the map.

type Set

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

Set is a collection of UUID values.

func (*Set) Add

func (s *Set) Add(v *UUID)

Add adds the given UUID to the set.

func (*Set) All added in v0.19.18

func (s *Set) All() iter.Seq[*UUID]

All yields all members of the set.

func (*Set) Clear added in v0.19.18

func (s *Set) Clear()

Clear removes all members from the set.

func (*Set) Clone added in v0.19.18

func (s *Set) Clone() *Set

Clone returns a shallow copy of the set.

func (*Set) Delete

func (s *Set) Delete(v *UUID)

Delete removes the given UUID from the set.

func (*Set) Has

func (s *Set) Has(v *UUID) bool

Has reports whether the set contains the given UUID.

func (*Set) Len added in v0.19.18

func (s *Set) Len() int

Len returns the number of members in the set.

type UUID

type UUID struct {
	Upper uint64 `protobuf:"varint,1,opt,name=upper,proto3" json:"upper,omitempty"`
	Lower uint64 `protobuf:"varint,2,opt,name=lower,proto3" json:"lower,omitempty"`
	// contains filtered or unexported fields
}

UUID is a size-optimized representation of an RFC 9562 UUID.

func Derive added in v0.17.0

func Derive[T ~string | ~[]byte](ns *UUID, names ...T) *UUID

Derive returns a new SHA-1 derived (v5) UUID from the given namespace and names.

func FromByteArray

func FromByteArray[T ~[16]B, B byte](data T) *UUID

FromByteArray returns a UUID from a byte array.

func FromBytes added in v0.19.12

func FromBytes[T ~[]B, B byte](data T) (*UUID, error)

FromBytes returns a UUID from a byte slice.

It returns an error if the length of the slice is not exactly 16 bytes.

func Generate

func Generate() *UUID

Generate returns a new randomly generated (v4) UUID.

func MustParse added in v0.12.0

func MustParse(str string) *UUID

MustParse parses an RFC 9562 "hex-and-dash" UUID string, or panics if unable to do so.

func Parse added in v0.12.0

func Parse(str string) (*UUID, error)

Parse parses an RFC 9562 "hex-and-dash" UUID string.

func (*UUID) AsByteArray added in v0.19.12

func (x *UUID) AsByteArray() [16]byte

AsByteArray returns the UUID as a byte array.

func (*UUID) AsBytes

func (x *UUID) AsBytes() []byte

AsBytes returns the UUID as a byte slice.

func (*UUID) AsString

func (x *UUID) AsString() string

AsString returns the UUID as an RFC 9562 string.

func (*UUID) Compare

func (x *UUID) Compare(id *UUID) int

Compare performs a three-way comparison between x and id.

func (*UUID) DapperString

func (x *UUID) DapperString() string

DapperString implements github.com/dogmatiq/dapper.Stringer.

func (*UUID) Descriptor deprecated

func (*UUID) Descriptor() ([]byte, []int)

Deprecated: Use UUID.ProtoReflect.Descriptor instead.

func (*UUID) Equal

func (x *UUID) Equal(id *UUID) bool

Equal returns true if x and id are equal.

func (*UUID) Format

func (x *UUID) Format(f fmt.State, verb rune)

Format implements the fmt.Formatter interface, allowing UUIDs to be formatted with functions from the fmt package.

This method takes precedence over the UUID.String method, which is generated by the Protocol Buffers compiler.

func (*UUID) GetLower

func (x *UUID) GetLower() uint64

func (*UUID) GetUpper

func (x *UUID) GetUpper() uint64

func (*UUID) Less

func (x *UUID) Less(id *UUID) bool

Less returns true if x is less than id.

func (*UUID) MarshalBinary added in v0.18.0

func (x *UUID) MarshalBinary() ([]byte, error)

MarshalBinary returns the binary representation of the message, equivalent to calling proto.Marshal(x).

It allows *UUID to implement encoding.BinaryMarshaler.

func (*UUID) ProtoMessage

func (*UUID) ProtoMessage()

func (*UUID) ProtoReflect

func (x *UUID) ProtoReflect() protoreflect.Message

func (*UUID) Reset

func (x *UUID) Reset()

func (*UUID) SetLower

func (x *UUID) SetLower(v uint64)

SetLower sets the x.Lower field to v, then returns x.

func (*UUID) SetUpper

func (x *UUID) SetUpper(v uint64)

SetUpper sets the x.Upper field to v, then returns x.

func (*UUID) String

func (x *UUID) String() string

func (*UUID) UnmarshalBinary added in v0.18.0

func (x *UUID) UnmarshalBinary(data []byte) error

UnmarshalBinary populates x from its binary representation, equivalent to calling proto.Unmarshal(data, x).

It allows *UUID to implement encoding.BinaryUnmarshaler.

func (*UUID) Validate

func (x *UUID) Validate() error

Validate returns an error if x is not a valid Version 4 (random) or Version 5 (name-based) UUID.

type UUIDBuilder

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

func NewUUIDBuilder

func NewUUIDBuilder() *UUIDBuilder

NewUUIDBuilder returns a builder that constructs UUID messages.

func (*UUIDBuilder) Build

func (b *UUIDBuilder) Build() *UUID

Build returns a new UUID containing the values configured via the builder.

Each call returns a new message, such that future changes to the builder do not modify previously constructed messages.

func (*UUIDBuilder) From

func (b *UUIDBuilder) From(x *UUID) *UUIDBuilder

From configures the builder to use x as the prototype for new messages, then returns b.

It performs a shallow copy of x, such that any changes made via the builder do not modify x. It does not make a copy of the field values themselves.

func (*UUIDBuilder) WithLower

func (b *UUIDBuilder) WithLower(v uint64) *UUIDBuilder

WithLower configures the builder to set the Lower field to v, then returns b.

func (*UUIDBuilder) WithUpper

func (b *UUIDBuilder) WithUpper(v uint64) *UUIDBuilder

WithUpper configures the builder to set the Upper field to v, then returns b.

Jump to

Keyboard shortcuts

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