Categorygithub.com/spacemeshos/go-scale
modulepackage
1.2.0
Repository: https://github.com/spacemeshos/go-scale.git
Documentation: pkg.go.dev

# README

SCALE

Types

golangnotesexample
[]bytelength prefixed byte array with length as u32 compact integer
stringsame as []byte
[...]byteappended to the result
bool1 byte, 0 for false, 1 for true
Object{}concatenation of fields
*Object{}Option. 0 for nil, 1 for Object{}. if 1 - decode Object{}
uint8compact u8 [TODO no need for compact u8]
uint16compact u16
uint32compact u32
uint34compact u64
*uint8Option (0 for nil, 1 otherwise), followed by compact u8&64 -> 01FC; &255 -> 01FD03
*uint16Option (0 for nil, 1 otherwise), followed by compact u16&255 -> 01FD03
*uint32Option (0 for nil, 1 otherwise), followed by compact u32&255 -> 01FD03
*uint64Option (0 for nil, 1 otherwise), followed by compact u64&255 -> 01FD03
[]uint16length prefixed (compact u32) followed by compact u16s[4, 15, 23, u16::MAX] -> 10103C5CFEFF0300
[]uint32length prefixed (compact u32) followed by compact u32s[4, 15, 23, u32::MAX] -> 10103C5C03FFFFFFFF
[]uint64length prefixed (compact u32) followed by compact u64s[4, 15, 23, u64::MAX] -> 10103C5C13FFFFFFFFFFFFFFFF
[...]Objectarray with objects. encoded by consecutively encoding every object
[]Objectslice with objects. prefixed with compact u32

Not implemented:

  • pointers to arrays and slices
  • slices with pointers
  • enumerations
  • fixed width integers

Code generation

go install github.com/spacemeshos/go-scale/scalegen

//go:generate scalegen will discover all struct types and derive EncodeScale/DecodeScale methods. To avoid struct auto-discovery use -types=U8,U16.

# Packages

nolint.
No description provided by the author
nolint.
No description provided by the author

# Functions

No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
LenSize returns the size in bytes required to encode a length value.
MaxScaleElements is a generic version of GetMaxElementsFromValue that uses the specified type instead of a struct value.
MaxScaleElementsForField returns the max number of elements for the specified field in the struct passed as the v argument based on the 'scale' tag.
MustGetMaxElements is the same as GetMaxElements, but returns just the max tag value and panics in case of an error.
NewDecoder returns a new decoder that reads from r.
NewEncoder returns a new encoder that writes to w.
WithDecodeMaxElements sets the maximum number of elements allowed in a collection.
WithDecodeMaxNested sets the nested level of the decoder.
WithEncodeMaxElements sets the maximum number of elements allowed in a collection.
WithEncodeMaxNested sets the nested level of the encoder.

# Constants

MaxElements is the maximum number of elements allowed in a collection if not set explicitly during encoding/decoding.
MaxNested is the maximum nested level allowed if not set explicitly during encoding/decoding.

# Variables

ErrDecodeNestedTooDeep is returned when nested level is too deep.
ErrDecodeTooManyElements is returned when scale limit tag is used and collection has too many elements to decode.
ErrEncodeNestedTooDeep is returned when the depth of nested types exceeds the limit.
ErrEncodeTooManyElements is returned when scale limit tag is used and collection has too many elements to encode.

# Structs

No description provided by the author
No description provided by the author

# Interfaces

No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author

# Type aliases

No description provided by the author