codec

package
v1.1.1 Latest Latest
Warning

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

Go to latest
Published: Dec 28, 2023 License: MIT Imports: 17 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CvpCodec

type CvpCodec interface {
	// EncodeStreamingLightValidators encodes the given light validators information into sorter string for streaming.
	// Input is assumed to be valid, otherwise panic.
	EncodeStreamingLightValidators(types.StreamingLightValidators) []byte

	// DecodeStreamingLightValidators decodes the given string into light validators.
	DecodeStreamingLightValidators([]byte) (types.StreamingLightValidators, error)

	// EncodeStreamingNextBlockVotingInformation encodes the given next block voting information into sorter string for streaming.
	// Input is assumed to be valid, otherwise panic.
	EncodeStreamingNextBlockVotingInformation(*types.StreamingNextBlockVotingInformation) []byte

	// DecodeStreamingNextBlockVotingInformation decodes the given string into next block voting information.
	DecodeStreamingNextBlockVotingInformation([]byte) (*types.StreamingNextBlockVotingInformation, error)

	// GetVersion returns the implementation version of this codec instance.
	//
	// In case a proxy CvpCodec, it returns the underlying implementation version
	// which set by NewProxyCvpCodec (default) or WrapCvpCodecInProxy (specify).
	GetVersion() CvpCodecVersion
}

CvpCodec is the interface for encoding and decoding streaming data.

func GetCvpCodecV1 deprecated added in v1.1.0

func GetCvpCodecV1() CvpCodec

GetCvpCodecV1 returns genesis version of CvpCodec.

Deprecated: use NewProxyCvpCodec for the latest and compatible version.

func GetCvpCodecV2 added in v1.1.0

func GetCvpCodecV2() CvpCodec

GetCvpCodecV2 returns new instance of v2 implementation of CvpCodec.

V2 output smaller size of encoded data than v1. But still not as small as v3 (gzip version of v2).

func GetCvpCodecV3 added in v1.1.0

func GetCvpCodecV3() CvpCodec

GetCvpCodecV3 returns new instance of CvpCodec that actually encode data using v2 codec then gzip it. Procedures smaller data than v2 codec in most cases with large data size. But slower than v2 codec, ofc.

func NewProxyCvpCodec

func NewProxyCvpCodec() CvpCodec

NewProxyCvpCodec returns new instance of proxy CvpCodec.

The proxy automatically detect version of encoded data and forward to the corresponding implementation for decoding.

When invoking encode functions, it forward to default CvpCodec version.

func WrapCvpCodecInProxy added in v1.1.0

func WrapCvpCodecInProxy(inner CvpCodec) CvpCodec

WrapCvpCodecInProxy wraps a CvpCodec into a proxy CvpCodec.

The proxy automatically detect version of encoded data and forward to the corresponding implementation for decoding.

When invoking encode functions, it forward to the provided version.

type CvpCodecVersion added in v1.1.0

type CvpCodecVersion string
const (
	CvpCodecVersionUnknown CvpCodecVersion = "unknown"
	CvpCodecVersionV1      CvpCodecVersion = "v1"
	CvpCodecVersionV2      CvpCodecVersion = "v2"
	CvpCodecVersionV3      CvpCodecVersion = "v3"
)

func DetectEncodingVersion added in v1.1.1

func DetectEncodingVersion(bz []byte) (possible CvpCodecVersion, detected bool)

DetectEncodingVersion will try to detect the encoding version of the given byte array based on the very first bytes. The returned version is 'possible' because it is not guaranteed to be the correct version without actual decode it.

Jump to

Keyboard shortcuts

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