msgpack

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Sep 28, 2018 License: MIT Imports: 4 Imported by: 36

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

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-8           	 1000000	      1319 ns/op	     320 B/op	       3 allocs/op
BenchmarkCompareEncodeShamatonArray-8      	 1000000	      1172 ns/op	     256 B/op	       3 allocs/op
BenchmarkCompareEncodeVmihailenco-8        	  300000	      4626 ns/op	    1000 B/op	      14 allocs/op
BenchmarkCompareEncodeVmihailencoArray-8   	  500000	      3918 ns/op	     680 B/op	      13 allocs/op
BenchmarkCompareEncodeUgorji-8             	 1000000	      1985 ns/op	     986 B/op	      11 allocs/op
BenchmarkCompareEncodeJson-8               	  500000	      3649 ns/op	    1224 B/op	      16 allocs/op
BenchmarkCompareEncodeGob-8                	  100000	     12324 ns/op	    2824 B/op	      50 allocs/op
Decode
BenchmarkCompareDecodeShamaton-8           	 1000000	      1494 ns/op	     512 B/op	       6 allocs/op
BenchmarkCompareDecodeShamatonArray-8      	 1000000	      1031 ns/op	     512 B/op	       6 allocs/op
BenchmarkCompareDecodeVmihailenco-8        	  200000	      5660 ns/op	    1056 B/op	      33 allocs/op
BenchmarkCompareDecodeVmihailencoArray-8   	  300000	      4779 ns/op	     992 B/op	      22 allocs/op
BenchmarkCompareDecodeUgorji-8             	  500000	      2774 ns/op	     844 B/op	      12 allocs/op
BenchmarkCompareDecodeJson-8               	  200000	      9721 ns/op	    1216 B/op	      43 allocs/op
BenchmarkCompareDecodeGob-8                	   50000	     37553 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