Skip to content

Commit

Permalink
Merge pull request #14 from xconnio/session
Browse files Browse the repository at this point in the history
Add WAMP session
  • Loading branch information
om26er authored May 26, 2024
2 parents 4444866 + 9b1309b commit 3bc6d81
Show file tree
Hide file tree
Showing 6 changed files with 412 additions and 42 deletions.
36 changes: 19 additions & 17 deletions messages/invocation.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package messages

import "fmt"
import (
"fmt"
)

const MessageTypeInvocation = 68
const MessageNameInvocation = "INVOCATION"
Expand All @@ -22,32 +24,32 @@ type Invocation interface {
Message

RequestID() int64
RegistrationID() int64
Details() map[string]any
Procedure() string
Args() []any
KwArgs() map[string]any
}

type invocation struct {
requestID int64
details map[string]any
procedure string
args []any
kwArgs map[string]any
requestID int64
registrationID int64
details map[string]any
args []any
kwArgs map[string]any
}

func NewEmptyInvocation() Invocation {
return &invocation{}
}

func NewInvocation(requestID int64, details map[string]any, procedure string, args []any,
func NewInvocation(requestID, registrationID int64, details map[string]any, args []any,
kwArgs map[string]any) Invocation {
return &invocation{
requestID: requestID,
details: details,
procedure: procedure,
args: args,
kwArgs: kwArgs,
requestID: requestID,
registrationID: registrationID,
details: details,
args: args,
kwArgs: kwArgs,
}
}

Expand All @@ -59,8 +61,8 @@ func (e *invocation) Details() map[string]any {
return e.details
}

func (e *invocation) Procedure() string {
return e.procedure
func (e *invocation) RegistrationID() int64 {
return e.registrationID
}

func (e *invocation) Args() []any {
Expand All @@ -82,16 +84,16 @@ func (e *invocation) Parse(wampMsg []any) error {
}

e.requestID = fields.RequestID
e.registrationID = fields.RegistrationID
e.details = fields.Details
e.procedure = fields.URI
e.args = fields.Args
e.kwArgs = fields.KwArgs

return nil
}

func (e *invocation) Marshal() []any {
result := []any{MessageTypeInvocation, e.requestID, e.details, e.procedure}
result := []any{MessageTypeInvocation, e.requestID, e.registrationID, e.details}

if e.args != nil {
result = append(result, e.args)
Expand Down
14 changes: 2 additions & 12 deletions messages/result.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ var resultValidationSpec = ValidationSpec{ //nolint:gochecknoglobals
Spec: Spec{
1: ValidateRequestID,
2: ValidateDetails,
3: ValidateURI,
4: ValidateArgs,
5: ValidateKwArgs,
},
Expand All @@ -23,15 +22,13 @@ type Result interface {

RequestID() int64
Details() map[string]any
Procedure() string
Args() []any
KwArgs() map[string]any
}

type resultMsg struct {
requestID int64
details map[string]any
procedure string
args []any
kwArgs map[string]any
}
Expand All @@ -40,12 +37,10 @@ func NewEmptyResult() Result {
return &resultMsg{}
}

func NewResult(requestID int64, details map[string]any, procedure string, args []any,
kwArgs map[string]any) Result {
func NewResult(requestID int64, details map[string]any, args []any, kwArgs map[string]any) Result {
return &resultMsg{
requestID: requestID,
details: details,
procedure: procedure,
args: args,
kwArgs: kwArgs,
}
Expand All @@ -59,10 +54,6 @@ func (e *resultMsg) Details() map[string]any {
return e.details
}

func (e *resultMsg) Procedure() string {
return e.procedure
}

func (e *resultMsg) Args() []any {
return e.args
}
Expand All @@ -83,15 +74,14 @@ func (e *resultMsg) Parse(wampMsg []any) error {

e.requestID = fields.RequestID
e.details = fields.Details
e.procedure = fields.URI
e.args = fields.Args
e.kwArgs = fields.KwArgs

return nil
}

func (e *resultMsg) Marshal() []any {
result := []any{MessageTypeResult, e.requestID, e.details, e.procedure}
result := []any{MessageTypeResult, e.requestID, e.details}

if e.args != nil {
result = append(result, e.args)
Expand Down
2 changes: 1 addition & 1 deletion messages/unsubscribe.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package messages

import "fmt"

const MessageTypeUnSubscribe = 32
const MessageTypeUnSubscribe = 33
const MessageNameUnSubscribe = "UNSUBSCRIBE"

var unSubscribeValidationSpec = ValidationSpec{ //nolint:gochecknoglobals
Expand Down
15 changes: 3 additions & 12 deletions messages/yield.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,12 @@ const MessageTypeYield = 70
const MessageNameYield = "YIELD"

var yieldValidationSpec = ValidationSpec{ //nolint:gochecknoglobals
MinLength: 4,
MaxLength: 6,
MinLength: 3,
MaxLength: 5,
Message: MessageNameYield,
Spec: Spec{
1: ValidateRequestID,
2: ValidateOptions,
3: ValidateURI,
4: ValidateArgs,
5: ValidateKwArgs,
},
Expand All @@ -23,15 +22,13 @@ type Yield interface {

RequestID() int64
Options() map[string]any
Procedure() string
Args() []any
KwArgs() map[string]any
}

type yield struct {
requestID int64
options map[string]any
procedure string
args []any
kwArgs map[string]any
}
Expand All @@ -44,7 +41,6 @@ func NewYield(requestID int64, options map[string]any, procedure string, args []
return &yield{
requestID: requestID,
options: options,
procedure: procedure,
args: args,
kwArgs: kwArgs,
}
Expand All @@ -58,10 +54,6 @@ func (e *yield) Options() map[string]any {
return e.options
}

func (e *yield) Procedure() string {
return e.procedure
}

func (e *yield) Args() []any {
return e.args
}
Expand All @@ -82,15 +74,14 @@ func (e *yield) Parse(wampMsg []any) error {

e.requestID = fields.RequestID
e.options = fields.Options
e.procedure = fields.URI
e.args = fields.Args
e.kwArgs = fields.KwArgs

return nil
}

func (e *yield) Marshal() []any {
result := []any{MessageTypeYield, e.requestID, e.options, e.procedure}
result := []any{MessageTypeYield, e.requestID, e.options}

if e.args != nil {
result = append(result, e.args)
Expand Down
Loading

0 comments on commit 3bc6d81

Please sign in to comment.