Documentation
¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Decoder ¶
Decoder decodes msgpack bytes into T (tinylib). T must have msgp code generation (go:generate msgp) so that *T implements msgp.Unmarshaler.
func Encoder ¶
Encoder encodes T to msgpack bytes (tinylib). T must have msgp code generation (go:generate msgp) so that *T implements msgp.Marshaler.
func NewCodec ¶
NewCodec returns a msgpack codec for T backed by tinylib/msgp. T must have msgp code generation (go:generate msgp) so that *T implements msgp.Marshaler and msgp.Unmarshaler. It is safe for concurrent use.
Example ¶
package main
import (
"fmt"
msgpack "github.com/foomo/goencode/msgpack/tinylib"
"github.com/foomo/goencode/msgpack/tinylib/testdata"
)
func main() {
c := msgpack.NewCodec[testdata.User]()
encoded, err := c.Encode(*testdata.NewUserTinyLib())
if err != nil {
fmt.Printf("Encode failed: %v\n", err)
return
}
var decoded testdata.User
if err := c.Decode(encoded, &decoded); err != nil {
fmt.Printf("Decode failed: %v\n", err)
return
}
fmt.Printf("Decoded Handle: %s\n", decoded.Handle)
fmt.Printf("Decoded Country: %s\n", decoded.Country)
}
Output: Decoded Handle: @bench Decoded Country: US
func NewStreamCodec ¶
func NewStreamCodec[T any]() encoding.StreamCodec[T]
NewStreamCodec returns a msgpack stream codec for T backed by tinylib/msgp. T must have msgp code generation (go:generate msgp) so that *T implements msgp.Encodable and msgp.Decodable. It is safe for concurrent use.
Example ¶
package main
import (
"bytes"
"fmt"
msgpack "github.com/foomo/goencode/msgpack/tinylib"
"github.com/foomo/goencode/msgpack/tinylib/testdata"
)
func main() {
c := msgpack.NewStreamCodec[testdata.User]()
var buf bytes.Buffer
if err := c.Encode(&buf, *testdata.NewUserTinyLib()); err != nil {
fmt.Printf("Encode failed: %v\n", err)
return
}
var decoded testdata.User
if err := c.Decode(&buf, &decoded); err != nil {
fmt.Printf("Decode failed: %v\n", err)
return
}
fmt.Printf("Decoded Handle: %s\n", decoded.Handle)
fmt.Printf("Decoded Country: %s\n", decoded.Country)
}
Output: Decoded Handle: @bench Decoded Country: US
func StreamDecoder ¶
StreamDecoder decodes T from a msgpack stream (tinylib). T must have msgp code generation (go:generate msgp) so that *T implements msgp.Decodable.
Types ¶
This section is empty.