encoder

package
v0.3.7 Latest Latest
Warning

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

Go to latest
Published: Mar 21, 2020 License: GPL-3.0 Imports: 6 Imported by: 27

Documentation

Overview

Package encoder allows for registering custom data encoders for information sent as raw bytes over the wire via p2p to other nodes. Examples of encoders are SSZ (SimpleSerialize), SSZ with Snappy compression, among others. Providing an abstract interface for these encoders allows for future flexibility of Ethereum beacon node p2p.

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

Variables

This section is empty.

Functions

This section is empty.

Types

type NetworkEncoding

type NetworkEncoding interface {
	// Decodes to the provided message. The interface must be a pointer to the decoding destination.
	Decode([]byte, interface{}) error
	// DecodeWithLength a bytes from a reader with a varint length prefix. The interface must be a pointer to the
	// decoding destination.
	DecodeWithLength(io.Reader, 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{}, uint64) error
	// Encode an arbitrary message to the provided writer. The interface must be a pointer object to encode.
	Encode(io.Writer, interface{}) (int, error)
	// EncodeWithLength an arbitrary message to the provided writer with a varint length prefix. The interface must be
	// a pointer object to encode.
	EncodeWithLength(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{}, uint64) (int, error)
	// ProtocolSuffix returns the last part of the protocol ID to indicate the encoding scheme.
	ProtocolSuffix() string
}

NetworkEncoding represents an encoder compatible with Ethereum 2.0 p2p.

type SszNetworkEncoder

type SszNetworkEncoder struct {
	UseSnappyCompression bool
}

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

func (SszNetworkEncoder) Decode

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

Decode the bytes to the protobuf message provided.

func (SszNetworkEncoder) DecodeWithLength

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

DecodeWithLength the bytes from io.Reader to the protobuf message provided.

func (SszNetworkEncoder) DecodeWithMaxLength

func (e SszNetworkEncoder) DecodeWithMaxLength(r io.Reader, to interface{}, maxSize uint64) 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) Encode

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

Encode the proto message to the io.Writer.

func (SszNetworkEncoder) EncodeWithLength

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

EncodeWithLength the proto message to the io.Writer. This encoding prefixes the byte slice with a protobuf varint to indicate the size of the message.

func (SszNetworkEncoder) EncodeWithMaxLength

func (e SszNetworkEncoder) EncodeWithMaxLength(w io.Writer, msg interface{}, maxSize uint64) (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) 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