schema

package
v0.4.5 Latest Latest
Warning

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

Go to latest
Published: Jan 23, 2022 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package schema implements miscellaneous data structures that can be converted to and from blobs.

Index

Constants

This section is empty.

Variables

View Source
var File_schema_proto protoreflect.FileDescriptor

Functions

func ProtectList added in v0.3.0

func ProtectList(f gc.ProtectFunc) gc.ProtectFunc

ProtectList returns a gc.ProtectFunc that protects the list and its member refs from garbage collection. The function f is the ProtectFunc for the members of the list.

func ProtectMap added in v0.3.0

func ProtectMap(k, v gc.ProtectFunc) gc.ProtectFunc

ProtectMap returns a gc.ProtectFunc that protects the nodes of a Map and any refs they contain. The parameters k and v are ProtectFuncs for protecting keys and values found in the Map, if those should be interpreted as refs; they should be nil if not.

func ProtectSet added in v0.3.0

func ProtectSet(f gc.ProtectFunc) gc.ProtectFunc

ProtectSet returns a gc.ProtectFunc that protects the nodes of a Set and the refs they contain. The parameter f is the function that protects the refs that are members of the Set.

Types

type List

type List struct {
	Members [][]byte `protobuf:"bytes,1,rep,name=members,proto3" json:"members,omitempty"`
	// contains filtered or unexported fields
}

func ListFromRefs

func ListFromRefs(ctx context.Context, s bs.Store, refs []bs.Ref) (*List, bs.Ref, error)

ListFromRefs creates a new list whose members are the given refs, and stores the resulting list in s. It returns the List and the ref at which it is stored.

func LoadList

func LoadList(ctx context.Context, g bs.Getter, ref bs.Ref) (*List, error)

LoadList loads the List at ref from g.

func (*List) Descriptor deprecated

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

Deprecated: Use List.ProtoReflect.Descriptor instead.

func (*List) GetMembers

func (x *List) GetMembers() [][]byte

func (*List) ProtoMessage

func (*List) ProtoMessage()

func (*List) ProtoReflect

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

func (*List) Reset

func (x *List) Reset()

func (*List) String

func (x *List) String() string

type Map

type Map struct {
	Node *TreeNode `protobuf:"bytes,1,opt,name=node,proto3" json:"node,omitempty"`
	// Mutually exclusive with node.left and node.right.
	Members []*MapPair `protobuf:"bytes,2,rep,name=members,proto3" json:"members,omitempty"`
	// contains filtered or unexported fields
}

func LoadMap

func LoadMap(ctx context.Context, g bs.Getter, ref bs.Ref) (*Map, error)

LoadMap loads the map at the given ref.

func MapFromGo

func MapFromGo(ctx context.Context, s bs.Store, m map[string][]byte) (*Map, bs.Ref, error)

MapFromGo creates a Map from a Go map[string][]byte.

func NewMap

func NewMap() *Map

NewMap produces a new, blank map, not yet written to a blob store.

func (*Map) Descriptor deprecated

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

Deprecated: Use Map.ProtoReflect.Descriptor instead.

func (*Map) Each

func (m *Map) Each(ctx context.Context, g bs.Getter, f func(*MapPair) error) error

Each calls a function for each member pair of a Map, in an indeterminate order. If the callback returns an error, Each exits with that error.

func (*Map) GetMembers

func (x *Map) GetMembers() []*MapPair

func (*Map) GetNode

func (x *Map) GetNode() *TreeNode

func (*Map) IsEmpty

func (m *Map) IsEmpty() bool

IsEmpty tells whether the map is empty.

func (*Map) Lookup

func (m *Map) Lookup(ctx context.Context, g bs.Getter, key []byte) ([]byte, bool, error)

Lookup finds the given key in a Map and returns its payload if found. The boolean return value indicates whether the key was in the Map.

func (*Map) ProtoMessage

func (*Map) ProtoMessage()

func (*Map) ProtoReflect

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

func (*Map) Remove

func (m *Map) Remove(ctx context.Context, store bs.Store, key []byte) (bs.Ref, bool, error)

Remove removes the member pair with the given key from a Map. It return's the Map's possibly-updated Ref and a boolean telling whether a change was made, which will be false if the key was not in the Map.

func (*Map) Reset

func (x *Map) Reset()

func (*Map) Set

func (m *Map) Set(ctx context.Context, store bs.Store, key, payload []byte) (bs.Ref, Outcome, error)

Set sets the payload for a given key in a Map. It returns the Map's possibly-updated Ref and an Outcome: ONone if no change was needed (the key was already present and had the same payload), OUpdated (the key was present with a different payload), or OAdded (the key was not present).

func (*Map) String

func (x *Map) String() string

type MapPair

type MapPair struct {
	Key     []byte `protobuf:"bytes,1,opt,name=key,proto3" json:"key,omitempty"`
	Payload []byte `protobuf:"bytes,2,opt,name=payload,proto3" json:"payload,omitempty"`
	// contains filtered or unexported fields
}

func (*MapPair) Descriptor deprecated

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

Deprecated: Use MapPair.ProtoReflect.Descriptor instead.

func (*MapPair) GetKey

func (x *MapPair) GetKey() []byte

