You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

68 lines
2.5 KiB

  1. # MessagePack encoding for Golang
  2. [![Build Status](https://travis-ci.org/vmihailenco/msgpack.svg?branch=v2)](https://travis-ci.org/vmihailenco/msgpack)
  3. [![GoDoc](https://godoc.org/github.com/vmihailenco/msgpack?status.svg)](https://godoc.org/github.com/vmihailenco/msgpack)
  4. Supports:
  5. - Primitives, arrays, maps, structs, time.Time and interface{}.
  6. - Appengine *datastore.Key and datastore.Cursor.
  7. - [CustomEncoder](https://godoc.org/github.com/vmihailenco/msgpack#example-CustomEncoder)/CustomDecoder interfaces for custom encoding.
  8. - [Extensions](https://godoc.org/github.com/vmihailenco/msgpack#example-RegisterExt) to encode type information.
  9. - Renaming fields via `msgpack:"my_field_name"`.
  10. - Omitting individual empty fields via `msgpack:",omitempty"` tag or all [empty fields in a struct](https://godoc.org/github.com/vmihailenco/msgpack#example-Marshal--OmitEmpty).
  11. - [Map keys sorting](https://godoc.org/github.com/vmihailenco/msgpack#Encoder.SortMapKeys).
  12. - Encoding/decoding all [structs as arrays](https://godoc.org/github.com/vmihailenco/msgpack#Encoder.StructAsArray) or [individual structs](https://godoc.org/github.com/vmihailenco/msgpack#example-Marshal--AsArray).
  13. - Simple but very fast and efficient [queries](https://godoc.org/github.com/vmihailenco/msgpack#example-Decoder-Query).
  14. API docs: https://godoc.org/github.com/vmihailenco/msgpack.
  15. Examples: https://godoc.org/github.com/vmihailenco/msgpack#pkg-examples.
  16. ## Installation
  17. Install:
  18. ```shell
  19. go get -u github.com/vmihailenco/msgpack
  20. ```
  21. ## Quickstart
  22. ```go
  23. func ExampleMarshal() {
  24. type Item struct {
  25. Foo string
  26. }
  27. b, err := msgpack.Marshal(&Item{Foo: "bar"})
  28. if err != nil {
  29. panic(err)
  30. }
  31. var item Item
  32. err = msgpack.Unmarshal(b, &item)
  33. if err != nil {
  34. panic(err)
  35. }
  36. fmt.Println(item.Foo)
  37. // Output: bar
  38. }
  39. ```
  40. ## Benchmark
  41. ```
  42. BenchmarkStructVmihailencoMsgpack-4 200000 12814 ns/op 2128 B/op 26 allocs/op
  43. BenchmarkStructUgorjiGoMsgpack-4 100000 17678 ns/op 3616 B/op 70 allocs/op
  44. BenchmarkStructUgorjiGoCodec-4 100000 19053 ns/op 7346 B/op 23 allocs/op
  45. BenchmarkStructJSON-4 20000 69438 ns/op 7864 B/op 26 allocs/op
  46. BenchmarkStructGOB-4 10000 104331 ns/op 14664 B/op 278 allocs/op
  47. ```
  48. ## Howto
  49. Please go through [examples](https://godoc.org/github.com/vmihailenco/msgpack#pkg-examples) to get an idea how to use this package.
  50. ## See also
  51. - [Golang PostgreSQL ORM](https://github.com/go-pg/pg)
  52. - [Golang message task queue](https://github.com/go-msgqueue/msgqueue)