Skip to content

Commit

Permalink
Upgrading msgpack to v5 (#127)
Browse files Browse the repository at this point in the history
  • Loading branch information
Paul Osman authored Jul 21, 2021
1 parent 08b3259 commit 2506893
Show file tree
Hide file tree
Showing 9 changed files with 35 additions and 53 deletions.
4 changes: 1 addition & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,8 @@ require (
github.com/facebookgo/muster v0.0.0-20150708232844-fd3d7953fd52
github.com/facebookgo/stack v0.0.0-20160209184415-751773369052 // indirect
github.com/facebookgo/subset v0.0.0-20200203212716-c811ad88dec4 // indirect
github.com/golang/protobuf v1.3.5 // indirect
github.com/klauspost/compress v1.12.3
github.com/stretchr/testify v1.6.1
github.com/vmihailenco/msgpack/v4 v4.3.12
golang.org/x/net v0.0.0-20200324143707-d3edc9973b7e // indirect
github.com/vmihailenco/msgpack/v5 v5.2.0
gopkg.in/alexcesaro/statsd.v2 v2.0.0
)
35 changes: 6 additions & 29 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
github.com/DataDog/zstd v1.4.8 h1:Rpmta4xZ/MgZnriKNd24iZMhGpP5dvUcs/uqfBapKZY=
github.com/DataDog/zstd v1.4.8/go.mod h1:g4AWEaM3yOg3HYfnJ3YIawPnVdXJh9QME85blwSAmyw=
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/facebookgo/clock v0.0.0-20150410010913-600d898af40a h1:yDWHCSQ40h88yih2JAcL6Ls/kVkSE8GFACTGVnMPruw=
github.com/facebookgo/clock v0.0.0-20150410010913-600d898af40a/go.mod h1:7Ga40egUymuWXxAe151lTNnCv97MddSOVsjpPPkityA=
github.com/facebookgo/ensure v0.0.0-20200202191622-63f1cf65ac4c h1:8ISkoahWXwZR41ois5lSJBSVw4D0OV19Ht/JSTzvSv0=
Expand All @@ -15,44 +14,22 @@ github.com/facebookgo/stack v0.0.0-20160209184415-751773369052 h1:JWuenKqqX8nojt
github.com/facebookgo/stack v0.0.0-20160209184415-751773369052/go.mod h1:UbMTZqLaRiH3MsBH8va0n7s1pQYcu3uTb8G4tygF4Zg=
github.com/facebookgo/subset v0.0.0-20200203212716-c811ad88dec4 h1:7HZCaLC5+BZpmbhCOZJ293Lz68O7PYrF2EzeiFMwCLk=
github.com/facebookgo/subset v0.0.0-20200203212716-c811ad88dec4/go.mod h1:5tD+neXqOorC30/tWg0LCSkrqj/AR6gu8yY8/fpw1q0=
github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/golang/protobuf v1.3.4/go.mod h1:vzj43D7+SQXF/4pzW/hwtAqwc6iTitCiVSaWz5lYuqw=
github.com/golang/protobuf v1.3.5 h1:F768QJ1E9tib+q5Sc8MkdJi1RxLTbRcTf8LJV56aRls=
github.com/golang/protobuf v1.3.5/go.mod h1:6O5/vntMXwX2lRkT1hjjk0nAC1IDOTvTlVgjlRvqsdk=
github.com/golang/snappy v0.0.3 h1:fHPg5GQYlCeLIPB9BZqMVR5nR9A+IM5zcgeTdjMYmLA=
github.com/golang/snappy v0.0.3/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
github.com/klauspost/compress v1.12.3 h1:G5AfA94pHPysR56qqrkO2pxEexdDzrpFJ6yt/VqWxVU=
github.com/klauspost/compress v1.12.3/go.mod h1:8dP1Hq4DHOhN9w426knH3Rhby4rFm6D8eO+e+Dq5Gzg=
github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.6.1 h1:hDPOHmpOpP40lSULcqw7IrRb/u7w6RpDC9399XyoNd0=
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/vmihailenco/msgpack/v4 v4.3.12 h1:07s4sz9IReOgdikxLTKNbBdqDMLsjPKXwvCazn8G65U=
github.com/vmihailenco/msgpack/v4 v4.3.12/go.mod h1:gborTTJjAo/GWTqqRjrLCn9pgNN+NXzzngzBKDPIqw4=
github.com/vmihailenco/tagparser v0.1.1 h1:quXMXlA39OCbd2wAdTsGDlK9RkOk6Wuw+x37wVyIuWY=
github.com/vmihailenco/tagparser v0.1.1/go.mod h1:OeAg3pn3UbLjkWt+rN9oFYB6u/cQgqMEUPoW2WPyhdI=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/net v0.0.0-20190603091049-60506f45cf65/go.mod h1:HSz+uSET+XFnRR8LxR5pz3Of3rY3CfYBVs4xY44aLks=
golang.org/x/net v0.0.0-20200301022130-244492dfa37a/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20200324143707-d3edc9973b7e h1:3G+cUijn7XD+S4eJFddp53Pv7+slrESplyjG25HgL+k=
golang.org/x/net v0.0.0-20200324143707-d3edc9973b7e/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
google.golang.org/appengine v1.6.5 h1:tycE03LOZYQNhDpS27tcQdAzLCVMaj7QT2SXxebnpCM=
google.golang.org/appengine v1.6.5/go.mod h1:8WjMMxjGQR8xUklV/ARdw2HLXBOI7O7uCIDZVag1xfc=
github.com/vmihailenco/msgpack/v5 v5.2.0 h1:ZhIAtVUP1mme8GIlpiAnmTzjSWMexA/uNF2We85DR0w=
github.com/vmihailenco/msgpack/v5 v5.2.0/go.mod h1:fEM7KuHcnm0GvDCztRpw9hV0PuoO2ciTismP6vjggcM=
github.com/vmihailenco/tagparser/v2 v2.0.0 h1:y09buUbR+b5aycVFQs/g70pqKVZNBmxwAhO7/IwNM9g=
github.com/vmihailenco/tagparser/v2 v2.0.0/go.mod h1:Wri+At7QHww0WTrCBeu4J6bNtoV6mEfg5OIWRZA9qds=
gopkg.in/alexcesaro/statsd.v2 v2.0.0 h1:FXkZSCZIH17vLCO5sO2UucTHsH9pc+17F6pl3JVCwMc=
gopkg.in/alexcesaro/statsd.v2 v2.0.0/go.mod h1:i0ubccKGzBVNBpdGV5MocxyA/XlLUJzA7SLonnE4drU=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
8 changes: 8 additions & 0 deletions libhoney_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -277,14 +277,22 @@ func TestAddMap(t *testing.T) {
"d": []string{"d_a", "d_b"},
"e": r,
}
mInts := map[int64]interface{}{
1: "foo",
2: "bar",
}
ev := NewEvent()
err := ev.Add(mStr)
testOK(t, err)
err = ev.Add(mInts)
testOK(t, err)
testEquals(t, ev.data["a"], mStr["a"].(string))
testEquals(t, ev.data["b"], int(mStr["b"].(int)))
testEquals(t, ev.data["c"], float64(mStr["c"].(float64)))
testEquals(t, ev.data["d"], mStr["d"])
testEquals(t, ev.data["e"], r)
testEquals(t, ev.data["1"], "foo")
testEquals(t, ev.data["2"], "bar")

mInt := map[uint8]interface{}{
1: "valA",
Expand Down
6 changes: 4 additions & 2 deletions transmission/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"sort"
"time"

"github.com/vmihailenco/msgpack/v4"
"github.com/vmihailenco/msgpack/v5"
)

type Event struct {
Expand Down Expand Up @@ -74,7 +74,9 @@ func (e *Event) MarshalMsgpack() (byts []byte, err error) {
}()

var buf bytes.Buffer
err = msgpack.NewEncoder(&buf).UseJSONTag(true).Encode(struct {
encoder := msgpack.NewEncoder(&buf)
encoder.SetCustomStructTag("json")
err = encoder.Encode(struct {
Data map[string]interface{} `msgpack:"data"`
SampleRate uint `msgpack:"samplerate,omitempty"`
Timestamp *time.Time `msgpack:"time,omitempty"`
Expand Down
19 changes: 7 additions & 12 deletions transmission/event_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"testing"
"time"

"github.com/vmihailenco/msgpack/v4"
"github.com/vmihailenco/msgpack/v5"
)

func TestEventMarshal(t *testing.T) {
Expand All @@ -23,19 +23,16 @@ func TestEventMarshal(t *testing.T) {
"g": map[string]interface{}{
"g": 1,
},
"h": map[int]int{
1: 1,
},
}
b, err := json.Marshal(e)
testOK(t, err)
testEquals(t, string(b), `{"data":{"a":1,"b":1,"c":true,"d":"foo","e":1000,"f":{"f":1},"g":{"g":1},"h":{"1":1}}}`)
testEquals(t, string(b), `{"data":{"a":1,"b":1,"c":true,"d":"foo","e":1000,"f":{"f":1},"g":{"g":1}}}`)

e.Timestamp = time.Unix(1476309645, 0).UTC()
e.SampleRate = 5
b, err = json.Marshal(e)
testOK(t, err)
testEquals(t, string(b), `{"data":{"a":1,"b":1,"c":true,"d":"foo","e":1000,"f":{"f":1},"g":{"g":1},"h":{"1":1}},"samplerate":5,"time":"2016-10-12T22:00:45Z"}`)
testEquals(t, string(b), `{"data":{"a":1,"b":1,"c":true,"d":"foo","e":1000,"f":{"f":1},"g":{"g":1}},"samplerate":5,"time":"2016-10-12T22:00:45Z"}`)

var buf bytes.Buffer
err = msgpack.NewEncoder(&buf).Encode(e)
Expand All @@ -45,9 +42,10 @@ func TestEventMarshal(t *testing.T) {
err = msgpack.NewDecoder(&buf).Decode(&decoded)
testOK(t, err)
localTime := e.Timestamp.Local()

testEquals(t, decoded, map[string]interface{}{
"time": &localTime,
"samplerate": uint64(5),
"time": localTime,
"samplerate": int8(5),
"data": map[string]interface{}{
"a": int64(1),
"b": float64(1.0),
Expand All @@ -58,10 +56,7 @@ func TestEventMarshal(t *testing.T) {
"f": int64(1),
},
"g": map[string]interface{}{
"g": int64(1),
},
"h": map[int64]int64{
1: 1,
"g": int8(1),
},
},
})
Expand Down
2 changes: 1 addition & 1 deletion transmission/response.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"errors"
"time"

"github.com/vmihailenco/msgpack/v4"
"github.com/vmihailenco/msgpack/v5"
)

// Response is a record of an event sent. It includes information about sending
Expand Down
6 changes: 3 additions & 3 deletions transmission/response_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"encoding/json"
"testing"

"github.com/vmihailenco/msgpack"
"github.com/vmihailenco/msgpack/v5"
)

// response struct sent from API
Expand Down Expand Up @@ -59,7 +59,7 @@ func TestUnmarshalJSONResponseSingle(t *testing.T) {
func TestUnmarshalMsgpackResponse(t *testing.T) {
buf := &bytes.Buffer{}
encoder := msgpack.NewEncoder(buf)
encoder.UseJSONTag(true)
encoder.SetCustomStructTag("json")
err := encoder.Encode(srcBatchResponseMultiple)
testOK(t, err)

Expand All @@ -76,7 +76,7 @@ func TestUnmarshalMsgpackResponse(t *testing.T) {
func TestUnmarshalMsgpackResponseSingle(t *testing.T) {
buf := &bytes.Buffer{}
encoder := msgpack.NewEncoder(buf)
encoder.UseJSONTag(true)
encoder.SetCustomStructTag("json")
err := encoder.Encode(srcBatchResponseSingle)
testOK(t, err)

Expand Down
2 changes: 1 addition & 1 deletion transmission/transmission.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import (

"github.com/facebookgo/muster"
"github.com/klauspost/compress/zstd"
"github.com/vmihailenco/msgpack/v4"
"github.com/vmihailenco/msgpack/v5"
)

const (
Expand Down
6 changes: 4 additions & 2 deletions transmission/transmission_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
// convincing testing.
"github.com/DataDog/zstd"
"github.com/facebookgo/muster"
"github.com/vmihailenco/msgpack/v4"
"github.com/vmihailenco/msgpack/v5"
)

var (
Expand Down Expand Up @@ -232,7 +232,9 @@ func TestTxSendSingle(t *testing.T) {
},
}}
var buf bytes.Buffer
err := msgpack.NewEncoder(&buf).UseJSONTag(true).Encode(&v)
encoder := msgpack.NewEncoder(&buf)
encoder.SetCustomStructTag("json")
err := encoder.Encode(&v)
testOK(t, err)
_, err = g.Write(buf.Bytes())
testOK(t, err)
Expand Down

0 comments on commit 2506893

Please sign in to comment.