Created
October 9, 2021 09:50
-
-
Save AlmogBaku/4a9ad3c66247f404e26378e31e049992 to your computer and use it in GitHub Desktop.
Sarama protobuf encoder
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
package protoencoder | |
import ( | |
"github.com/Shopify/sarama" | |
"google.golang.org/protobuf/proto" | |
) | |
type encoder struct { | |
msg proto.Message | |
} | |
func (e *encoder) Encode() ([]byte, error) { | |
return proto.Marshal(e.msg) | |
} | |
func (e *encoder) Length() int { | |
return proto.Size(e.msg) | |
} | |
// ProtoEncoder encodes ProtocolBuffer messages natively on Sarama | |
// Utilizing this encoder will only encode the message during the producing time | |
func ProtoEncoder(msg proto.Message) sarama.Encoder { | |
return &encoder{msg: msg} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment