prysm-pulse/beacon-chain/p2p/encoder/network_encoding.go
Nishant Das 0db690df75 Chunked Responses (#3528)
* update naming

* replace with updated version

* more changes

* fixed all tests

* build and lint

* regen protos

* fix test

* remove outdated code

* prestons review

* add chunk size

* more fixes to chunked responses

* handle eof

* fix all tests

* abstract into common method

* add comment

* preston's comments

* preston's review

* preston's review

* lint

* add encoding methods

* gaz

* simplify

* simplify

* lint

* change naming

* update

* handle eof separately

* Apply suggestions from code review

Co-Authored-By: Preston Van Loon <preston@prysmaticlabs.com>

* remove def

* preston's review

* preston's review

* add unit tests

* add delay to fix test
2019-09-24 07:56:50 -07:00

34 lines
1.6 KiB
Go

package encoder
import (
"io"
)
// Defines the different encoding formats
const (
SSZ = "ssz" // SSZ is SSZ only.
SSZSnappy = "ssz-snappy" // SSZSnappy is SSZ with snappy compression.
)
// NetworkEncoding represents an encoder compatible with Ethereum 2.0 p2p.
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
}