Documentation
¶
Overview ¶
Package structs contains objects, functions and methods that are related to reading and writing Claw struct types from wire encoding. THIS FILE IS PUBLIC ONLY OUT OF NECCESSITY AND ANY USE IS NOT PROTECTED between any versions. Seriously, your code will break if you use this.
Index ¶
- func AppendListStruct(s *Struct, fieldNum uint16, values ...*Struct) error
- func DeleteBool(s *Struct, fieldNum uint16) error
- func DeleteBytes(s *Struct, fieldNum uint16) error
- func DeleteField(s *Struct, fieldNum uint16)
- func DeleteListBools(s *Struct, fieldNum uint16) error
- func DeleteListBytes(s *Struct, fieldNum uint16) error
- func DeleteListNumber[N Number](s *Struct, fieldNum uint16) error
- func DeleteListStructs(s *Struct, fieldNum uint16) error
- func DeleteNumber(s *Struct, fieldNum uint16) error
- func DeleteStruct(s *Struct, fieldNum uint16) error
- func GetBool(s *Struct, fieldNum uint16) (bool, error)
- func GetBytes(s *Struct, fieldNum uint16) (*[]byte, error)
- func GetNumber[N Number](s *Struct, fieldNum uint16) (N, error)
- func MustAppendListStruct(s *Struct, fieldNum uint16, values ...*Struct)
- func MustGetBool(s *Struct, fieldNum uint16) bool
- func MustGetBytes(s *Struct, fieldNum uint16) *[]byte
- func MustGetNumber[N Number](s *Struct, fieldNum uint16) N
- func MustSetBool(s *Struct, fieldNum uint16, value bool)
- func MustSetBytes(s *Struct, fieldNum uint16, value []byte, isString bool)
- func MustSetListBool(s *Struct, fieldNum uint16, value *Bools)
- func MustSetListBytes(s *Struct, fieldNum uint16, value *Bytes)
- func MustSetListNumber[N Number](s *Struct, fieldNum uint16, value *Numbers[N])
- func MustSetListStrings(s *Struct, fieldNum uint16, value *Strings)
- func MustSetListStruct(s *Struct, fieldNum uint16, value *Structs)
- func MustSetNumber[N Number](s *Struct, fieldNum uint16, value N)
- func MustSetStruct(s *Struct, fieldNum uint16, value *Struct)
- func NewBoolsFromBytes(data *[]byte, s *Struct) (GenericHeader, *Bools, error)
- func Padding(padding int) []byte
- func PaddingNeeded[I constraints.Integer](size I) I
- func SetBool(s *Struct, fieldNum uint16, value bool) error
- func SetBytes(s *Struct, fieldNum uint16, value []byte, isString bool) error
- func SetField(s *Struct, fieldNum uint16, value any)
- func SetListBool(s *Struct, fieldNum uint16, value *Bools) error
- func SetListBytes(s *Struct, fieldNum uint16, value *Bytes) error
- func SetListNumber[N Number](s *Struct, fieldNum uint16, value *Numbers[N]) error
- func SetListStructs(s *Struct, fieldNum uint16, value *Structs) error
- func SetNumber[N Number](s *Struct, fieldNum uint16, value N) error
- func SetStruct(s *Struct, fieldNum uint16, value *Struct) error
- func SizeWithPadding[I constraints.Integer](size I) I
- func XXXAddToTotal[N int64 | int | uint | uint64](s *Struct, value N)
- type Bools
- type Bytes
- func (b *Bytes) Append(values ...[]byte)
- func (b *Bytes) Encode(w io.Writer) (int, error)
- func (b *Bytes) Get(index int) []byte
- func (b *Bytes) Len() int
- func (b *Bytes) Range(ctx context.Context, from, to int) chan []byte
- func (b *Bytes) Reset()
- func (b *Bytes) Set(index int, value []byte)
- func (b *Bytes) Slice() [][]byte
- type BytesPool
- type GenericHeader
- type Number
- type Numbers
- type Strings
- func (s Strings) Append(values ...string)
- func (s Strings) Bytes() *Bytes
- func (s Strings) Get(index int) string
- func (s Strings) Len() int
- func (s Strings) Range(ctx context.Context, from, to int) chan string
- func (s Strings) Reset()
- func (s Strings) Set(index int, value string)
- func (s Strings) Slice() []string
- type Struct
- type StructField
- type Structs
- func (s *Structs) Append(values ...*Struct) error
- func (s *Structs) Encode(w io.Writer) (int, error)
- func (s *Structs) Get(index int) *Struct
- func (s *Structs) Len() int
- func (s *Structs) Map() *mapping.Map
- func (s *Structs) New() *Struct
- func (s *Structs) Range(ctx context.Context, from, to int) chan *Struct
- func (s *Structs) Reset()
- func (s *Structs) Set(index int, value *Struct) error
- func (s *Structs) Slice() []*Struct
- type StructsPool
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AppendListStruct ¶
AppendListStruct adds the values to the list of Structs at fieldNum. Existing items will be retained.
func DeleteBool ¶
DeleteBool deletes a boolean and updates our storage total.
func DeleteBytes ¶
DeleteBytes deletes a bytes field and updates our storage total.
func DeleteField ¶
DeleteField will delete the field entry for fieldNum.
func DeleteListBools ¶
DeleteListBools deletes a list of bools field and updates our storage total.
func DeleteListBytes ¶
DeleteListBytes deletes a list of bytes field and updates our storage total.
func DeleteListNumber ¶
DeleteListNumber deletes a list of numbers field and updates our storage total.
func DeleteListStructs ¶
DeleteListStructs deletes a list of Structs field and updates our storage total.
func DeleteNumber ¶
DeleteNumber deletes the number and updates our storage total.
func DeleteStruct ¶
DeleteStruct deletes a Struct field and updates our storage total.
func GetBool ¶
GetBool gets a bool value from field at fieldNum. This return an error if the field is not a bool or fieldNum is not a valid field number. If the field is not set, it returns false with no error.
func GetBytes ¶
GetBytes returns a field of bytes (also our string as well in []byte form). If the value was not set, this is returned as nil. If it was set, but empty, this will be []byte{}. It is UNSAFE to modify this.
func MustAppendListStruct ¶
func MustGetBool ¶
func MustGetBytes ¶
func MustGetNumber ¶
func MustSetBool ¶
func MustSetListBool ¶
func MustSetListBytes ¶
func MustSetListNumber ¶
func MustSetListStrings ¶
func MustSetListStruct ¶
func MustSetNumber ¶
func MustSetStruct ¶
func NewBoolsFromBytes ¶
func NewBoolsFromBytes(data *[]byte, s *Struct) (GenericHeader, *Bools, error)
NewBoolsFromBytes returns a new Bool value and advances "data" passed the list.
func Padding ¶
Padding returns a pre-allocated []byte that represents the padding we need to align to 64 bits.
func PaddingNeeded ¶
func PaddingNeeded[I constraints.Integer](size I) I
PaddingNeeded returns the amount of padding needed for size to align 64 bits.
func SetField ¶
SetField sets the field value at fieldNum to value. If value isn't valid for that field, this will panic.
func SetListNumber ¶
func SetListStructs ¶
SetListStructs deletes all existing values and puts in the passed value.
func SizeWithPadding ¶
func SizeWithPadding[I constraints.Integer](size I) I
SizeWithPadding returns the complete size once padding has been applied.
Types ¶
type Bools ¶
type Bools struct {
// contains filtered or unexported fields
}
Bools is a wrapper around a list of boolean values.
func GetListBool ¶
GetListBool returns a list of bools at fieldNum.
func MustGetListBool ¶
func (*Bools) Encode ¶
Encode returns the []byte to write to output to represent this Bool. If it returns nil, no output should be written.
func (*Bools) Range ¶
Range ranges from "from" (inclusive) to "to" (exclusive). You must read values from Range until the returned channel closes or cancel the Context passed. Otherwise you will have a goroutine leak.
type Bytes ¶
type Bytes struct {
// contains filtered or unexported fields
}
Bytes represents a list of bytes.
func GetListBytes ¶
GetListBytes returns a list of bytes at fieldNum.
func MustGetListBytes ¶
func NewBytes ¶
func NewBytes() *Bytes
NewBytes returns a new Bytes for holding lists of bytes. This is used when creating a new list not attached to a Struct yet.
func NewBytesFromBytes ¶
NewBytesFromBytes returns a new Bytes value.
func (*Bytes) Encode ¶
Encode returns the []byte to write to output to represent this Bytes. If it returns nil, no output should be written.
func (*Bytes) Range ¶
Range ranges from "from" (inclusive) to "to" (exclusive). You must read values from Range until the returned channel closes or cancel the Context passed. Otherwise you will have a goroutine leak. You should NOT modify the returned []byte slice.
func (*Bytes) Reset ¶
func (b *Bytes) Reset()
Reset resets all the internal fields to their zero value.
type GenericHeader ¶
GenericHeader is the header of struct.
func NewGenericHeader ¶
func NewGenericHeader() GenericHeader
type Number ¶
type Number interface { constraints.Integer | constraints.Float }
Number represents all int, uint and float types.
type Numbers ¶
type Numbers[I Number] struct { // contains filtered or unexported fields }
Numbers represents a list of numbers
func GetListNumber ¶
GetListNumber returns a list of numbers at fieldNum.
func NewNumbers ¶
NewNumbers is used to create a holder for a list of numbers not decoded from an existing []byte stream.
func NewNumbersFromBytes ¶
NewNumbersFromBytes returns a new Number value.
func (*Numbers[I]) Append ¶
func (n *Numbers[I]) Append(i ...I)
Append appends values to the list of numbers.
func (*Numbers[I]) Encode ¶
Encode returns the []byte to write to output to represent this Number. If it returns nil, no output should be written.
func (*Numbers[I]) Range ¶
Range ranges from "from" (inclusive) to "to" (exclusive). You must read values from Range until the returned channel closes or cancel the Context passed. Otherwise you will have a goroutine leak.
type Strings ¶
type Strings struct {
// contains filtered or unexported fields
}
Strings represents a list of strings.
func (Strings) Bytes ¶
Bytes returns the underlying Bytes implementation. This is for internal use out side of that has no support.
func (Strings) Range ¶
Range ranges from "from" (inclusive) to "to" (exclusive). You must read values from Range until the returned channel closes or cancel the Context passed. Otherwise you will have a goroutine leak. You should NOT modify the returned []byte slice.
func (Strings) Reset ¶
func (s Strings) Reset()
Reset resets all the internal fields to their zero value. Slices are not nilled, but are set to their zero size to hold the capacity.
type Struct ¶
type Struct struct {
// contains filtered or unexported fields
}
Struct is the basic type for holding a set of values. In claw format, every variable must be contained in a Struct.
func GetStruct ¶
GetStruct returns a Struct field . If the value was not set, this is returned as nil. If it was set, but empty, this will be *Struct with no data.
func MustGetStruct ¶
func NewFromReader ¶
NewFromReader creates a new Struct from data we read in.
func (*Struct) Fields ¶
func (s *Struct) Fields() []StructField
Fields returns the list of StructFields.
func (*Struct) IsSet ¶
IsSet determines if our Struct has a field set or not. If the fieldNum is invalid, this simply returns false. If NoZeroTypeCompression is NOT set, then we will return true for all scaler values, string and bytes.
func (*Struct) XXXSetNoZeroTypeCompression ¶
func (s *Struct) XXXSetNoZeroTypeCompression()
XXXSetNoZeroTypeCompression sets the Struct to output scalar value headers even if the value is set to the zero value of the type. This makes the size larger but allows detection if the field was set to 0 versus being a zero value. As with all XXXFunName, this is meant to be used internally. Using this otherwise can have bad effects and there is no compatibility promise around it.
type StructField ¶
StructField holds a struct field entry.
type Structs ¶
type Structs struct {
// contains filtered or unexported fields
}
Structs represents a list of Struct.
func GetListStruct ¶
GetListStruct returns a list of Structs at fieldNum.
func MustGetListStruct ¶
func NewStructs ¶
NewStructs returns a new Structs for holding lists of Structs. This is used when creating a new list not attached to a Struct yet.
func NewStructsFromBytes ¶
NewStructsFromBytes returns a new Bytes value.
func (*Structs) Encode ¶
Encode returns the []byte to write to output to represent this Structs. If it returns nil, no output should be written.
func (*Structs) Range ¶
Range ranges from "from" (inclusive) to "to" (exclusive). You must read values from Range until the returned channel closes or cancel the Context passed. Otherwise you will have a goroutine leak.
func (*Structs) Reset ¶
func (s *Structs) Reset()
Reset resets all the internal fields to their zero value. This should only be used when recycling the Structs as it does not reset parent size counters.