Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

get rid of github.com/gogo/protobuf #526

Merged
merged 7 commits into from
Jan 16, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 14 additions & 9 deletions components/cqrs/marshaler_protobuf.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ import (

"github.com/ThreeDotsLabs/watermill"
"github.com/ThreeDotsLabs/watermill/message"
"google.golang.org/protobuf/proto"

"github.com/gogo/protobuf/proto"
"github.com/pkg/errors"
)

// ProtobufMarshaler is the default Protocol Buffers marshaler.
type ProtobufMarshaler struct {
// ProtoMarshaler is the default Protocol Buffers marshaler.
type ProtoMarshaler struct {
NewUUID func() string
GenerateName func(v interface{}) string
}
Expand All @@ -31,7 +31,7 @@ func (e NoProtoMessageError) Error() string {
}

// Marshal marshals the given protobuf's message into watermill's Message.
func (m ProtobufMarshaler) Marshal(v interface{}) (*message.Message, error) {
func (m ProtoMarshaler) Marshal(v interface{}) (*message.Message, error) {
protoMsg, ok := v.(proto.Message)
if !ok {
return nil, errors.WithStack(NoProtoMessageError{v})
Expand All @@ -51,7 +51,7 @@ func (m ProtobufMarshaler) Marshal(v interface{}) (*message.Message, error) {
return msg, nil
}

func (m ProtobufMarshaler) newUUID() string {
func (m ProtoMarshaler) newUUID() string {
if m.NewUUID != nil {
return m.NewUUID()
}
Expand All @@ -61,12 +61,17 @@ func (m ProtobufMarshaler) newUUID() string {
}

// Unmarshal unmarshals given watermill's Message into protobuf's message.
func (ProtobufMarshaler) Unmarshal(msg *message.Message, v interface{}) (err error) {
return proto.Unmarshal(msg.Payload, v.(proto.Message))
func (ProtoMarshaler) Unmarshal(msg *message.Message, v interface{}) (err error) {
protoV, ok := v.(proto.Message)
if !ok {
return errors.WithStack(NoProtoMessageError{v})
}

return proto.Unmarshal(msg.Payload, protoV)
}

// Name returns the command or event's name.
func (m ProtobufMarshaler) Name(cmdOrEvent interface{}) string {
func (m ProtoMarshaler) Name(cmdOrEvent interface{}) string {
if m.GenerateName != nil {
return m.GenerateName(cmdOrEvent)
}
Expand All @@ -75,6 +80,6 @@ func (m ProtobufMarshaler) Name(cmdOrEvent interface{}) string {
}

// NameFromMessage returns the metadata name value for a given Message.
func (m ProtobufMarshaler) NameFromMessage(msg *message.Message) string {
func (m ProtoMarshaler) NameFromMessage(msg *message.Message) string {
return msg.Metadata.Get("name")
}
Loading
Loading