msgpack

package module
v1.1.1 Latest Latest
Warning

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

Go to latest
Published: Jul 12, 2019 License: MIT Imports: 4 Imported by: 0

README

MessagePack for Golang

GoDoc Build Status Coverage Status Releases

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

This package require more than golang version 1.9

Installation

go get -u github.com/shamaton/msgpack

Quick Start

package main;

import (
  "github.com/shamaton/msgpack"
)

func main() {
	type Struct struct {
		String string
	}
	v := Struct{String: "msgpack"}

	d, err := msgpack.Encode(v)
	if err != nil {
		panic(err)
	}
	r := Struct{}
	err = msgpack.Decode(d, &r)
	if err != nil {
		panic(err)
	}
}

Benchmark

This result made from shamaton/msgpack_bench

Encode
BenchmarkCompareEncodeShamaton-4           	 1000000	      1341 ns/op	     320 B/op	       3 allocs/op
BenchmarkCompareEncodeShamatonArray-4      	 1000000	      1183 ns/op	     256 B/op	       3 allocs/op
BenchmarkCompareEncodeVmihailenco-4        	  200000	      5271 ns/op	     968 B/op	      14 allocs/op
BenchmarkCompareEncodeVmihailencoArray-4   	  300000	      5055 ns/op	     968 B/op	      14 allocs/op
BenchmarkCompareEncodeUgorji-4             	 1000000	      1772 ns/op	     872 B/op	      10 allocs/op
BenchmarkCompareEncodeZeroformatter-4      	 1000000	      1960 ns/op	     744 B/op	      13 allocs/op
BenchmarkCompareEncodeJson-4               	  300000	      3679 ns/op	    1224 B/op	      16 allocs/op
BenchmarkCompareEncodeGob-4                	  100000	     11988 ns/op	    2824 B/op	      50 allocs/op
Decode
BenchmarkCompareDecodeShamaton-4           	 1000000	      1501 ns/op	     512 B/op	       6 allocs/op
BenchmarkCompareDecodeShamatonArray-4      	 1000000	      1032 ns/op	     512 B/op	       6 allocs/op
BenchmarkCompareDecodeVmihailenco-4        	  200000	      5573 ns/op	    1056 B/op	      33 allocs/op
BenchmarkCompareDecodeVmihailencoArray-4   	  300000	      4438 ns/op	     992 B/op	      22 allocs/op
BenchmarkCompareDecodeUgorji-4             	  500000	      2615 ns/op	     858 B/op	      11 allocs/op
BenchmarkCompareDecodeJson-4               	  200000	      9241 ns/op	    1216 B/op	      43 allocs/op
BenchmarkCompareDecodeGob-4                	   50000	     37985 ns/op	   10172 B/op	     275 allocs/op

License

This library is under the MIT License.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var StructAsArray = false

StructAsArray is encoding option. If this option sets true, default encoding sets to array-format.

Functions

func AddExtCoder

func AddExtCoder(e ext.Encoder, d ext.Decoder) error

AddExtCoder adds encoders for extension types.

func Decode

func Decode(data []byte, v interface{}) error

Decode analyzes the MessagePack-encoded data and stores the result into the pointer of v.

func DecodeStructAsArray

func DecodeStructAsArray(data []byte, v interface{}) error

DecodeStructAsArray decodes data that is encoded as array format. This is the same thing that StructAsArray sets true.

func DecodeStructAsMap

func DecodeStructAsMap(data []byte, v interface{}) error

DecodeStructAsMap decodes data that is encoded as map format. This is the same thing that StructAsArray sets false.

func Encode

func Encode(v interface{}) ([]byte, error)

Encode returns the MessagePack-encoded byte array of v.

func EncodeStructAsArray

func EncodeStructAsArray(v interface{}) ([]byte, error)

EncodeStructAsArray encodes data as array format. This is the same thing that StructAsArray sets true.

func EncodeStructAsMap

func EncodeStructAsMap(v interface{}) ([]byte, error)

EncodeStructAsMap encodes data as map format. This is the same thing that StructAsArray sets false.

func RemoveExtCoder

func RemoveExtCoder(e ext.Encoder, d ext.Decoder) error

RemoveExtCoder removes encoders for extension types.

Types

This section is empty.

Directories

Path Synopsis
internal

Jump to

Keyboard shortcuts

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