msgpack

package
v1.5.0 Latest Latest
Warning

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

Go to latest
Published: Oct 19, 2026 License: MIT Imports: 1 Imported by: 0

README

shamaton/msgpack v3 codec

wrapper/cache codec that encodes values as MessagePack with github.com/shamaton/msgpack/v3. The v2 codec (../v2) stays; both implement cache.Codec[T].

import (
	"github.com/xgodev/boost/wrapper/cache"
	msgpack "github.com/xgodev/boost/wrapper/cache/codec/contrib/shamaton/msgpack/v3"
)

manager := cache.NewManager[Order]("orders", msgpack.New[Order](), drv)

Moving from v2

  • Compatible on the wire. v3 reads the entries v2 wrote and v2 reads the entries v3 writes (strings, bytes, structs, slices, times), so a service can switch codecs without flushing its cache, and instances on v2 and v3 can share one cache during a rollout (codec_test.go: TestCodec_ReadsV2, TestCodec_V2Reads, TestCodec_Time_DecodesAsUTC).
  • time.Time decodes in UTC. v2 decoded a timestamp into time.Local; v3 decodes it into time.UTC. The instant is the same (Equal holds), only Location() differs, so code that formats the time or compares with == sees a change. msgpack.SetDecodedTimeAsLocal() from github.com/shamaton/msgpack/v3 restores the v2 behaviour process-wide.

Documentation

Overview

Package msgpack is a wrapper/cache codec on github.com/shamaton/msgpack/v3.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Codec

type Codec[T any] struct {
}

Codec encodes cache values as MessagePack with shamaton/msgpack v3.

func New

func New[T any]() *Codec[T]

New returns a shamaton/msgpack v3 codec for T.

func (*Codec[T]) Decode

func (c *Codec[T]) Decode(b []byte, data *T) (err error)

Decode deserializes MessagePack bytes into data. A timestamp decodes into a time.Time in UTC (v2 decoded into Local); the instant is the same.

func (*Codec[T]) Encode

func (c *Codec[T]) Encode(data T) (b []byte, err error)

Encode serializes data as MessagePack.

Jump to

Keyboard shortcuts

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