structs

package
v0.0.0-...-720af6a Latest Latest
Warning

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

Go to latest
Published: Sep 26, 2022 License: MIT Imports: 19 Imported by: 2

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

Constants

This section is empty.

Variables

This section is empty.

Functions

func AppendListStruct

func AppendListStruct(s *Struct, fieldNum uint16, values ...*Struct) error

AppendListStruct adds the values to the list of Structs at fieldNum. Existing items will be retained.

func DeleteBool

func DeleteBool(s *Struct, fieldNum uint16) error

DeleteBool deletes a boolean and updates our storage total.

func DeleteBytes

func DeleteBytes(s *Struct, fieldNum uint16) error

DeleteBytes deletes a bytes field and updates our storage total.

func DeleteField

func DeleteField(s *Struct, fieldNum uint16)

DeleteField will delete the field entry for fieldNum.

func DeleteListBools

func DeleteListBools(s *Struct, fieldNum uint16) error

DeleteListBools deletes a list of bools field and updates our storage total.

func DeleteListBytes

func DeleteListBytes(s *Struct, fieldNum uint16) error

DeleteListBytes deletes a list of bytes field and updates our storage total.

func DeleteListNumber

func DeleteListNumber[N Number](s *Struct, fieldNum uint16) error

DeleteListNumber deletes a list of numbers field and updates our storage total.

func DeleteListStructs

func DeleteListStructs(s *Struct, fieldNum uint16) error

DeleteListStructs deletes a list of Structs field and updates our storage total.

func DeleteNumber

func DeleteNumber(s *Struct, fieldNum uint16) error

DeleteNumber deletes the number and updates our storage total.

func DeleteStruct

func DeleteStruct(s *Struct, fieldNum uint16) error

DeleteStruct deletes a Struct field and updates our storage total.

func GetBool

func GetBool(s *Struct, fieldNum uint16) (bool, error)

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

func GetBytes(s *Struct, fieldNum uint16) (*[]byte, error)

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 GetNumber

func GetNumber[N Number](s *Struct, fieldNum uint16) (N, error)

GetNumber gets a number value at fieldNum.

func MustAppendListStruct

func MustAppendListStruct(s *Struct, fieldNum uint16, values ...*Struct)

func MustGetBool

func MustGetBool(s *Struct, fieldNum uint16) bool

func MustGetBytes

func MustGetBytes(s *Struct, fieldNum uint16) *[]byte

func MustGetNumber

func MustGetNumber[N Number](s *Struct, fieldNum uint16) N

func MustSetBool

func MustSetBool(s *Struct, fieldNum uint16, value bool)

func MustSetBytes

func MustSetBytes(s *Struct, fieldNum uint16, value []byte, isString bool)

func MustSetListBool

func MustSetListBool(s *Struct, fieldNum uint16, value *Bools)

func MustSetListBytes

func MustSetListBytes(s *Struct, fieldNum uint16, value *Bytes)

func MustSetListNumber

func MustSetListNumber[N Number](s *Struct, fieldNum uint16, value *Numbers[N])

func MustSetListStrings

func MustSetListStrings(s *Struct, fieldNum uint16, value *Strings)

func MustSetListStruct

func MustSetListStruct(s *Struct, fieldNum uint16, value *Structs)

func MustSetNumber

func MustSetNumber[N Number](s *Struct, fieldNum uint16, value N)

func MustSetStruct

func MustSetStruct(s *Struct, fieldNum uint16, value *Struct)

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

func Padding(padding int) []byte

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 SetBool

func SetBool(s *Struct, fieldNum uint16, value bool) error

SetBool sets a boolean value in field "fieldNum" to value "value".

func SetBytes

func SetBytes(s *Struct, fieldNum uint16, value []byte, isString bool) error

SetBytes sets a field of bytes (also our string as well in []byte form).

func SetField

func SetField(s *Struct, fieldNum uint16, value any)

SetField sets the field value at fieldNum to value. If value isn't valid for that field, this will panic.

func SetListBool

func SetListBool(s *Struct, fieldNum uint16, value *Bools) error

func SetListBytes

func SetListBytes(s *Struct, fieldNum uint16, value *Bytes) error

func SetListNumber

func SetListNumber[N Number](s *Struct, fieldNum uint16, value *Numbers[N]) error

func SetListStructs

func SetListStructs(s *Struct, fieldNum uint16, value *Structs) error

