Skip to content

Commit

Permalink
add wamp UNREGISTERED message
Browse files Browse the repository at this point in the history
  • Loading branch information
om26er committed May 25, 2024
1 parent cc0ee6a commit 09bdf8d
Showing 1 changed file with 58 additions and 0 deletions.
58 changes: 58 additions & 0 deletions messages/unregistered.go
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
}

0 comments on commit 09bdf8d

Please sign in to comment.