msgpack

package module
v1.2.1 Latest Latest
Warning

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

Go to latest
Published: Feb 9, 2021 License: MIT Imports: 5 Imported by: 35

README

MessagePack for Golang

Go Reference Build Status Coverage Status Go Report Card FOSSA Status

Features

  • Supported types : primitive / array / slice / struct / map / interface{} and time.Time
  • Renaming fields via msgpack:"field_name"
  • Omitting fields via msgpack:"-" or 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.Marshal(v)
	if err != nil {
		panic(err)
	}
	r := Struct{}
	err = msgpack.Unmarshal(d, &r)
	if err != nil {
		panic(err)
	}
}

Benchmark

This result made from shamaton/msgpack_bench

Encode
BenchmarkCompareEncodeShamaton-4                  843001              1271 ns/op             320 B/op          3 allocs/op
BenchmarkCompareEncodeShamatonArray-4            1000000              1128 ns/op             256 B/op          3 allocs/op
BenchmarkCompareEncodeVmihailenco-4               308065              3562 ns/op            1000 B/op         15 allocs/op
BenchmarkCompareEncodeVmihailencoArray-4          327612              3577 ns/op            1000 B/op         15 allocs/op
BenchmarkCompareEncodeUgorji-4                    690046              1708 ns/op             904 B/op          9 allocs/op
BenchmarkCompareEncodeJson-4                      452257              2800 ns/op             824 B/op         14 allocs/op
BenchmarkCompareEncodeGob-4                       135574              8493 ns/op            2760 B/op         50 allocs/op
Decode
BenchmarkCompareDecodeShamaton-4                  826440              1419 ns/op             512 B/op          6 allocs/op
BenchmarkCompareDecodeShamatonArray-4            1246941              1126 ns/op             512 B/op          6 allocs/op
BenchmarkCompareDecodeVmihailenco-4               234380              4914 ns/op            1055 B/op         33 allocs/op
BenchmarkCompareDecodeVmihailencoArray-4          291438              4148 ns/op             992 B/op         22 allocs/op
BenchmarkCompareDecodeUgorji-4                    497340              2302 ns/op             890 B/op         10 allocs/op
BenchmarkCompareDecodeJson-4                      152253              7632 ns/op            1144 B/op         33 allocs/op
BenchmarkCompareDecodeGob-4                        36434             34308 ns/op           10108 B/op        275 allocs/op

License

This library is under the MIT License.

FOSSA Status

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 deprecated

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

Deprecated: Use Unmarshal, this method will be deleted.

func DecodeStructAsArray deprecated

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

Deprecated: Use UnmarshalAsArray, this method will be deleted.

func DecodeStructAsMap deprecated

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

Deprecated: Use UnmarshalAsMap, this method will be deleted.

func Encode deprecated

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

Deprecated: Use Marshal, this method will be deleted.

func EncodeStructAsArray deprecated

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

Deprecated: Use MarshalAsArray, this method will be deleted.

func EncodeStructAsMap deprecated

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

Deprecated: Use MarshalAsMap, this method will be deleted.

func Marshal added in v1.2.0

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

Marshal returns the MessagePack-encoded byte array of v.

func MarshalAsArray added in v1.2.0

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

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

func MarshalAsMap added in v1.2.0

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

MarshalAsMap 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.

func SetComplexTypeCode added in v1.2.0

func SetComplexTypeCode(code int8)

SetComplexTypeCode sets def.complexTypeCode

func Unmarshal added in v1.2.0

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

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

func UnmarshalAsArray added in v1.2.0

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

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

func UnmarshalAsMap added in v1.2.0

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

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

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