Skip to content

Commit

Permalink
Merge pull request #34 from xconnio/static-serializers
Browse files Browse the repository at this point in the history
passthru payload if recipient supports it
  • Loading branch information
om26er authored Jun 6, 2024
2 parents 5235d6a + 485df3e commit 14a7a17
Show file tree
Hide file tree
Showing 9 changed files with 32 additions and 13 deletions.
3 changes: 2 additions & 1 deletion acceptor.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 2 additions & 4 deletions dealer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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())
Expand Down
4 changes: 2 additions & 2 deletions dealer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion joiner.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions serializers/cbor.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,7 @@ func (c *CBORSerializer) Deserialize(payload []byte) (messages.Message, error) {

return msg, nil
}

func (c *CBORSerializer) Static() bool {
return false
}
4 changes: 4 additions & 0 deletions serializers/json.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,7 @@ func (j *JSONSerializer) Deserialize(payload []byte) (messages.Message, error) {

return msg, nil
}

func (j *JSONSerializer) Static() bool {
return false
}
4 changes: 4 additions & 0 deletions serializers/msgpack.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,7 @@ func (m *MsgPackSerializer) Deserialize(payload []byte) (messages.Message, error

return msg, nil
}

func (m *MsgPackSerializer) Static() bool {
return false
}
1 change: 1 addition & 0 deletions serializers/serializer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
17 changes: 12 additions & 5 deletions types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
}

Expand All @@ -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
Expand Down

0 comments on commit 14a7a17

Please sign in to comment.