msgpack

package module
v0.0.0-...-a145f35 Latest Latest
Warning

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

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

Documentation

Overview

Package msgpack provides a MessagePack driver for go-shelve.

Example
product := Product{
	ID:       1,
	Name:     "Apple",
	Price:    1.0,
	Quantity: 1,
	Active:   true,
}

codec := NewDefault()
b, err := codec.Encode(&product)
if err != nil {
	log.Printf("encode msgpack: %s", err)
	return
}

err = codec.Decode(b, &product)
if err != nil {
	log.Printf("decode msgpack: %s", err)
	return
}

fmt.Println(product.Name, product.Price)
Output:

Apple 1

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Codec

type Codec struct{}

Codec is a shelve.Codec driver for msgpack.

func NewDefault

func NewDefault() *Codec

NewDefault creates a new Codec with default values.

func (*Codec) Decode

func (e *Codec) Decode(data []byte, value any) error

Decode parses the encoded msgpack data and stores the result in the value pointed to by v. It is the inverse of Encode.

func (*Codec) Encode

func (e *Codec) Encode(value any) ([]byte, error)

Encode returns the msgpack encoding of v as a byte slice.

Jump to

Keyboard shortcuts

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