-
Notifications
You must be signed in to change notification settings - Fork 0
/
response.go
50 lines (45 loc) · 1.09 KB
/
response.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package ssp
type ResponseCode byte
// Generic response codes
const (
OK ResponseCode = 0xF0
CommandNotKnown ResponseCode = 0xF2
WrongNumberOfParameters ResponseCode = 0xF3
ParameterOutOfRange ResponseCode = 0xF4
CommandCannotBeProcessed ResponseCode = 0xF5
SoftwareError ResponseCode = 0xF6
Fail ResponseCode = 0xF8
KeyNotSet ResponseCode = 0xFA
)
type Response struct {
Code ResponseCode `json:"code"`
Args []byte `json:"-"`
}
func NewResponse(code ResponseCode, args []byte) *Response {
return &Response{
Code: code,
Args: args,
}
}
func (r *Response) String() string {
switch r.Code {
default:
return "unknown code"
case OK:
return "ok"
case CommandNotKnown:
return "command not known"
case WrongNumberOfParameters:
return "wrong number of params"
case ParameterOutOfRange:
return "parameter out of range"
case CommandCannotBeProcessed:
return "cannot be processed"
case SoftwareError:
return "software error"
case Fail:
return "fail"
case KeyNotSet:
return "key not set"
}
}