modulepackage
0.0.0-20240116150400-b058b4376d53
Repository: https://github.com/streamingfast/binary.git
Documentation: pkg.go.dev
# README
StreamingFast binary
Binary Encoder and Decoder library
Usage
Struct Field Tags
_
will skip the field when encoding & deocode a strucsizeof=
indicates this field is a number used to track the length of a another field.little
indicates this field will be encoded as little endianbig
indicates this field will be encoded as big endianoptional
indicates this field is optional. An optional field will have an initial byte either0x00
or0x01
indicating whether the field is present. If the field is present it will be followed by the value.- Bare values will be parsed as type and little endian when necessary
Supported Types
int8
,int16
,int32
,int64
,Int128
uint8
,uint16
,uint32
,uint64
,Uint128
float32
,float64
,Float128
string
,bool
Varint16
,Varint32
Varuint16
,Varuint32
Custom Types
To implement custom types, your types would need to implement the MarshalerBinary
& UnmarshalerBinary
interfaces
Example
Basic Implementation
type Example struct {
Var uint32 `bin:"_"`
Str string
IntCount uint32 `bin:"sizeof=Var"`
Weird [8]byte
Var []int
}
Custom Implementation
type Example struct {
Prefix byte
Value uint32
}
func (e *Example) UnmarshalBinary(decoder *Decoder) (err error) {
if e.Prefix, err = decoder.ReadByte(); err != nil {
return err
}
if e.Value, err = decoder.ReadUint32(BE()); err != nil {
return err
}
return nil
}
func (e *Example) MarshalBinary(encoder *Encoder) error {
if err := encoder.WriteByte(e.Prefix); err != nil {
return err
}
return encoder.WriteUint32(e.Value, BE())
}
Contributing
Issues and PR in this repo related strictly to the binary library
Report any protocol-specific issues in their respective repositories
Please first refer to the general StreamingFast contribution guide, if you wish to contribute to this code base.
This codebase uses unit tests extensively, please write and run tests.
License
# Functions
No description provided by the author
ByteCount computes the byte count size for the received populated structure.
No description provided by the author
No description provided by the author
MustByteCount acts just like ByteCount but panics if it encounters any encoding errors.
No description provided by the author
No description provided by the author
NewVariantDefinition creates a variant definition based on the *ordered* provided types.
# Constants
No description provided by the author
No description provided by the author
No description provided by the author
# Variables
No description provided by the author
No description provided by the author
# Structs
No description provided by the author
Decoder implements the EOS unpacking, similar to FC_BUFFER.
No description provided by the author
An InvalidDecoderError describes an invalid argument passed to Decoder.
uint128.
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
# Type aliases
No description provided by the author
No description provided by the author
No description provided by the author
Int128.
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