Skip to content

Commit

Permalink
make it easy to use protobuf serializer
Browse files Browse the repository at this point in the history
  • Loading branch information
om26er committed Jul 1, 2024
1 parent 260f672 commit 1ee5293
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 8 deletions.
8 changes: 1 addition & 7 deletions cmd/xconn/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
"golang.org/x/exp/slices"
"gopkg.in/yaml.v3"

"github.com/xconnio/wampproto-protobuf/go"
"github.com/xconnio/xconn-go"
)

Expand All @@ -25,8 +24,6 @@ const (

ConfigDir = ".xconn"
ConfigFile = ConfigDir + "/config.yaml"

ProtobufSubProtocol = "wamp.2.protobuf"
)

type cmd struct {
Expand Down Expand Up @@ -96,10 +93,7 @@ func Run(args []string) error {

for _, transport := range config.Transports {
if slices.Contains(transport.Serializers, "protobuf") {
serializer := &wampprotobuf.ProtobufSerializer{}
protobufSpec := xconn.NewWSSerializerSpec(ProtobufSubProtocol, serializer)

if err := server.RegisterSpec(protobufSpec); err != nil {
if err := server.RegisterSpec(xconn.ProtobufSerializerSpec); err != nil {
return err
}
}
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ require (
github.com/gobwas/ws v1.4.0
github.com/stretchr/testify v1.8.4
github.com/xconnio/wampproto-go v0.0.0-20240630150305-316020c30fb7
github.com/xconnio/wampproto-protobuf/go v0.0.0-20240611092706-1e859744b5a2
github.com/xconnio/wampproto-protobuf/go v0.0.0-20240701141955-e9a1025ec125
golang.org/x/exp v0.0.0-20240525044651-4c93da0ed11d
gopkg.in/yaml.v3 v3.0.1
)
Expand Down
1 change: 1 addition & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ github.com/xconnio/wampproto-go v0.0.0-20240630150305-316020c30fb7 h1:DrQEqUq14X
github.com/xconnio/wampproto-go v0.0.0-20240630150305-316020c30fb7/go.mod h1:/b7EyR1X9EkOHPQBJGz1KvdjClo1GsalBGIzjQU5+i4=
github.com/xconnio/wampproto-protobuf/go v0.0.0-20240611092706-1e859744b5a2 h1:1WkQ68ICoin0wTerMn5FrWl+ZbK4XS3/W2Wr86jS9K8=
github.com/xconnio/wampproto-protobuf/go v0.0.0-20240611092706-1e859744b5a2/go.mod h1:SZAkbKSDucIUBrPgcKlT0SzVmktfrsD7OdP1chFR+vw=
github.com/xconnio/wampproto-protobuf/go v0.0.0-20240701141955-e9a1025ec125/go.mod h1:SZAkbKSDucIUBrPgcKlT0SzVmktfrsD7OdP1chFR+vw=
github.com/xhit/go-str2duration/v2 v2.1.0 h1:lxklc02Drh6ynqX+DdPyp5pCKLUQpRT8bp8Ydu2Bstc=
github.com/xhit/go-str2duration/v2 v2.1.0/go.mod h1:ohY8p+0f07DiV6Em5LKB0s2YpLtXVyJfNt1+BlmyAsU=
go.uber.org/goleak v1.2.1 h1:NBol2c7O1ZokfZ0LEU9K6Whx/KnwvepVetCUhtKja4A=
Expand Down
3 changes: 3 additions & 0 deletions types.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (

"github.com/xconnio/wampproto-go/messages"
"github.com/xconnio/wampproto-go/serializers"
wampprotobuf "github.com/xconnio/wampproto-protobuf/go"
)

type (
Expand All @@ -27,6 +28,8 @@ var (
CborWebsocketProtocol, &serializers.CBORSerializer{})
MsgPackSerializerSpec = NewWSSerializerSpec( //nolint:gochecknoglobals
MsgpackWebsocketProtocol, &serializers.MsgPackSerializer{})
ProtobufSerializerSpec = NewWSSerializerSpec( //nolint:gochecknoglobals
ProtobufSubProtocol, &wampprotobuf.ProtobufSerializer{})
)

type BaseSession interface {
Expand Down
1 change: 1 addition & 0 deletions wamp.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ const (
JsonWebsocketProtocol = "wamp.2.json"
MsgpackWebsocketProtocol = "wamp.2.msgpack"
CborWebsocketProtocol = "wamp.2.cbor"
ProtobufSubProtocol = "wamp.2.protobuf"
)

0 comments on commit 1ee5293

Please sign in to comment.