Skip to content

Commit

Permalink
added msgpack plugin decoder
Browse files Browse the repository at this point in the history
  • Loading branch information
bl17zar committed Dec 28, 2019
1 parent 91bec45 commit 931817a
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 0 deletions.
48 changes: 48 additions & 0 deletions examples/plugins/msgpack/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package main

import (
"encoding/json"
"github.com/vmihailenco/msgpack"
)

// Msgpack is an example of how to create a plugin
// to decode msgpack encoded kafka messages.
// To compile:
// go build -buildmode=plugin -o msgpack.so msgpack.go
// Then start kcli like:
// kcli -d ./msgpack.so
type Msgpack struct{}

// Decode is required in order to be a plugin
func (m Msgpack) Decode(topic string, b []byte) ([]byte, error) {

// accepts any topic
if topic == "" {
return b, nil
}

// schema free container
// for result
var out map[string]interface{}

// fill container with decoded values
err := msgpack.Unmarshal(b, &out)
if err != nil {
return nil, err
}

// represent result as json
// for beautiful output with kcli
repr, err := json.Marshal(out)
if err != nil {
return b, nil
}

return repr, nil
}

// Decoder is the symbol that kcli will search for when
// using this as a plugin.
var Decoder Msgpack

func main() {}
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ require (
github.com/pierrec/lz4 v1.0.2-0.20171218195038-2fcda4cb7018
github.com/pierrec/xxHash v0.1.1
github.com/rcrowley/go-metrics v0.0.0-20181016184325-3113b8401b8a
github.com/vmihailenco/msgpack v4.0.4+incompatible
golang.org/x/crypto v0.0.0-20190404164418-38d8ce5564a5
golang.org/x/net v0.0.0-20191007182048-72f939374954
golang.org/x/sys v0.0.0-20190403152447-81d4e9dc473e
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ github.com/rcrowley/go-metrics v0.0.0-20181016184325-3113b8401b8a/go.mod h1:bCqn
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/vmihailenco/msgpack v4.0.4+incompatible h1:dSLoQfGFAo3F6OoNhwUmLwVgaUXK79GlxNBwueZn0xI=
github.com/vmihailenco/msgpack v4.0.4+incompatible/go.mod h1:fy3FlTQTDXWkZ7Bh6AcGMlsjHatGryHQYUTf1ShIgkk=
github.com/xdg/scram v0.0.0-20180814205039-7eeb5667e42c/go.mod h1:lB8K/P019DLNhemzwFU4jHLhdvlE6uDZjXFejJXr49I=
github.com/xdg/stringprep v1.0.0/go.mod h1:Jhud4/sHMO4oL310DaZAKk9ZaJ08SJfe+sJh0HrGL1Y=
golang.org/x/crypto v0.0.0-20180119165957-a66000089151/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
Expand Down

0 comments on commit 931817a

Please sign in to comment.