streamable

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Mar 17, 2024 License: Apache-2.0 Imports: 6 Imported by: 0

README

Streamable

This package implements the chia streamable format. Not all aspects of the streamable format are fully implemented, and support for more types are added as protocol messages are added to this package. This is not intended to be used in consensus critical applications and there may be unexpected errors for untested streamable objects.

For more information on the streamable format, see the streamable docs

How to Use

When defining structs that are streamable, the order of the fields is extremely important, and should match the order of the fields in chia-blockchain. To support struct fields that are not defined in chia-blockchain, streamable objects require a streamable tag on each field of the struct that should be streamed.

Example Type Definition:

// TimestampedPeerInfo contains information about peers with timestamps
type TimestampedPeerInfo struct {
	Host      string `streamable:""`
	Port      uint16 `streamable:""`
	Timestamp uint64 `streamable:""`
}

For a given streamable object, the interface is very similar to json marshal/unmarshal.

Encode to Bytes

peerInfo := &TimestampedPeerInfo{....}
bytes, err := streamable.Marshal(peerInfo)

Decode to Struct

peerInfo := &TimestampedPeerInfo{}
err := streamable.Unmarshal(bytes, peerInfo)

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Marshal

func Marshal(v interface{}) ([]byte, error)

Marshal marshals the item into the streamable byte format

func Unmarshal

func Unmarshal(bytes []byte, v interface{}) error

Unmarshal unmarshals a streamable type based on struct tags Struct order is extremely important in this decoding. Ensure the order/types are identical on both sides of the stream

Types

type InvalidUnmarshalError

type InvalidUnmarshalError struct {
	Type reflect.Type
}

An InvalidUnmarshalError describes an invalid argument passed to Unmarshal. (The argument to Unmarshal must be a non-nil pointer.)

func (*InvalidUnmarshalError) Error

func (e *InvalidUnmarshalError) Error() string

Error outputs the error message and satisfies the Error interface

Jump to

Keyboard shortcuts

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