func (*MapPair) GetPayload

func (x *MapPair) GetPayload() []byte

func (*MapPair) ProtoMessage

func (*MapPair) ProtoMessage()

func (*MapPair) ProtoReflect

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

func (*MapPair) Reset

func (x *MapPair) Reset()

func (*MapPair) String

func (x *MapPair) String() string

type Outcome

type Outcome int

Outcome is the outcome of a Map.Set operation.

const (
	// ONone means no change was needed.
	ONone Outcome = iota

	// OAdded means a key was not present, and was added.
	OAdded

	// OUpdated means a key was present but its payload was changed.
	OUpdated
)

type Set

type Set struct {
	Node *TreeNode `protobuf:"bytes,1,opt,name=node,proto3" json:"node,omitempty"`
	// Mutually exclusive with node.left and node.right.
	Members [][]byte `protobuf:"bytes,2,rep,name=members,proto3" json:"members,omitempty"`
	// contains filtered or unexported fields
}

Set is a set of refs, represented as a tree. The shape of the tree is insensitive to the order of Add and Remove calls.

func LoadSet

func LoadSet(ctx context.Context, g bs.Getter, ref bs.Ref) (*Set, error)

LoadSet loads the set at the given ref.

func NewSet

func NewSet() *Set

NewSet produces a new, empty Set, not yet written to a blob store.

func SetFromRefs

func SetFromRefs(ctx context.Context, s bs.Store, refs []bs.Ref) (*Set, bs.Ref, error)

SetFromRefs creates a Set from a slice of bs.Ref.

func (*Set) Add

func (s *Set) Add(ctx context.Context, store bs.Store, ref bs.Ref) (bs.Ref, bool, error)

Add adds a Ref to a Set. It returns the Set's own possibly-updated Ref, and a boolean indicating whether the Set was changed, which will be false if the input Ref was already present. If the Set is changed, it is written to the Store.

func (*Set) Check

func (s *Set) Check(ctx context.Context, g bs.Getter, ref bs.Ref) (bool, error)

Check checks whether ref is in s.

func (*Set) Descriptor deprecated

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

Deprecated: Use Set.ProtoReflect.Descriptor instead.

func (*Set) Each

func (s *Set) Each(ctx context.Context, g bs.Getter, f func(bs.Ref) error) error

Each calls a function for each member of the Set.

func (*Set) GetMembers

func (x *Set) GetMembers() [][]byte

func (*Set) GetNode

func (x *Set) GetNode() *TreeNode

func (*Set) ProtoMessage

func (*Set) ProtoMessage()

func (*Set) ProtoReflect

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

func (*Set) Remove

func (s *Set) Remove(ctx context.Context, store bs.Store, ref bs.Ref) (bs.Ref, bool, error)

Remove removes ref from s. It returns the set's new root ref, and a boolean indicating whether the ref was removed. (If false, the ref was not present in the set, and the root ref is unchanged.) If s is changed, it is written to the Store.

func (*Set) Reset

func (x *Set) Reset()

func (*Set) String

func (x *Set) String() string

type SubNode

type SubNode struct {
	Ref  []byte `protobuf:"bytes,1,opt,name=ref,proto3" json:"ref,omitempty"`
	Size int32  `protobuf:"varint,2,opt,name=size,proto3" json:"size,omitempty"`
	// contains filtered or unexported fields
}

func (*SubNode) Descriptor deprecated

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

Deprecated: Use SubNode.ProtoReflect.Descriptor instead.

func (*SubNode) GetRef

func (x *SubNode) GetRef() []byte

func (*SubNode) GetSize

func (x *SubNode) GetSize() int32

func (*SubNode) ProtoMessage

func (*SubNode) ProtoMessage()

func (*SubNode) ProtoReflect

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

func (*SubNode) Reset

func (x *SubNode) Reset()

func (*SubNode) String

func (x *SubNode) String() string

type TreeNode

type TreeNode struct {
	Depth int32    `protobuf:"varint,1,opt,name=depth,proto3" json:"depth,omitempty"`
	Size  int32    `protobuf:"varint,2,opt,name=size,proto3" json:"size,omitempty"`
	Left  *SubNode `protobuf:"bytes,3,opt,name=left,proto3" json:"left,omitempty"`
	Right *SubNode `protobuf:"bytes,4,opt,name=right,proto3" json:"right,omitempty"`
	// contains filtered or unexported fields
}

func (*TreeNode) Descriptor deprecated

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

Deprecated: Use TreeNode.ProtoReflect.Descriptor instead.

func (*TreeNode) GetDepth

func (x *TreeNode) GetDepth() int32

func (*TreeNode) GetLeft

func (x *TreeNode) GetLeft() *SubNode

func (*TreeNode) GetRight

func (x *TreeNode) GetRight() *SubNode

func (*TreeNode) GetSize

func (x *TreeNode) GetSize() int32

func (*TreeNode) ProtoMessage

func (*TreeNode) ProtoMessage()

func (*TreeNode) ProtoReflect

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

func (*TreeNode) Reset

func (x *TreeNode) Reset()

func (*TreeNode) String

func (x *TreeNode) String() string

Jump to

Keyboard shortcuts

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