encoder

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: May 22, 2024 License: ISC Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	SSZ       = "ssz"        // SSZ is SSZ only.
	SSZSnappy = "ssz-snappy" // SSZSnappy is SSZ with snappy compression.
)

Defines the different encoding formats

View Source
const (
	SszNetworkEncoderHeadSize = 16
)

SSZ network encode size for data head

Variables

View Source
var MaxChunkSize = uint64(qtypes.MaxBlockPayload + SszNetworkEncoderHeadSize) // Adjust according to block

MaxChunkSize is the the maximum allowed size of uncompressed req/resp chunked responses.

View Source
var MaxGossipSize = uint64(qtypes.MaxBlockPayload + SszNetworkEncoderHeadSize) // Adjust according to block

MaxGossipSize allowed for gossip messages. It is the maximum allowed size of uncompressed gossip messages.

Functions

This section is empty.

Types

type NetworkEncoding

type NetworkEncoding interface {
	// DecodeGossip to the provided gossip message. The interface must be a pointer to the decoding destination.
	DecodeGossip([]byte, interface{}) error
	// DecodeWithMaxLength a bytes from a reader with a varint length prefix. The interface must be a pointer to the
	// decoding destination. The length of the message should not be more than the provided limit.
	DecodeWithMaxLength(io.Reader, interface{}) error
	// EncodeGossip an arbitrary gossip message to the provided writer. The interface must be a pointer object to encode.
	EncodeGossip(io.Writer, interface{}) (int, error)
	// EncodeWithMaxLength an arbitrary message to the provided writer with a varint length prefix. The interface must be
	// a pointer object to encode. The encoded message should not be bigger than the provided limit.
	EncodeWithMaxLength(io.Writer, interface{}) (int, error)
	// ProtocolSuffix returns the last part of the protocol ID to indicate the encoding scheme.
	ProtocolSuffix() string
	// return max chunk size
	GetMaxChunkSize() uint64
	// return msg size
	GetSize(msg interface{}) int
}

NetworkEncoding represents an encoder compatible with Qitmeer 2.0 p2p.

type SszNetworkEncoder

type SszNetworkEncoder struct {
	UseSnappyCompression bool
}

SszNetworkEncoder supports p2p networking encoding using SimpleSerialize with snappy compression (if enabled).

func (SszNetworkEncoder) DecodeGossip

func (e SszNetworkEncoder) DecodeGossip(b []byte, to interface{}) error

DecodeGossip decodes the bytes to the protobuf gossip message provided.

func (SszNetworkEncoder) DecodeWithMaxLength

func (e SszNetworkEncoder) DecodeWithMaxLength(r io.Reader, to interface{}) error

DecodeWithMaxLength the bytes from io.Reader to the protobuf message provided. This checks that the decoded message isn't larger than the provided max limit.

func (SszNetworkEncoder) EncodeGossip

func (e SszNetworkEncoder) EncodeGossip(w io.Writer, msg interface{}) (int, error)

EncodeGossip the proto gossip message to the io.Writer.

func (SszNetworkEncoder) EncodeWithMaxLength

func (e SszNetworkEncoder) EncodeWithMaxLength(w io.Writer, msg interface{}) (int, error)

EncodeWithMaxLength the proto message to the io.Writer. This encoding prefixes the byte slice with a protobuf varint to indicate the size of the message. This checks that the encoded message isn't larger than the provided max limit.

func (SszNetworkEncoder) GetMaxChunkSize

func (e SszNetworkEncoder) GetMaxChunkSize() uint64

return max chunk size

func (SszNetworkEncoder) GetSize

func (e SszNetworkEncoder) GetSize(msg interface{}) int

func (SszNetworkEncoder) MaxLength

func (e SszNetworkEncoder) MaxLength(length int) int

MaxLength specifies the maximum possible length of an encoded chunk of data.

func (SszNetworkEncoder) ProtocolSuffix

func (e SszNetworkEncoder) ProtocolSuffix() string

ProtocolSuffix returns the appropriate suffix for protocol IDs.

Jump to

Keyboard shortcuts

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