Skip to content

Commit

Permalink
Merge pull request #53 from muzzammilshahid/clean-encode-cbor
Browse files Browse the repository at this point in the history
Don't return serializer type in EncodeCBOR
  • Loading branch information
muzzammilshahid authored Jul 10, 2024
2 parents 9ddebed + e27a0f1 commit d40cf39
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 10 deletions.
8 changes: 5 additions & 3 deletions serializers/cbor.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import (
"github.com/xconnio/wampproto-go/messages"
)

const CBORSerializerID = 3

var cborEncoder cbor.DecMode //nolint:gochecknoglobals

type CBORSerializer struct{}
Expand Down Expand Up @@ -44,16 +46,16 @@ func (c *CBORSerializer) Static() bool {
return false
}

func EncodeCBOR(args []any, kwargs map[string]any) ([]byte, int, error) {
func EncodeCBOR(args []any, kwargs map[string]any) ([]byte, error) {
var payload []any
payload = append(payload, args)
payload = append(payload, kwargs)
payloadData, err := cbor.Marshal(payload)
if err != nil {
return nil, 0, err
return nil, err
}

return payloadData, CBORSerializerValue, nil
return payloadData, nil
}

func DecodeCBOR(data []byte) ([]any, map[string]any, error) {
Expand Down
7 changes: 0 additions & 7 deletions serializers/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,6 @@ import (
"github.com/xconnio/wampproto-go/messages"
)

const (
JSONSerializerValue = 1
MsgPackSerializerValue = 2
CBORSerializerValue = 3
ProtobufSerializerValue = 16
)

func ToMessage(wampMsg []any) (messages.Message, error) {
messageType, _ := messages.AsInt64(wampMsg[0])
var msg messages.Message
Expand Down
2 changes: 2 additions & 0 deletions serializers/json.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import (
"github.com/xconnio/wampproto-go/messages"
)

const JSONSerializerID = 1

type JSONSerializer struct{}

func (j *JSONSerializer) Serialize(message messages.Message) ([]byte, error) {
Expand Down
2 changes: 2 additions & 0 deletions serializers/msgpack.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import (
"github.com/xconnio/wampproto-go/messages"
)

const MsgPackSerializerID = 2

type MsgPackSerializer struct{}

func (m *MsgPackSerializer) Serialize(message messages.Message) ([]byte, error) {
Expand Down

0 comments on commit d40cf39

Please sign in to comment.