SetListStructs deletes all existing values and puts in the passed value.

func SetNumber

func SetNumber[N Number](s *Struct, fieldNum uint16, value N) error

SetNumber sets a number value in field "fieldNum" to value "value".

func SetStruct

func SetStruct(s *Struct, fieldNum uint16, value *Struct) error

SetStruct sets a Struct field.

func SizeWithPadding

func SizeWithPadding[I constraints.Integer](size I) I

SizeWithPadding returns the complete size once padding has been applied.

func XXXAddToTotal

func XXXAddToTotal[N int64 | int | uint | uint64](s *Struct, value N)

XXXAddToTotal is used to increment the sizes of everything in a struct by some value.

Types

type Bools

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

Bools is a wrapper around a list of boolean values.

func GetListBool

func GetListBool(s *Struct, fieldNum uint16) (*Bools, error)

GetListBool returns a list of bools at fieldNum.

func MustGetListBool

func MustGetListBool(s *Struct, fieldNum uint16) *Bools

func NewBools

func NewBools(fieldNum uint16) *Bools

NewBools creates a new Bool that will be stored in a Struct field.

func (*Bools) Append

func (b *Bools) Append(i ...bool)

Append appends values to the list of bools.

func (*Bools) Encode

func (b *Bools) Encode() []byte

Encode returns the []byte to write to output to represent this Bool. If it returns nil, no output should be written.

func (*Bools) Get

func (b *Bools) Get(index int) bool

Get gets a value in the list[pos].

func (*Bools) Len

func (b *Bools) Len() int

Len returns the number of items in this list of bools.

func (*Bools) Range

func (b *Bools) Range(ctx context.Context, from, to int) chan bool

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 (*Bools) Set

func (b *Bools) Set(index int, val bool)

Set a boolean in position "pos" to "val".

func (*Bools) Slice

func (b *Bools) Slice() []bool

Slice converts this into a standard []bool. The values aren't linked, so changing []bool or calling b.Set(...) will have no affect on the other. If there are no entries, this returns a nil slice.

type Bytes

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

Bytes represents a list of bytes.

func GetListBytes

func GetListBytes(s *Struct, fieldNum uint16) (*Bytes, error)

GetListBytes returns a list of bytes at fieldNum.

func MustGetListBytes

func MustGetListBytes(s *Struct, fieldNum uint16) *Bytes

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

func NewBytesFromBytes(data *[]byte, s *Struct) (*Bytes, error)

NewBytesFromBytes returns a new Bytes value.

func (*Bytes) Append

func (b *Bytes) Append(values ...[]byte)

Append appends values to the list of []byte.

func (*Bytes) Encode

func (b *Bytes) Encode(w io.Writer) (int, error)

Encode returns the []byte to write to output to represent this Bytes. If it returns nil, no output should be written.

func (*Bytes) Get

func (b *Bytes) Get(index int) []byte

Get gets a []byte stored at the index.

func (*Bytes) Len

func (b *Bytes) Len() int

Len returns the number of items in the list.

func (*Bytes) Range

func (b *Bytes) Range(ctx context.Context, from, to int) chan []byte

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.

func (*Bytes) Set

func (b *Bytes) Set(index int, value []byte)

Set a number in position "index" to "value".

func (*Bytes) Slice

func (b *Bytes) Slice() [][]byte

Slice converts this into a standard [][]byte. The values aren't linked, so changing []bool or calling b.Set(...) will have no affect on the other. If there are no entries, this returns a nil slice.

type BytesPool

type BytesPool interface {
	Get() *[]byte
	Put(*[]byte)
}

type GenericHeader

type GenericHeader = header.Generic

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

func GetListNumber[N Number](s *Struct, fieldNum uint16) (*Numbers[N], error)

GetListNumber returns a list of numbers at fieldNum.

func MustGetListNumber

func MustGetListNumber[N Number](s *Struct, fieldNum uint16) *Numbers[N]

func NewNumbers

func NewNumbers[I Number]() *Numbers[I]

NewNumbers is used to create a holder for a list of numbers not decoded from an existing []byte stream.

func NewNumbersFromBytes

func NewNumbersFromBytes[I Number](data *[]byte, s *Struct) (*Numbers[I], error)

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

func (n *Numbers[I]) Encode() []byte

