Skip to content

Commit

Permalink
Decoder takes topic as an arg.
Browse files Browse the repository at this point in the history
  • Loading branch information
cswank committed Jan 22, 2019
1 parent 977ecfe commit 2aef792
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion examples/plugin/protobuf.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
// kcli -d ./protobuf.so
type Protobuf struct{}

func (p Protobuf) Decode(b []byte) ([]byte, error) {
func (p Protobuf) Decode(topic string, b []byte) ([]byte, error) {
var x person.Person
err := proto.Unmarshal(b, &x)
if err != nil {
Expand Down
6 changes: 3 additions & 3 deletions internal/kafka/kafka.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ import (
)

type Decoder interface {
Decode([]byte) ([]byte, error)
Decode(topic string, data []byte) ([]byte, error)
}

// plainDecoder is the default Decoder
type plainDecoder struct{}

func (p plainDecoder) Decode(b []byte) ([]byte, error) { return b, nil }
func (p plainDecoder) Decode(topic string, data []byte) ([]byte, error) { return data, nil }

//Client fetches from kafka
type Client struct {
Expand Down Expand Up @@ -187,7 +187,7 @@ func (c *Client) GetPartition(part Partition, end int, f func([]byte) bool) ([]M
select {
case msg = <-pc.Messages():
if f(msg.Value) {
val, err := c.decoder.Decode(msg.Value)
val, err := c.decoder.Decode(part.Topic, msg.Value)
if err != nil {
return nil, err
}
Expand Down

0 comments on commit 2aef792

Please sign in to comment.