msgpack

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

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

Go to latest
Published: Apr 21, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Decoder

func Decoder[T any](b []byte, v *T) error

Decoder decodes msgpack bytes into T (vmihailenco).

func Encoder

func Encoder[T any](v T) ([]byte, error)

Encoder encodes T to msgpack bytes (vmihailenco).

func NewCodec

func NewCodec[T any]() encoding.Codec[T, []byte]

NewCodec returns a msgpack codec for T backed by vmihailenco/msgpack/v5. It is safe for concurrent use.

Example
package main

import (
	"fmt"

	msgpack "github.com/foomo/goencode/msgpack/vmihailenco"
)

func main() {
	type Data struct {
		Name string `msgpack:"name"`
	}

	c := msgpack.NewCodec[Data]()

	encoded, err := c.Encode(Data{Name: "example-123"})
	if err != nil {
		fmt.Printf("Encode failed: %v\n", err)
		return
	}

	var decoded Data
	if err := c.Decode(encoded, &decoded); err != nil {
		fmt.Printf("Decode failed: %v\n", err)
		return
	}

	fmt.Printf("Decoded Name: %s\n", decoded.Name)
}
Output:
Decoded Name: example-123

func NewStreamCodec

func NewStreamCodec[T any]() encoding.StreamCodec[T]

NewStreamCodec returns a msgpack stream codec for T backed by vmihailenco/msgpack/v5. It is safe for concurrent use.

Example
package main

import (
	"bytes"
	"fmt"

	msgpack "github.com/foomo/goencode/msgpack/vmihailenco"
)

func main() {
	type Data struct {
		Name string `msgpack:"name"`
	}

	c := msgpack.NewStreamCodec[Data]()

	var buf bytes.Buffer
	if err := c.Encode(&buf, Data{Name: "example-123"}); err != nil {
		fmt.Printf("Encode failed: %v\n", err)
		return
	}

	var decoded Data
	if err := c.Decode(&buf, &decoded); err != nil {
		fmt.Printf("Decode failed: %v\n", err)
		return
	}

	fmt.Printf("Decoded Name: %s\n", decoded.Name)
}
Output:
Decoded Name: example-123

func StreamDecoder

func StreamDecoder[T any](r io.Reader, v *T) error

StreamDecoder decodes T from a msgpack stream (vmihailenco).

func StreamEncoder

func StreamEncoder[T any](w io.Writer, v T) error

StreamEncoder encodes T to a msgpack stream (vmihailenco).

Types

This section is empty.

Jump to

Keyboard shortcuts

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