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
- Variables
- func DecodeSnappy(msg []byte, maxSize uint64) ([]byte, error)
- type NetworkEncoding
- type SszNetworkEncoder
- func (_ SszNetworkEncoder) DecodeGossip(b []byte, to fastssz.Unmarshaler) error
- func (e SszNetworkEncoder) DecodeWithMaxLength(r io.Reader, to fastssz.Unmarshaler) error
- func (_ SszNetworkEncoder) EncodeGossip(w io.Writer, msg fastssz.Marshaler) (int, error)
- func (_ SszNetworkEncoder) EncodeWithMaxLength(w io.Writer, msg fastssz.Marshaler) (int, error)
- func (_ SszNetworkEncoder) MaxLength(length uint64) (int, error)
- func (_ SszNetworkEncoder) ProtocolSuffix() string
Constants ¶
const ProtocolSuffixSSZSnappy = "ssz_snappy"
ProtocolSuffixSSZSnappy is the last part of the topic string to identify the encoding protocol.
Variables ¶
var MaxChunkSize = params.BeaconConfig().MaxChunkSize // 10 Mib.
var MaxGossipSize = params.BeaconConfig().GossipMaxSize // 10 Mib.
MaxGossipSize allowed for gossip messages.
Functions ¶
Types ¶
type NetworkEncoding ¶
type NetworkEncoding interface { // DecodeGossip to the provided gossip message. The interface must be a pointer to the decoding destination. DecodeGossip([]byte, ssz.Unmarshaler) 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, ssz.Unmarshaler) error // EncodeGossip an arbitrary gossip message to the provided writer. The interface must be a pointer object to encode. EncodeGossip(io.Writer, ssz.Marshaler) (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, ssz.Marshaler) (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 consensus p2p.
type SszNetworkEncoder ¶
type SszNetworkEncoder struct{}
SszNetworkEncoder supports p2p networking encoding using SimpleSerialize with snappy compression (if enabled).
func (SszNetworkEncoder) DecodeGossip ¶
func (_ SszNetworkEncoder) DecodeGossip(b []byte, to fastssz.Unmarshaler) error
DecodeGossip decodes the bytes to the protobuf gossip message provided.
func (SszNetworkEncoder) DecodeWithMaxLength ¶
func (e SszNetworkEncoder) DecodeWithMaxLength(r io.Reader, to fastssz.Unmarshaler) 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 ¶
EncodeGossip the proto gossip message to the io.Writer.
func (SszNetworkEncoder) EncodeWithMaxLength ¶
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) MaxLength ¶
func (_ SszNetworkEncoder) MaxLength(length uint64) (int, error)
MaxLength specifies the maximum possible length of an encoded chunk of data.
func (SszNetworkEncoder) ProtocolSuffix ¶
func (_ SszNetworkEncoder) ProtocolSuffix() string
ProtocolSuffix returns the appropriate suffix for protocol IDs.