-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from xconnio/reg-msg
Add registration related messages
- Loading branch information
Showing
5 changed files
with
308 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
package messages | ||
|
||
import "fmt" | ||
|
||
const MessageTypeRegister = 64 | ||
const MessageNameRegister = "REGISTER" | ||
|
||
var registerValidationSpec = ValidationSpec{ //nolint:gochecknoglobals | ||
MinLength: 4, | ||
MaxLength: 4, | ||
Message: MessageNameRegister, | ||
Spec: Spec{ | ||
1: ValidateRequestID, | ||
2: ValidateOptions, | ||
3: ValidateURI, | ||
}, | ||
} | ||
|
||
type Register interface { | ||
Message | ||
|
||
RequestID() int64 | ||
Options() map[string]any | ||
Procedure() string | ||
} | ||
|
||
type register struct { | ||
requestID int64 | ||
options map[string]any | ||
procedure string | ||
} | ||
|
||
func NewEmptyRegister() Register { | ||
return ®ister{} | ||
} | ||
|
||
func NewRegister(requestID int64, options map[string]any, uri string) Register { | ||
return ®ister{ | ||
requestID: requestID, | ||
options: options, | ||
procedure: uri, | ||
} | ||
} | ||
|
||
func (r *register) Type() int { | ||
return MessageTypeRegister | ||
} | ||
|
||
func (r *register) Parse(wampMsg []any) error { | ||
fields, err := ValidateMessage(wampMsg, registerValidationSpec) | ||
if err != nil { | ||
return fmt.Errorf("register: failed to validate message %s: %w", MessageNameRegister, err) | ||
} | ||
|
||
r.requestID = fields.SessionID | ||
r.options = fields.Options | ||
r.procedure = fields.URI | ||
|
||
return nil | ||
} | ||
|
||
func (r *register) Marshal() []any { | ||
return []any{MessageTypeRegister, r.requestID, r.options, r.procedure} | ||
} | ||
|
||
func (r *register) RequestID() int64 { | ||
return r.requestID | ||
} | ||
|
||
func (r *register) Options() map[string]any { | ||
return r.options | ||
} | ||
|
||
func (r *register) Procedure() string { | ||
return r.procedure | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
package messages | ||
|
||
import "fmt" | ||
|
||
const MessageTypeRegistered = 65 | ||
const MessageNameRegistered = "REGISTERED" | ||
|
||
var registeredValidationSpec = ValidationSpec{ //nolint:gochecknoglobals | ||
MinLength: 3, | ||
MaxLength: 3, | ||
Message: MessageNameRegistered, | ||
Spec: Spec{ | ||
1: ValidateRequestID, | ||
2: ValidateRegistrationID, | ||
}, | ||
} | ||
|
||
type Registered interface { | ||
Message | ||
|
||
RequestID() int64 | ||
RegistrationID() int64 | ||
} | ||
|
||
type registered struct { | ||
requestID int64 | ||
registrationID int64 | ||
} | ||
|
||
func NewEmptyRegistered() Registered { | ||
return ®istered{} | ||
} | ||
|
||
func NewRegistered(requestID, registrationID int64) Registered { | ||
return ®istered{ | ||
requestID: requestID, | ||
registrationID: registrationID, | ||
} | ||
} | ||
|
||
func (r *registered) Type() int { | ||
return MessageTypeRegistered | ||
} | ||
|
||
func (r *registered) Parse(wampMsg []any) error { | ||
fields, err := ValidateMessage(wampMsg, registeredValidationSpec) | ||
if err != nil { | ||
return fmt.Errorf("registered: failed to validate message %s: %w", MessageNameRegistered, err) | ||
} | ||
|
||
r.requestID = fields.RequestID | ||
r.registrationID = fields.RegistrationID | ||
|
||
return nil | ||
} | ||
|
||
func (r *registered) Marshal() []any { | ||
return []any{MessageTypeRegistered, r.requestID, r.registrationID} | ||
} | ||
|
||
func (r *registered) RequestID() int64 { | ||
return r.requestID | ||
} | ||
|
||
func (r *registered) RegistrationID() int64 { | ||
return r.registrationID | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
package messages | ||
|
||
import "fmt" | ||
|
||
const MessageTypeUnRegister = 66 | ||
const MessageNameUnRegister = "UNREGISTER" | ||
|
||
var unRegisterValidationSpec = ValidationSpec{ //nolint:gochecknoglobals | ||
MinLength: 3, | ||
MaxLength: 3, | ||
Message: MessageNameUnRegister, | ||
Spec: Spec{ | ||
1: ValidateRequestID, | ||
2: ValidateRegistrationID, | ||
}, | ||
} | ||
|
||
type UnRegister interface { | ||
Message | ||
|
||
RequestID() int64 | ||
RegistrationID() int64 | ||
} | ||
|
||
type unRegister struct { | ||
requestID int64 | ||
registrationID int64 | ||
} | ||
|
||
func NewEmptyUnRegister() UnRegister { | ||
return &unRegister{} | ||
} | ||
|
||
func NewUnRegister(requestID, registrationID int64) UnRegister { | ||
return &unRegister{ | ||
requestID: requestID, | ||
registrationID: registrationID, | ||
} | ||
} | ||
|
||
func (r *unRegister) Type() int { | ||
return MessageTypeUnRegister | ||
} | ||
|
||
func (r *unRegister) Parse(wampMsg []any) error { | ||
fields, err := ValidateMessage(wampMsg, unRegisterValidationSpec) | ||
if err != nil { | ||
return fmt.Errorf("unregister: failed to validate message %s: %w", MessageNameUnRegister, err) | ||
} | ||
|
||
r.requestID = fields.RequestID | ||
r.registrationID = fields.RegistrationID | ||
|
||
return nil | ||
} | ||
|
||
func (r *unRegister) Marshal() []any { | ||
return []any{MessageTypeUnRegister, r.requestID, r.registrationID} | ||
} | ||
|
||
func (r *unRegister) RequestID() int64 { | ||
return r.requestID | ||
} | ||
|
||
func (r *unRegister) RegistrationID() int64 { | ||
return r.registrationID | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package messages | ||
|
||
import "fmt" | ||
|
||
const MessageTypeUnRegistered = 67 | ||
const MessageNameUnRegistered = "UNREGISTERED" | ||
|
||
var unRegisteredValidationSpec = ValidationSpec{ //nolint:gochecknoglobals | ||
MinLength: 2, | ||
MaxLength: 2, | ||
Message: MessageNameUnRegistered, | ||
Spec: Spec{ | ||
1: ValidateRequestID, | ||
}, | ||
} | ||
|
||
type UnRegistered interface { | ||
Message | ||
|
||
RequestID() int64 | ||
} | ||
|
||
type unRegistered struct { | ||
requestID int64 | ||
} | ||
|
||
func NewEmptyUnRegistered() UnRegistered { | ||
return &unRegistered{} | ||
} | ||
|
||
func NewUnRegistered(requestID int64) UnRegistered { | ||
return &unRegistered{ | ||
requestID: requestID, | ||
} | ||
} | ||
|
||
func (r *unRegistered) Type() int { | ||
return MessageTypeUnRegistered | ||
} | ||
|
||
func (r *unRegistered) Parse(wampMsg []any) error { | ||
fields, err := ValidateMessage(wampMsg, unRegisteredValidationSpec) | ||
if err != nil { | ||
return fmt.Errorf("unregistered: failed to validate message %s: %w", MessageNameUnRegistered, err) | ||
} | ||
|
||
r.requestID = fields.RequestID | ||
|
||
return nil | ||
} | ||
|
||
func (r *unRegistered) Marshal() []any { | ||
return []any{MessageTypeUnRegistered, r.requestID} | ||
} | ||
|
||
func (r *unRegistered) RequestID() int64 { | ||
return r.requestID | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters