package kafka import ( "errors" "git.noahlan.cn/northlan/ntools-go/kafka" "google.golang.org/protobuf/proto" ) var _ kafka.Marshaler = (*protobufMarshaler)(nil) var _ kafka.UnMarshaler = (*protobufMarshaler)(nil) var ProtobufMarshaler = &protobufMarshaler{} type protobufMarshaler struct { } func (p *protobufMarshaler) Marshal(v interface{}) ([]byte, error) { if msg, ok := v.(proto.Message); ok { return proto.Marshal(msg) } return nil, errors.New("v must be proto message") } func (p *protobufMarshaler) UnMarshal(data []byte, v interface{}) error { if msg, ok := v.(proto.Message); ok { return proto.Unmarshal(data, msg) } return errors.New("v must be proto message") }