diff --git a/acceptor.go b/acceptor.go index 33375b0..083b47e 100644 --- a/acceptor.go +++ b/acceptor.go @@ -253,7 +253,8 @@ func (a *Acceptor) sendWelcome(sessionID int64, response auth.Response) *message "authmethod": a.authMethod, }) - a.sessionDetails = NewSessionDetails(sessionID, a.hello.Realm(), response.AuthID(), response.AuthRole()) + a.sessionDetails = NewSessionDetails(sessionID, a.hello.Realm(), response.AuthID(), response.AuthRole(), + a.serializer.Static()) a.state = AcceptorStateWelcomeSent return welcome diff --git a/dealer.go b/dealer.go index 4b0f340..f305a30 100644 --- a/dealer.go +++ b/dealer.go @@ -116,9 +116,7 @@ func (d *Dealer) ReceiveMessage(sessionID int64, msg messages.Message) (*Message } var invocation *messages.Invocation - if call.PayloadIsBinary() { - // FIXME: If CALL has binary payload, we need to make sure the callee - // also supports binary payloads. + if call.PayloadIsBinary() && d.sessions[callee].StaticSerializer() { invocation = messages.NewInvocationBinary(invocationID, regs.ID, nil, call.Payload(), call.PayloadSerializer()) } else { @@ -136,7 +134,7 @@ func (d *Dealer) ReceiveMessage(sessionID int64, msg messages.Message) (*Message delete(d.pendingCalls, yield.RequestID()) var result *messages.Result - if yield.PayloadIsBinary() { + if yield.PayloadIsBinary() && d.sessions[pending.CallerID].StaticSerializer() { // FIXME: If YIELD has binary payload, we need to make sure the caller // also supports binary payloads. result = messages.NewResultBinary(pending.RequestID, nil, yield.Payload(), yield.PayloadSerializer()) diff --git a/dealer_test.go b/dealer_test.go index ada0da5..dd53dca 100644 --- a/dealer_test.go +++ b/dealer_test.go @@ -18,7 +18,7 @@ func TestDealerAddRemoveSession(t *testing.T) { }) t.Run("AddRemove", func(t *testing.T) { - details := wampproto.NewSessionDetails(1, "realm", "authid", "anonymous") + details := wampproto.NewSessionDetails(1, "realm", "authid", "anonymous", false) err := dealer.AddSession(details) require.NoError(t, err) @@ -34,7 +34,7 @@ func TestDealerRegisterUnRegister(t *testing.T) { dealer := wampproto.NewDealer() t.Run("Register", func(t *testing.T) { - details := wampproto.NewSessionDetails(1, "realm", "authid", "anonymous") + details := wampproto.NewSessionDetails(1, "realm", "authid", "anonymous", false) err := dealer.AddSession(details) require.NoError(t, err) diff --git a/joiner.go b/joiner.go index dba56c1..a5ebf9e 100644 --- a/joiner.go +++ b/joiner.go @@ -112,7 +112,7 @@ func (j *Joiner) ReceiveMessage(msg messages.Message) (messages.Message, error) welcome := msg.(*messages.Welcome) j.sessionDetails = NewSessionDetails(welcome.SessionID(), j.realm, welcome.Details()["authid"].(string), - welcome.Details()["authrole"].(string)) + welcome.Details()["authrole"].(string), j.serializer.Static()) j.state = joinerStateJoined return nil, nil diff --git a/serializers/cbor.go b/serializers/cbor.go index 8c79751..7e26cbc 100644 --- a/serializers/cbor.go +++ b/serializers/cbor.go @@ -38,3 +38,7 @@ func (c *CBORSerializer) Deserialize(payload []byte) (messages.Message, error) { return msg, nil } + +func (c *CBORSerializer) Static() bool { + return false +} diff --git a/serializers/json.go b/serializers/json.go index b5f64c4..d5ccd44 100644 --- a/serializers/json.go +++ b/serializers/json.go @@ -29,3 +29,7 @@ func (j *JSONSerializer) Deserialize(payload []byte) (messages.Message, error) { return msg, nil } + +func (j *JSONSerializer) Static() bool { + return false +} diff --git a/serializers/msgpack.go b/serializers/msgpack.go index 76d018b..7bf3d9e 100644 --- a/serializers/msgpack.go +++ b/serializers/msgpack.go @@ -29,3 +29,7 @@ func (m *MsgPackSerializer) Deserialize(payload []byte) (messages.Message, error return msg, nil } + +func (m *MsgPackSerializer) Static() bool { + return false +} diff --git a/serializers/serializer.go b/serializers/serializer.go index 4810b7f..13a69f3 100644 --- a/serializers/serializer.go +++ b/serializers/serializer.go @@ -5,4 +5,5 @@ import "github.com/xconnio/wampproto-go/messages" type Serializer interface { Serialize(message messages.Message) ([]byte, error) Deserialize([]byte) (messages.Message, error) + Static() bool } diff --git a/types.go b/types.go index 5d05653..52d1621 100644 --- a/types.go +++ b/types.go @@ -7,14 +7,17 @@ type SessionDetails struct { realm string authID string authRole string + + staticSerializer bool } -func NewSessionDetails(id int64, realm, authID, authRole string) *SessionDetails { +func NewSessionDetails(id int64, realm, authID, authRole string, staticSerializer bool) *SessionDetails { return &SessionDetails{ - id: id, - realm: realm, - authID: authID, - authRole: authRole, + id: id, + realm: realm, + authID: authID, + authRole: authRole, + staticSerializer: staticSerializer, } } @@ -34,6 +37,10 @@ func (s *SessionDetails) AuthRole() string { return s.authRole } +func (s *SessionDetails) StaticSerializer() bool { + return s.staticSerializer +} + type MessageWithRecipient struct { Message messages.Message Recipient int64