Documentation
¶
Index ¶
- Constants
- func DatumAsByte(datum Datum) []byte
- func EncodeIDs(ids ...ID) []byte
- func LabelAsByte(label Label) []byte
- func LanguageAsByte(language Language) []byte
- func MarshalID(value ID) ([]byte, error)
- func MarshalIDs(dst []byte, ids ...ID) error
- func UnmarshalID(dest *ID, src []byte) error
- func UnmarshalIDs(src []byte, dests ...*ID) error
- type Datum
- type ID
- func (id ID) Compare(other ID) int
- func (id *ID) Decode(src []byte)
- func (id ID) Encode(dest []byte)
- func (id *ID) GobDecode(src []byte) error
- func (id ID) GobEncode() ([]byte, error)
- func (id *ID) Inc() (next ID)
- func (id ID) Int(value *big.Int) *big.Int
- func (id *ID) LoadInt(value *big.Int) *ID
- func (id *ID) Reset()
- func (id ID) String() string
- func (id ID) Valid() bool
- type Label
- type Language
Examples ¶
Constants ¶
const IDLen = 4
IDLen is the size of an encoded ID struct in bytes
Variables ¶
This section is empty.
Functions ¶
func DatumAsByte ¶
DatumAsByte encodes a datum as a set of bytes.
func EncodeIDs ¶
EncodeIDs encodes IDs into a new slice of bytes. Each id is encoded sequentially using [Encode].
func LabelAsByte ¶
LabelAsByte encodes a label as a set of bytes.
func LanguageAsByte ¶ added in v0.0.3
LanguageAsByte encodes a language as a set of bytes.
func MarshalIDs ¶
MarshalIDs is like EncodeIDs, but also takes a []byte to write to
func UnmarshalID ¶
UnmarshalID behaves like [dest.Decode], but produces an error when there are insufficient number of bytes in src.
func UnmarshalIDs ¶
UnmarshalIDs is like UnmarshalID but decodes into every destination passed.
Types ¶
type Datum ¶
type Datum string
Datum is the type of data used across the implementation. It may or may not be comparable.
func ByteAsDatum ¶
ByteAsDatum decodes a datum from a set of bytes.
type ID ¶
type ID struct {
// contains filtered or unexported fields
}
ID uniquely identifies an object within this implementation. Not all IDs are valid, see [Valid].
Example ¶
// create a new zero -- which isn't valid var zero ID fmt.Println(zero) fmt.Println(zero.Valid()) // increment the id -- it is now valid fmt.Println(zero.Inc()) fmt.Println(zero.Valid()) // create the value 10 var ten ID for i := 0; i < 10; i++ { ten.Inc() } // compare it with other ids fmt.Println(zero.Compare(ten)) // 0 < 10 fmt.Println(ten.Compare(zero)) // 10 > 0 fmt.Println(ten.Compare(ten)) // 10 == 10
Output: ID(0) false ID(1) true -1 1 0
func DecodeIDs ¶
DecodeIDs decodes a set of ids encoded with EncodeIDs. The behavior of slices that do not evenly divide into IDs is not defined.
func (ID) Compare ¶
Compare compares this ID to another id, based on how many times Inc() has been called. The result will be 0 if id == other, -1 if id < other, and +1 if id > other.
func (*ID) Decode ¶
Decode sets this id to be the values that has been decoded from src. src must be of at least size IDLen, or a runtime panic occurs.
func (ID) Encode ¶
Encode encodes id using a big endian encoding into dest. dest must be of at least size IDLen.
func (*ID) Inc ¶
Inc increments this ID, and then returns a copy of the new value. It is the equivalent of the "++" operator.
When Inc() exceeds the maximum possible value for an ID, panics.
func (ID) Int ¶
Int writes the numerical value of this id into the given big int. The big.Int is returned for convenience.
func (*ID) LoadInt ¶
LoadInt sets the value of this id as an integer and returns it. Trying to load an integer bigger than the maximal id results in a panic.
The ID is returned for convenience.