-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
bl17zar
committed
Dec 28, 2019
1 parent
91bec45
commit 931817a
Showing
3 changed files
with
51 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters