2019-08-14 01:37:45 +00:00
|
|
|
package encoder
|
|
|
|
|
2019-08-14 21:18:32 +00:00
|
|
|
import (
|
|
|
|
"io"
|
|
|
|
)
|
2019-08-14 01:37:45 +00:00
|
|
|
|
2019-08-21 16:33:48 +00:00
|
|
|
// Defines the different encoding formats
|
|
|
|
const (
|
|
|
|
SSZ = "ssz" // SSZ is SSZ only.
|
|
|
|
SSZSnappy = "ssz-snappy" // SSZSnappy is SSZ with snappy compression.
|
|
|
|
)
|
|
|
|
|
2019-08-14 01:37:45 +00:00
|
|
|
// NetworkEncoding represents an encoder compatible with Ethereum 2.0 p2p.
|
|
|
|
type NetworkEncoding interface {
|
2020-04-15 03:03:44 +00:00
|
|
|
// Decode to the provided message. The interface must be a pointer to the decoding destination.
|
2019-09-10 14:24:14 +00:00
|
|
|
Decode([]byte, interface{}) error
|
2020-04-15 03:03:44 +00:00
|
|
|
// DecodeGossip to the provided gossip message. The interface must be a pointer to the decoding destination.
|
|
|
|
DecodeGossip([]byte, interface{}) error
|
2019-09-10 14:24:14 +00:00
|
|
|
// 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
|
2019-09-24 14:56:50 +00:00
|
|
|
// 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
|
2019-09-10 14:24:14 +00:00
|
|
|
// Encode an arbitrary message to the provided writer. The interface must be a pointer object to encode.
|
|
|
|
Encode(io.Writer, interface{}) (int, error)
|
2020-04-15 03:03:44 +00:00
|
|
|
// EncodeGossip an arbitrary gossip message to the provided writer. The interface must be a pointer object to encode.
|
|
|
|
EncodeGossip(io.Writer, interface{}) (int, error)
|
2019-09-10 14:24:14 +00:00
|
|
|
// 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)
|
2019-09-24 14:56:50 +00:00
|
|
|
// 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)
|
2019-08-14 21:18:32 +00:00
|
|
|
// ProtocolSuffix returns the last part of the protocol ID to indicate the encoding scheme.
|
|
|
|
ProtocolSuffix() string
|
2019-08-14 01:37:45 +00:00
|
|
|
}
|