msgpack

package module
v0.0.0-...-e98f180 Latest Latest
Warning

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

Go to latest
Published: Apr 26, 2015 License: MIT Imports: 6 Imported by: 3

README

msgpack

GoDoc

MsgPack Decoding and Encoding for people who don't ask much

go test -bench=. -run=X -cpuprofile cpu.out -memprofile mem.out
PASS
BenchmarkDecodeBool     30000000                38.2 ns/op
BenchmarkDecodeFixInt   30000000                53.7 ns/op
BenchmarkDecodeUInt     20000000                74.7 ns/op
BenchmarkDecodeUInt16   20000000                80.0 ns/op
BenchmarkDecodeUInt32   20000000                70.5 ns/op
BenchmarkDecodeUInt64   20000000                85.6 ns/op
BenchmarkDecodeInt      30000000                56.0 ns/op
BenchmarkDecodeInt16    20000000                71.4 ns/op
BenchmarkDecodeInt32    20000000                70.1 ns/op
BenchmarkDecodeInt64    20000000                75.6 ns/op
BenchmarkDecodeFixStr   10000000               174 ns/op
BenchmarkDecodeStr8      2000000               658 ns/op
BenchmarkDecodeStr16           0                 0 ns/op
BenchmarkDecodeStr32           0                 0 ns/op
BenchmarkDecodeFixArray  1000000              1624 ns/op
BenchmarkDecodeArray16    200000             11262 ns/op
BenchmarkDecodeFixMap     200000              6486 ns/op
BenchmarkDecodeMap16           0                 0 ns/op

BenchmarkEncodeBool     10000000               191 ns/op
BenchmarkEncodeFixInt   10000000               224 ns/op
BenchmarkEncodeInt16    10000000               236 ns/op
BenchmarkEncodeInt32    10000000               233 ns/op
BenchmarkEncodeInt64    10000000               238 ns/op
BenchmarkEncodeUInt16   10000000               181 ns/op
BenchmarkEncodeUInt32   10000000               184 ns/op
BenchmarkEncodeUInt64   10000000               231 ns/op
BenchmarkEncodeStr8      5000000               324 ns/op
BenchmarkEncodeArrayString       5000000               268 ns/op
BenchmarkEncodeFixMap    2000000               791 ns/op
BenchmarkEncodeMap16      500000              3250 ns/op

Features

Type Decode Impl Decode Test Encode Impl Encode Test Issues
fixint X X X None
fixmap X X X None
fixarray X X X None
fixstr X X X None
nil X X X None
false X X X None
true X X X None
bin* None
ext* None
fixext* None
float* X X X negatives
int* X X X negatives
uint* X X X None
str* X X X None
array* X X X None
map* X X X None

WORK IN PROGRESS -- do not use this for anything requiring correctness

Documentation

Overview

This MsgPack encoding/decoding library was born out of a partial dissatisfaction with the current implementation of (and lack of documentation of) MsgPack encoders/decoders for Go. I also wanted some practice writing optimized Go code that attempted to avoid allocations and "got out of the way" of libraries using it.

This package is not finished yet, but it is close, and I've made an effort to do things in a standard way so that what is actually being done underneath the covers is easy to figure out. The focus of this package is not to provide the most fully featured MsgPack implementation out there, but rather support the main data types that I use in my work (most of the basic types, also []interface{} and map[string]interface{}). You'll notice that I don't use the `reflect` package at all, and that's because I wanted to see what code looked like when you just did a switch on types instead of using runtime reflection to figure out the types. This of course comes at the cost of not being able to extend this MsgPack implementation to arbitrary data types. Implementing a new type on your own is not difficult, though.

Coming up next are some more convenience methods for doing decoding and encoding through writer/reader/buffer interfaces

Index

Constants

View Source
const DEFAULT_ARR_SIZE = 15

Variables

This section is empty.

Functions

func Decode

func Decode(input *[]byte, offset int) (int, interface{})

func Encode

func Encode(input interface{}, ret *[]byte) int

Encodes the input as a msgpack byte array, which is provided by the user. This allows the user to control how many allocations are done. Returns the length of the encoded message, but does not adjust the length of the input array.

Types

This section is empty.

Jump to

Keyboard shortcuts

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