-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathmain.go
More file actions
35 lines (28 loc) · 749 Bytes
/
main.go
File metadata and controls
35 lines (28 loc) · 749 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
package main
import (
"github.com/cswank/kcli/dev/person"
"github.com/golang/protobuf/proto"
)
// Protobuf is an example of how to create a plugin
// to decode protobuf encoded kafka messages.
// To compile:
// go build -buildmode=plugin -o protobuf.so main.go
// Then start kcli like:
// kcli -d ./protobuf.so
type Protobuf struct{}
// Decode is required in order to be a plugin
func (p Protobuf) Decode(topic string, b []byte) ([]byte, error) {
if topic != "proto" {
return b, nil
}
var x person.Person
err := proto.Unmarshal(b, &x)
if err != nil {
return nil, err
}
return []byte(x.String()), nil
}
// Decoder is the symbol that kcli will search for when
// using this as a plugin.
var Decoder Protobuf
func main() {}