cbor

package
v0.26.17-access-fix-dy... Latest Latest
Warning

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

Go to latest
Published: Aug 9, 2022 License: AGPL-3.0 Imports: 13 Imported by: 4

Documentation

Index

Constants

View Source
const (
	CodeMin = iota + 1

	// consensus
	CodeBlockProposal
	CodeBlockVote

	// protocol state sync
	CodeSyncRequest
	CodeSyncResponse
	CodeRangeRequest
	CodeBatchRequest
	CodeBlockResponse

	// cluster consensus
	CodeClusterBlockProposal
	CodeClusterBlockVote
	CodeClusterBlockResponse

	// collections, guarantees & transactions
	CodeCollectionGuarantee
	CodeTransaction
	CodeTransactionBody

	// core messages for execution & verification
	CodeExecutionReceipt
	CodeResultApproval

	// execution state synchronization
	CodeExecutionStateSyncRequest
	CodeExecutionStateDelta

	// data exchange for execution of blocks
	CodeChunkDataRequest
	CodeChunkDataResponse

	// result approvals
	CodeApprovalRequest
	CodeApprovalResponse

	// generic entity exchange engines
	CodeEntityRequest
	CodeEntityResponse

	// testing
	CodeEcho

	// DKG
	CodeDKGMessage

	CodeMax
)

Variables

View Source
var ChannelToMsgCodes map[network.Channel][]uint8

ChannelToMsgCodes is a mapping of network channels to the cbor codec code's of the messages communicated on them. Each network channel has a list of messages that are expected to be communicated on them.

Functions

This section is empty.

Types

type Codec

type Codec struct {
}

Codec represents a CBOR codec for our network.

func NewCodec

func NewCodec() *Codec

NewCodec creates a new CBOR codec.

func (*Codec) Decode

func (c *Codec) Decode(data []byte) (interface{}, error)

Decode will, given a []byte 'envelope', return a Golang interface 'v'. Return an error if unpacking the envelope fails. NOTE: 'v' is the network message payload in un-serialized form. NOTE: 'code' is the message type. NOTE: 'what' is the 'code' name for debugging / instrumentation. NOTE: 'envelope' contains 'code' & serialized / encoded 'v'. i.e. 1st byte is 'code' and remaining bytes are CBOR encoded 'v'.

func (*Codec) DecodeMsgType added in v0.26.0

func (c *Codec) DecodeMsgType(data []byte) (byte, string, error)

DecodeMsgType is a helper func that returns the first byte of cbor encoded data which corresponds to the message type. This allows users of the codec to have an explicit dependency on this specific property of encoding with the cbor codec. You should not directly interpret the message type in code. i:e msgType := data[0], instead use this func.

func (*Codec) Encode

func (c *Codec) Encode(v interface{}) ([]byte, error)

Encode will, given a Golang interface 'v', return a []byte 'envelope'. Return an error if packing the envelope fails. NOTE: 'v' is the network message payload in unserialized form. NOTE: 'code' is the message type. NOTE: 'what' is the 'code' name for debugging / instrumentation. NOTE: 'envelope' contains 'code' & serialized / encoded 'v'. i.e. 1st byte is 'code' and remaining bytes are CBOR encoded 'v'.

func (*Codec) NewDecoder

func (c *Codec) NewDecoder(r io.Reader) network.Decoder

NewDecoder creates a new CBOR decoder with the given underlying reader.

func (*Codec) NewEncoder

func (c *Codec) NewEncoder(w io.Writer) network.Encoder

NewEncoder creates a new CBOR encoder with the given underlying writer.

type Decoder

type Decoder struct {
	// contains filtered or unexported fields
}

Decoder implements a stream decoder for CBOR.

func (*Decoder) Decode

func (d *Decoder) Decode() (interface{}, error)

Decode will decode the next CBOR value from the stream.

type Encoder

type Encoder struct {
	// contains filtered or unexported fields
}

Encoder is an encoder to write serialized CBOR to a writer.

func (*Encoder) Encode

func (e *Encoder) Encode(v interface{}) error

Encode will convert the given message into CBOR and write it to the underlying encoder, followed by a new line.

Jump to

Keyboard shortcuts

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