msgpack

package module
v2.1.1 Latest Latest
Warning

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

Go to latest
Published: Oct 21, 2022 License: MIT Imports: 5 Imported by: 101

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

This package requires more than version 1.13

Installation

Current version is msgpack/v2.

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

Quick Start

package main

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

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

msgpack_bench

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 Marshal ¶

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

Marshal returns the MessagePack-encoded byte array of v.

func MarshalAsArray ¶

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

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

func MarshalAsMap ¶

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 ¶

func SetComplexTypeCode(code int8)

SetComplexTypeCode sets def.complexTypeCode

func Unmarshal ¶

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

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

func UnmarshalAsArray ¶

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 ¶

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