Categorygithub.com/shamaton/msgpack/v2
modulepackage
2.2.2
Repository: https://github.com/shamaton/msgpack.git
Documentation: pkg.go.dev

# README

MessagePack for Golang

Go Reference test Go Report Card codecov FOSSA Status

📣 Notice

If your application serializes only primitive types, array, map and struct, code generation is also recommended. You can get the fastest performance with msgpackgen.

Features

  • Supported types : primitive / array / slice / struct / map / interface{} and time.Time
  • Renaming fields via msgpack:"field_name"
  • Omitting fields via msgpack:"-"
  • Supports extend encoder / decoder
  • Can also Encoding / Decoding struct as array

Installation

Current version is msgpack/v2.

go get -u github.com/shamaton/msgpack/v2

Quick Start

package main

import (
  "github.com/shamaton/msgpack/v2"
  "net/http"
)

type Struct struct {
	String string
}

// simple
func main() {
	v := Struct{String: "msgpack"}

	d, err := msgpack.Marshal(v)
	if err != nil {
		panic(err)
	}
	r := Struct{}
	if err =  msgpack.Unmarshal(d, &r); err != nil {
		panic(err)
	}
}

// streaming
func handle(w http.ResponseWriter, r *http.Request) {
	var body Struct
	if err := msgpack.UnmarshalRead(r, &body); err != nil {
		panic(err)
    }
	if err := msgpack.MarshalWrite(w, body); err != nil {
		panic(err)
    }
}

Benchmark

This result made from shamaton/msgpack_bench

msgpack_bench

License

This library is under the MIT License.

# Packages

No description provided by the author
No description provided by the author
No description provided by the author

# Functions

AddExtCoder adds encoders for extension types.
AddExtStreamCoder adds stream encoders for extension types.
Marshal returns the MessagePack-encoded byte array of v.
MarshalAsArray encodes data as array format.
MarshalAsMap encodes data as map format.
MarshalWrite writes MessagePack-encoded byte array of v to writer.
MarshalWriteAsArray writes array format encoded data to writer.
MarshalWriteAsMap writes map format encoded data to writer.
RemoveExtCoder removes encoders for extension types.
RemoveExtStreamCoder removes stream encoders for extension types.
SetComplexTypeCode sets def.complexTypeCode.
Unmarshal analyzes the MessagePack-encoded data and stores the result into the pointer of v.
UnmarshalAsArray decodes data that is encoded as array format.
UnmarshalAsMap decodes data that is encoded as map format.
UnmarshalRead reads the MessagePack-encoded data from reader and stores the result into the pointer of v.
UnmarshalReadAsArray decodes from stream.
UnmarshalReadAsMap decodes from stream.

# Variables

Error is used in all msgpack error as the based error.
StructAsArray is encoding option.