-
Notifications
You must be signed in to change notification settings - Fork 302
/
v3.go
116 lines (93 loc) · 3.92 KB
/
v3.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
// Copyright © 2019 The Things Network Foundation, The Things Industries B.V.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package topics
import (
"github.com/TheThingsIndustries/mystique/pkg/topic"
)
const topicV3 = "v3"
type v3 struct{}
func (v3) AcceptedTopic(applicationUID string, requested []string) ([]string, bool) {
// Rewrite # to v3/uid/#
if requested[0] == topic.Wildcard {
return []string{topicV3, applicationUID, topic.Wildcard}, true
}
if requested[0] != topicV3 || len(requested) < 2 {
return nil, false
}
switch requested[1] {
case topic.Wildcard:
// Rewrite v3/# to v3/uid/#
return []string{topicV3, applicationUID, topic.Wildcard}, true
case topic.PartWildcard:
// Rewrite v3/+/... to v3/uid/...
requested[1] = applicationUID
return requested, true
case applicationUID:
return requested, true
}
return nil, false
}
func (v3) UplinkMessageTopic(applicationUID, deviceID string) []string {
return []string{topicV3, applicationUID, "devices", deviceID, "up"}
}
func (v3) UplinkNormalizedTopic(applicationUID, deviceID string) []string {
return []string{topicV3, applicationUID, "devices", deviceID, "up", "normalized"}
}
func (v3) JoinAcceptTopic(applicationUID, deviceID string) []string {
return []string{topicV3, applicationUID, "devices", deviceID, "join"}
}
func (v3) DownlinkAckTopic(applicationUID, deviceID string) []string {
return []string{topicV3, applicationUID, "devices", deviceID, "down", "ack"}
}
func (v3) DownlinkNackTopic(applicationUID, deviceID string) []string {
return []string{topicV3, applicationUID, "devices", deviceID, "down", "nack"}
}
func (v3) DownlinkSentTopic(applicationUID, deviceID string) []string {
return []string{topicV3, applicationUID, "devices", deviceID, "down", "sent"}
}
func (v3) DownlinkFailedTopic(applicationUID, deviceID string) []string {
return []string{topicV3, applicationUID, "devices", deviceID, "down", "failed"}
}
func (v3) DownlinkQueuedTopic(applicationUID, deviceID string) []string {
return []string{topicV3, applicationUID, "devices", deviceID, "down", "queued"}
}
func (v3) DownlinkQueueInvalidatedTopic(applicationUID, deviceID string) []string {
return []string{topicV3, applicationUID, "devices", deviceID, "down", "invalidated"}
}
func (v3) LocationSolvedTopic(applicationUID, deviceID string) []string {
return []string{topicV3, applicationUID, "devices", deviceID, "location", "solved"}
}
func (v3) ServiceDataTopic(applicationUID, deviceID string) []string {
return []string{topicV3, applicationUID, "devices", deviceID, "service", "data"}
}
func (v3) DownlinkPushTopic(applicationUID, deviceID string) []string {
return []string{topicV3, applicationUID, "devices", deviceID, "down", "push"}
}
func (v3) IsDownlinkPushTopic(parts []string) bool {
return len(parts) == 6 && parts[0] == topicV3 && parts[2] == "devices" && parts[4] == "down" && parts[5] == "push"
}
func (v3) ParseDownlinkPushTopic(parts []string) (deviceID string) {
return parts[3]
}
func (v3) DownlinkReplaceTopic(applicationUID, deviceID string) []string {
return []string{topicV3, applicationUID, "devices", deviceID, "down", "replace"}
}
func (v3) IsDownlinkReplaceTopic(parts []string) bool {
return len(parts) == 6 && parts[0] == topicV3 && parts[2] == "devices" && parts[4] == "down" && parts[5] == "replace"
}
func (v3) ParseDownlinkReplaceTopic(parts []string) (deviceID string) {
return parts[3]
}
// Default is the default topic layout.
var Default Layout = &v3{}