encoding

package
v1.1.1 Latest Latest
Warning

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

Go to latest
Published: Aug 14, 2023 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DecodeMessagePack

func DecodeMessagePack(in []byte, out interface{}) error

DecodeMessagePack function decodes a byte slice of MessagePack data into a given object.

func DecodeString added in v1.0.9

func DecodeString(b []byte) (int, string, error)

DecodeString converts an input byte slice into a string. Arguments:

b: Input byte slice to be decoded.

Returns: - Integer: Length of byte representation of the string. - String: Decoded string. - Error: 'invalid length' if slice is empty or insufficient length, else nil.

The function reads the first byte as string length (l), creates a slice of length l and returns the formed string.

func EncodeMessagePack

func EncodeMessagePack(msg interface{}) ([]byte, error)

EncodeMessagePack function encodes a given object into MessagePack format.

func EncodeString added in v1.0.9

func EncodeString(s string) ([]byte, error)

EncodeString Functions for encoding and decoding strings to and from byte slices.

func NewMsgPackHandle added in v1.0.9

func NewMsgPackHandle() *codec.MsgpackHandle

NewMsgPackHandle is a helper function to create a new instance of MsgpackHandle

Types

type MessagePackCodec added in v1.0.9

type MessagePackCodec struct {
	MsgPack *codec.MsgpackHandle
	// contains filtered or unexported fields
}

MessagePackCodec struct, holds references to MessagePack handler and byte slice, along with Encoder and Decoder, and a typeMap for storing reflect.Type

func InitMessagePack added in v1.0.9

func InitMessagePack() MessagePackCodec

InitMessagePack function initializes MessagePackCodec struct and returns it.

func (*MessagePackCodec) AddExtension added in v1.0.9

func (m *MessagePackCodec) AddExtension(
	t reflect.Type,
	id byte,
	encoder func(reflect.Value) ([]byte, error),
	decoder func(reflect.Value, []byte) error) error

AddExtension method allows for setting custom encoders/decoders for specific reflect.Types.

func (*MessagePackCodec) Decode added in v1.0.9

func (m *MessagePackCodec) Decode(in []byte, out interface{}) error

Decode on MessagePackCodec type, using a byte slice as input.

func (*MessagePackCodec) Encode added in v1.0.9

func (m *MessagePackCodec) Encode(msg interface{}) ([]byte, error)

Encode method for MessagePackCodec. It encodes the input value into a byte slice using MessagePack. Returns encoded byte slice or error.

type MessagePackCodecDecoder added in v1.0.9

type MessagePackCodecDecoder struct {
	*MessagePackCodec
}

MessagePackCodecDecoder struct, holds a reference to a MessagePackCodec instance.

func NewMessagePackDecoder added in v1.0.9

func NewMessagePackDecoder(b []byte) *MessagePackCodecDecoder

NewMessagePackDecoder function takes in a byte slice, and returns a pointer to newly created and initialized MessagePackCodecDecoder

func (*MessagePackCodecDecoder) Decode added in v1.0.9

func (m *MessagePackCodecDecoder) Decode(msg interface{}) error

Decode is a method on MessagePackCodecDecoder that decodes MessagePack data into the provided interface; returns an error if any decoding issues occur.

type MessagePackCodecEncoder added in v1.0.9

type MessagePackCodecEncoder struct {
	MessagePackCodec // Embedded MessagePackCodec
}

MessagePackCodecEncoder struct derives from MessagePackCodec it manages IDs and counts of the encoded objects.

func NewMessagePackEncoder added in v1.0.9

func NewMessagePackEncoder() *MessagePackCodecEncoder

NewMessagePackEncoder function creates new MessagePackCodecEncoder and initializes it.

func (*MessagePackCodecEncoder) Bytes added in v1.0.9

func (m *MessagePackCodecEncoder) Bytes() []byte

Bytes is a method for MessagePackCodecEncoder. It returns a byte slice pointer b.

func (*MessagePackCodecEncoder) Encode added in v1.0.9

func (m *MessagePackCodecEncoder) Encode(msg interface{}) error

Encode is a method for MessagePackCodecEncoder. It takes in msg of type interface{} as input, that is to be encoded. Returns an error if encountered during encoding.

Jump to

Keyboard shortcuts

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