-
Notifications
You must be signed in to change notification settings - Fork 0
/
response.go
64 lines (56 loc) · 1.39 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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package yar
import (
"encoding/json"
"errors"
)
type exception struct {
Message string `json:"message" msgpack:"message"`
Code int `json:"code" msgpack:"code"`
File string `json:"file" msgpack:"file"`
Line int `json:"line" msgpack:"line"`
Type string `json:"_type" msgpack:"_type"`
}
type Exception struct {
e exception
}
func (e *Exception) GetMessage() string {
return e.e.Message
}
func (e *Exception) UnmarshalJSON(data []byte) error {
if len(data) == 0 {
return nil
}
if e == nil {
*e = Exception{e: exception{}}
}
if data[0] == '"' {
e.e.Message = string(data)
return nil
} else {
return json.Unmarshal(data, &e.e)
}
}
type RawMessage json.RawMessage
// MarshalMsgpack returns *m as the msgpack encoding of m.
func (m *RawMessage) MarshalMsgpack() ([]byte, error) {
return *m, nil
}
// UnmarshalMsgpack sets *m to a copy of data.
func (m *RawMessage) UnmarshalMsgpack(data []byte) error {
if m == nil {
return errors.New("msgpack.RawMessage: UnmarshalMsgpack on nil pointer")
}
*m = append((*m)[0:0], data...)
return nil
}
type Response struct {
Id uint32 `json:"i" msgpack:"i"`
Error *Exception `json:"e" msgpack:"e"`
Out RawMessage `json:"o" msgpack:"o"`
Response RawMessage `json:"r" msgpack:"r"`
Status ErrorType `json:"s" msgpack:"s"`
}
func NewResponse() (response *Response) {
response = new(Response)
return response
}