Encode returns the []byte to write to output to represent this Number. If it returns nil, no output should be written.

func (*Numbers[I]) Get

func (n *Numbers[I]) Get(index int) I

Get gets a number stored at the index.

func (*Numbers[I]) Len

func (n *Numbers[I]) Len() int

Len returns the number of items in this list.

func (*Numbers[I]) Range

func (n *Numbers[I]) Range(ctx context.Context, from, to int) chan I

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 (*Numbers[I]) Set

func (n *Numbers[I]) Set(index int, value I)

Set a number in position "index" to "value".

func (*Numbers[I]) Slice

func (n *Numbers[I]) Slice() []I

Slice converts this into a standard []I, where I is a number value. The values aren't linked, so changing []I or calling n.Set(...) will have no affect on the other. If there are no entries, this returns a nil slice.

type Strings

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

Strings represents a list of strings.

func (Strings) Append

func (s Strings) Append(values ...string)

Append appends values to the list of []byte.

func (Strings) Bytes

func (s Strings) Bytes() *Bytes

Bytes returns the underlying Bytes implementation. This is for internal use out side of that has no support.

func (Strings) Get

func (s Strings) Get(index int) string

Get gets a string stored at the index.

func (Strings) Len

func (s Strings) Len() int

Len returns the number of items in the list.

func (Strings) Range

func (s Strings) Range(ctx context.Context, from, to int) chan string

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.

func (Strings) Set

func (s Strings) Set(index int, value string)

Set a number in position "index" to "value".

func (Strings) Slice

func (s Strings) Slice() []string

Slice converts this into a standard []string. The values aren't linked, so changing []string or calling b.Set(...) will have no affect on the other. If there are no entries, this returns a nil slice.

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

func GetStruct(s *Struct, fieldNum uint16) (*Struct, error)

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 MustGetStruct(s *Struct, fieldNum uint16) *Struct

func New

func New(fieldNum uint16, dataMap *mapping.Map) *Struct

New creates a NewStruct that is used to create a *Struct for a specific data type.

func NewFromReader

func NewFromReader(r io.Reader, maps *mapping.Map) (*Struct, error)

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

func (s *Struct) IsSet(fieldNum uint16) bool

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) Map

func (s *Struct) Map() *mapping.Map

func (*Struct) Marshal

func (s *Struct) Marshal(w io.Writer) (n int, err error)

Marshal writes out the Struct to an io.Writer.

func (*Struct) NewFrom

func (s *Struct) NewFrom() *Struct

NewFrom creates a new Struct that represents the same Struct type.

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

type StructField struct {
	Header header.Generic
	Ptr    unsafe.Pointer
}

StructField holds a struct field entry.

type Structs

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

Structs represents a list of Struct.

func GetListStruct

func GetListStruct(s *Struct, fieldNum uint16) (*Structs, error)

GetListStruct returns a list of Structs at fieldNum.

func MustGetListStruct

func MustGetListStruct(s *Struct, fieldNum uint16) *Structs

func NewStructs

func NewStructs(m *mapping.Map) *Structs

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

func NewStructsFromBytes(data *[]byte, s *Struct, m *mapping.Map) (*Structs, error)

NewStructsFromBytes returns a new Bytes value.

func (*Structs) Append

func (s *Structs) Append(values ...*Struct) error

Append appends values to the list of []byte.

func (*Structs) Encode

func (s *Structs) Encode(w io.Writer) (int, error)

Encode returns the []byte to write to output to represent this Structs. If it returns nil, no output should be written.

func (*Structs) Get

func (s *Structs) Get(index int) *Struct

Get gets a *Struct stored at the index.

func (*Structs) Len

func (s *Structs) Len() int

Len returns the number of items in the list.

func (*Structs) Map

func (s *Structs) Map() *mapping.Map

Map returns the Map for all entries in this list of Structs.

func (*Structs) New

func (s *Structs) New() *Struct

New creates a new *Struct that can be stored in Structs.

func (*Structs) Range

func (s *Structs) Range(ctx context.Context, from, to int) chan *Struct

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.

func (*Structs) Set

func (s *Structs) Set(index int, value *Struct) error

Set a number in position "index" to "value".

func (*Structs) Slice

func (s *Structs) Slice() []*Struct

Slice converts this into a standard []*Struct.

type StructsPool

type StructsPool interface {
	Get() *Struct
	Put(*Struct)
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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