encoder

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Feb 4, 2025 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CBorEncoder

type CBorEncoder struct {
	EncOpts cbor.EncOptions
}

CBorEncoder is a concrete implementation of the Encoder interface that uses the CBOR (Concise Binary Object Representation) encoding format for serializing and deserializing data.

func NewCBorCustomEncoder

func NewCBorCustomEncoder(encOpts cbor.EncOptions) *CBorEncoder

NewCBorCustomEncoder creates and returns a new instance of CBorEncoder with custom encoding options passed as an argument.

func NewCBorEncoder

func NewCBorEncoder() *CBorEncoder

NewCBorEncoder creates and returns a new instance of CBorEncoder with default encoding options (unsorted keys).

func (*CBorEncoder) Marshal

func (g *CBorEncoder) Marshal(value any) ([]byte, error)

Marshal implements Encoder. It converts a Go value into a byte slice using the CBOR encoding format with the specified encoding options.

func (*CBorEncoder) Unmarshal

func (g *CBorEncoder) Unmarshal(data []byte, value any) error

Unmarshal implements Encoder. It decodes a byte slice into a Go value using the CBOR encoding format.

type Encoder

type Encoder interface {
	// Marshal encodes a Go value into a byte slice (e.g., JSON, CBOR, etc.).
	Marshal(value any) ([]byte, error)
	// Unmarshal decodes a byte slice into a Go value (e.g., JSON, CBOR, etc.).
	Unmarshal(data []byte, value any) error
}

Encoder defines the interface for types that handle encoding and decoding of data.

type GobEncoder

type GobEncoder struct {
}

GobEncoder is a concrete implementation of the Encoder interface that uses the Gob encoding format for serializing and deserializing data.

func NewGobEncoder

func NewGobEncoder() *GobEncoder

NewGobEncoder creates and returns a new instance of GobEncoder.

func (*GobEncoder) Marshal

func (g *GobEncoder) Marshal(value any) ([]byte, error)

Marshal implements Encoder. It converts a Go value into a byte slice using the Gob encoding format.

func (*GobEncoder) Unmarshal

func (g *GobEncoder) Unmarshal(data []byte, value any) error

Unmarshal implements Encoder. It decodes a byte slice into a Go value using the Gob encoding format.

type JsonEncoder

type JsonEncoder struct{}

JsonEncoder implements the Encoder interface for encoding and decoding data in JSON format.

func NewJsonEncoder

func NewJsonEncoder() *JsonEncoder

NewJsonEncoder creates and returns a new instance of JsonEncoder.

func (*JsonEncoder) Marshal

func (j *JsonEncoder) Marshal(value any) ([]byte, error)

Marshal implements the Encoder interface method for marshaling (encoding) a Go value into JSON bytes.

func (*JsonEncoder) Unmarshal

func (j *JsonEncoder) Unmarshal(data []byte, v any) error

Unmarshal implements the Encoder interface method for unmarshaling (decoding) JSON bytes into a Go value.

Jump to

Keyboard shortcuts

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