meta

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jan 23, 2025 License: Apache-2.0, MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNotEncryptable = errors.New("value of this type cannot be encrypted")
View Source
var ErrNotFound = errors.New("key not found in meta")

Functions

This section is empty.

Types

type Iterator

type Iterator interface {
	Iter() iter.Seq2[string, ipld.Node]
}

type Meta

type Meta struct {
	Keys   []string
	Values map[string]ipld.Node
}

Meta is a container for meta key-value pairs in a UCAN token. This also serves as a way to construct the underlying IPLD data with minimum allocations and transformations, while hiding the IPLD complexity from the caller.

func NewMeta

func NewMeta() *Meta

NewMeta constructs a new Meta.

func (*Meta) Add

func (m *Meta) Add(key string, val any) error

Add adds a key/value pair in the meta set. Accepted types for val are any CBOR compatible type, or directly IPLD values.

func (*Meta) AddEncrypted

func (m *Meta) AddEncrypted(key string, val any, encryptionKey []byte) error

AddEncrypted adds a key/value pair in the meta set. The value is encrypted with the given encryptionKey. Accepted types for the value are: string, []byte. The ciphertext will be 40 bytes larger than the plaintext due to encryption overhead.

func (*Meta) Clone

func (m *Meta) Clone() *Meta

Clone makes a deep copy.

func (*Meta) Equals

func (m *Meta) Equals(other *Meta) bool

Equals tells if two Meta hold the same key/values.

func (*Meta) GetBool

func (m *Meta) GetBool(key string) (bool, error)

GetBool retrieves a value as a bool. Returns ErrNotFound if the given key is missing. Returns datamodel.ErrWrongKind if the value has the wrong type.

func (*Meta) GetBytes

func (m *Meta) GetBytes(key string) ([]byte, error)

GetBytes retrieves a value as a []byte. Returns ErrNotFound if the given key is missing. Returns datamodel.ErrWrongKind if the value has the wrong type.

func (*Meta) GetEncryptedBytes

func (m *Meta) GetEncryptedBytes(key string, encryptionKey []byte) ([]byte, error)

GetEncryptedBytes decorates GetBytes and decrypt its output with the given symmetric encryption key.

func (*Meta) GetEncryptedString

func (m *Meta) GetEncryptedString(key string, encryptionKey []byte) (string, error)

GetEncryptedString decorates GetString and decrypt its output with the given symmetric encryption key.

func (*Meta) GetFloat64

func (m *Meta) GetFloat64(key string) (float64, error)

GetFloat64 retrieves a value as a float64. Returns ErrNotFound if the given key is missing. Returns datamodel.ErrWrongKind if the value has the wrong type.

func (*Meta) GetInt64

func (m *Meta) GetInt64(key string) (int64, error)

GetInt64 retrieves a value as an int64. Returns ErrNotFound if the given key is missing. Returns datamodel.ErrWrongKind if the value has the wrong type.

func (*Meta) GetNode

func (m *Meta) GetNode(key string) (ipld.Node, error)

GetNode retrieves a value as a raw IPLD node. Returns ErrNotFound if the given key is missing.

func (*Meta) GetString

func (m *Meta) GetString(key string) (string, error)

GetString retrieves a value as a string. Returns ErrNotFound if the given key is missing. Returns datamodel.ErrWrongKind if the value has the wrong type.

func (*Meta) Include

func (m *Meta) Include(other Iterator)

Include merges the provided meta into the existing one.

If duplicate keys are encountered, the new value is silently dropped without causing an error.

func (*Meta) Iter

func (m *Meta) Iter() iter.Seq2[string, ipld.Node]

Iter iterates over the meta key/values

func (*Meta) Len

func (m *Meta) Len() int

Len returns the number of key/values.

func (*Meta) ReadOnly

func (m *Meta) ReadOnly() ReadOnly

ReadOnly returns a read-only version of Meta.

func (*Meta) String

func (m *Meta) String() string

type ReadOnly

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

ReadOnly wraps a Meta into a read-only facade.

func (ReadOnly) Equals

func (r ReadOnly) Equals(other ReadOnly) bool

func (ReadOnly) GetBool

func (r ReadOnly) GetBool(key string) (bool, error)

func (ReadOnly) GetBytes

func (r ReadOnly) GetBytes(key string) ([]byte, error)

func (ReadOnly) GetEncryptedBytes

func (r ReadOnly) GetEncryptedBytes(key string, encryptionKey []byte) ([]byte, error)

func (ReadOnly) GetEncryptedString

func (r ReadOnly) GetEncryptedString(key string, encryptionKey []byte) (string, error)

func (ReadOnly) GetFloat64

func (r ReadOnly) GetFloat64(key string) (float64, error)

func (ReadOnly) GetInt64

func (r ReadOnly) GetInt64(key string) (int64, error)

func (ReadOnly) GetNode

func (r ReadOnly) GetNode(key string) (ipld.Node, error)

func (ReadOnly) GetString

func (r ReadOnly) GetString(key string) (string, error)

func (ReadOnly) Iter

func (r ReadOnly) Iter() iter.Seq2[string, ipld.Node]

func (ReadOnly) Len

func (r ReadOnly) Len() int

func (ReadOnly) String

func (r ReadOnly) String() string

func (ReadOnly) WriteableClone

func (r ReadOnly) WriteableClone() *Meta

Jump to

Keyboard shortcuts

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