format

package
v0.0.0-...-c4446b5 Latest Latest
Warning

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

Go to latest
Published: Mar 31, 2025 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ListElementSize_Small = 2
	ListElementSize_Big   = 4
)
View Source
const (
	MessageFieldSize_Small = 1 + 2 // tag(1) + offset(2)
	MessageFieldSize_Big   = 2 + 4 // tag(2) + offset(4)
)
View Source
const (
	MaxSize = math.MaxInt32
)

Variables

This section is empty.

Functions

func IsBigList

func IsBigList(elements []ListElement) bool

IsBigList returns true if table count > uint8 or element offset > uint16.

func IsBigMessage

func IsBigMessage(fields []MessageField) bool

IsBigList returns true if any field tag > uint8 or offset > uint16.

Types

type Bytes

type Bytes []byte

Bytes is a spec byte slice backed by a buffer. Clone it if you need to keep it around.

func (Bytes) Clone

func (b Bytes) Clone() []byte

Clone returns a bytes clone allocated on the heap.

func (Bytes) Unwrap

func (b Bytes) Unwrap() []byte

Unwrap returns a byte slice.

type ListElement

type ListElement struct {
	Offset uint32
}

ListElement specifies a value offset in a list byte array.

+-------------------+
|    offset(2/4)    |
+-------------------+

func TestElements

func TestElements() []ListElement

func TestElementsN

func TestElementsN(n int) []ListElement

func TestElementsSize

func TestElementsSize(big bool) []ListElement

func TestElementsSizeN

func TestElementsSizeN(big bool, n int) []ListElement

type ListTable

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

ListTable is a serialized array of list element offsets ordered by index. The serialization format depends on whether the list is big or small, see IsBigList().

+----------------+----------------+----------------+
|    off0(2/4)   |    off1(2/4)   |    off2(2/4)   |
+----------------+----------------+----------------+

func NewListTable

func NewListTable(table listTable, data uint32, big bool) ListTable

func (ListTable) DataSize

func (t ListTable) DataSize() uint32

DataSize returns the size of the list data.

func (ListTable) Elements

func (t ListTable) Elements() []ListElement

Elements parses the table and returns a slice of elements.

func (ListTable) Len

func (t ListTable) Len() int

Len returns the number of elements in the table.

func (ListTable) Offset

func (t ListTable) Offset(i int) (int, int)

Offset returns an element start/end by an index or -1/-1.

type MessageField

type MessageField struct {
	Tag    uint16
	Offset uint32
}

MessageField specifies a tag and a value offset in a message byte array.

+----------+-------------------+
| tag(1/2) |    offset(2/4)    |
+----------+-------------------+

func TestFields

func TestFields() []MessageField

func TestFieldsN

func TestFieldsN(n int) []MessageField

func TestFieldsSize

func TestFieldsSize(big bool) []MessageField

func TestFieldsSizeN

func TestFieldsSizeN(big bool, n int) []MessageField

type MessageTable

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

MessageTable is a table of message fields ordered by tags. The serialization format depends on whether the message is big or small, see isBigMessage().

         field0                field1                field2
+---------------------+---------------------+---------------------+
|  tag0 |   offset0   |  tag1 |   offset1   |  tag2 |   offset3   |
+---------------------+---------------------+---------------------+

func NewMessageTable

func NewMessageTable(table messageTable, data uint32, big bool) MessageTable

func (MessageTable) DataSize

func (t MessageTable) DataSize() uint32

DataSize returns the message data size.

func (MessageTable) Field

func (t MessageTable) Field(i int) (MessageField, bool)

Field returns a field by an index or false,

func (MessageTable) Fields

func (t MessageTable) Fields() []MessageField

Fields parses the table and returns a slice of fields.

func (MessageTable) Len

func (t MessageTable) Len() int

Len returns the number of fields in the message.

func (MessageTable) Offset

func (t MessageTable) Offset(tag uint16) int

Offset returns field end offset by a tag or -1.

func (MessageTable) OffsetByIndex

func (t MessageTable) OffsetByIndex(i int) int

OffsetByIndex returns field end offset by an index or -1.

type String

type String string

String is a spec string backed by a buffer. Clone it if you need to keep it around.

func (String) Clone

func (s String) Clone() string

Clone returns a string clone allocated on the heap.

func (String) Unwrap

func (s String) Unwrap() string

Unwrap returns a string.

type Type

type Type byte

Type specifies a value type.

const (
	TypeUndefined Type = 0

	TypeTrue  Type = 01
	TypeFalse Type = 02
	TypeByte  Type = 03

	TypeInt16 Type = 10
	TypeInt32 Type = 11
	TypeInt64 Type = 12

	TypeUint16 Type = 20
	TypeUint32 Type = 21
	TypeUint64 Type = 22

	TypeFloat32 Type = 40
	TypeFloat64 Type = 41

	TypeBin64  Type = 30
	TypeBin128 Type = 31
	TypeBin256 Type = 32

	TypeBytes  Type = 50
	TypeString Type = 60

	TypeList    Type = 70
	TypeBigList Type = 71

	TypeMessage    Type = 80
	TypeBigMessage Type = 81

	TypeStruct Type = 90
)

func (Type) Check

func (t Type) Check() error

func (Type) String

func (t Type) String() string

Jump to

Keyboard shortcuts

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