-
Notifications
You must be signed in to change notification settings - Fork 11
/
message.go
52 lines (42 loc) · 823 Bytes
/
message.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
package swap
import (
"encoding/json"
"github.com/NadiaSama/ccexgo/exchange/huobi"
"github.com/NadiaSama/ccexgo/internal/rpc"
"github.com/pkg/errors"
)
type (
CodeC struct {
*huobi.CodeC
}
)
func NewCodeC() *CodeC {
return &CodeC{
huobi.NewCodeC(),
}
}
func (cc *CodeC) Decode(raw []byte) (rpc.Response, error) {
msg, err := cc.Decompress(raw)
if err != nil {
return nil, err
}
var resp huobi.Response
if err := json.Unmarshal(msg, &resp); err != nil {
return nil, errors.WithMessagef(err, "bad response '%s'", string(msg))
}
ret, err := resp.Parse(msg)
if ret != nil {
return ret, nil
}
if err != nil && err != huobi.SkipError {
return nil, err
}
r, err := ParseDepth(resp.Tick)
if err != nil {
return nil, err
}
return &rpc.Notify{
Method: resp.Ch,
Params: r,
}, nil
}