-
Notifications
You must be signed in to change notification settings - Fork 3
/
util.go
143 lines (139 loc) · 3.53 KB
/
util.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
package rtm2_sdk
import base "github.com/tomasliu-agora/rtm2-base"
func generateHeader(uri int32, m Marshalable) *Header {
buffer, _ := m.Marshal()
return &Header{Uri: uri, Message: buffer}
}
func getUriFromReq(req interface{}) int32 {
switch req.(type) {
case *base.LoginReq:
return UriLogin
case *base.LogoutReq:
return UriLogout
case *base.MessageSubReq:
return UriMessageSubscribe
case *base.MessageUnsubReq:
return UriMessageUnsubscribe
case *base.MessagePublishReq:
return UriMessagePublish
case *base.StreamJoinReq:
return UriStreamJoin
case *base.StreamLeaveReq:
return UriStreamLeave
case *base.StreamJoinTopicReq:
return UriStreamJoinTopic
case *base.StreamMessageReq:
return UriStreamPublish
case *base.StreamLeaveTopicReq:
return UriStreamLeaveTopic
case *base.StreamSubTopicReq:
return UriStreamSubTopic
case *base.StreamUnsubTopicReq:
return UriStreamUnsubTopic
case *base.StreamSubListReq:
return 0 // TODO
case *base.StorageChannelReq:
return UriStorageOpChannelMetaData
case *base.StorageChannelGetReq:
return UriStorageGetChannelMetaData
case *base.StorageUserReq:
return UriStorageOpUserMetaData
case *base.StorageUserGetReq:
return UriStorageGetUserMetaData
case *base.StorageUserSubReq:
return UriStorageSubscribeUserMetaData
case *base.StorageUserUnsubReq:
return UriStorageUnSubscribeUserMetaData
case *base.PresenceWhereNowReq:
return UriPresenceWhereNow
case *base.PresenceWhoNowReq:
return UriPresenceWhoNow
case *base.PresenceSetStateReq:
return UriPresenceSetState
case *base.PresenceGetStateReq:
return UriPresenceGetState
case *base.PresenceRemoveStateReq:
return UriPresenceRemoveState
case *base.SetParamsReq:
return UriSetParam
case *base.RenewTokenReq:
return UriRenewToken
case *base.LockSetReq:
return UriLockSet
case *base.LockRemoveReq:
return UriLockRemove
case *base.LockGetReq:
return UriLockGet
case *base.LockAcquireReq:
return UriLockAcquire
case *base.LockReleaseReq:
return UriLockRelease
case *base.LockRevokeReq:
return UriLockRevoke
case base.TokenPrivilegeExpire:
return UriTokenPrivilegeExpire
default:
return 0
}
}
func unmarshalResp(uri int32, errCode int32, message []byte) (interface{}, int32, error) {
switch uri {
case UriStreamSubTopic:
resp := &base.StreamSubTopicResp{}
err := resp.Unmarshal(message)
if err != nil {
return nil, errCode, err
} else {
return resp, errCode, nil
}
case UriStorageGetChannelMetaData:
resp := &base.StorageChannelGetResp{}
err := resp.Unmarshal(message)
if err != nil {
return nil, errCode, err
} else {
return resp, errCode, nil
}
case UriStorageGetUserMetaData:
resp := &base.StorageUserGetResp{}
err := resp.Unmarshal(message)
if err != nil {
return nil, errCode, err
} else {
return resp, errCode, nil
}
case UriPresenceWhoNow:
resp := &base.PresenceWhoNowResp{}
err := resp.Unmarshal(message)
if err != nil {
return nil, errCode, err
} else {
return resp, errCode, nil
}
case UriPresenceWhereNow:
resp := &base.PresenceWhereNowResp{}
err := resp.Unmarshal(message)
if err != nil {
return nil, errCode, err
} else {
return resp, errCode, nil
}
case UriPresenceGetState:
resp := &base.PresenceGetStateResp{}
err := resp.Unmarshal(message)
if err != nil {
return nil, errCode, err
} else {
return resp, errCode, nil
}
case UriLockGet:
resp := &base.LockGetResp{}
err := resp.Unmarshal(message)
if err != nil {
return nil, errCode, err
} else {
return resp, errCode, nil
}
}
return nil, 0, nil
}