Help us shape the future of Go! Take the 2026 Go Developer Survey

cbor

package
v0.45.2 Latest Latest
Warning

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

Go to latest
Published: Jan 30, 2026 License: AGPL-3.0 Imports: 9 Imported by: 4

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

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 returns a new cbor Codec with the provided EncMode and DecMode. If either is nil, the default cbor EncMode/DecMode will be used.

CAUTION: this encoding should only be used for encoding/decoding data within a node. If used for decoding data that is shared between nodes, it makes the recipient VULNERABLE to RESOURCE EXHAUSTION ATTACKS, where a byzantine sender could include garbage data in the encoding, which would not be noticed by the recipient because the garbage data is dropped at the decoding step - yet, it consumes the recipient's networking bandwidth.

func (*Codec) Decode

func (c *Codec) Decode(data []byte) (messages.UntrustedMessage, 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'. Expected error returns during normal operations:

  • codec.ErrInvalidEncoding if message encoding is invalid.
  • codec.ErrUnknownMsgCode if message code byte does not match any of the configured message codes.
  • codec.ErrMsgUnmarshal if the codec fails to unmarshal the data to the message type denoted by the message code.

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() (messages.UntrustedMessage, error)

Decode will decode the next CBOR value from the stream. Expected error returns during normal operations:

  • codec.ErrInvalidEncoding if message encoding is invalid.
  • codec.ErrUnknownMsgCode if message code byte does not match any of the configured message codes.
  • codec.ErrMsgUnmarshal if the codec fails to unmarshal the data to the message type denoted by the message code.

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