You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

30 lines
693 B
Go

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")
}