-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpacket.go
49 lines (40 loc) · 988 Bytes
/
packet.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
package ade_linter
import (
"fmt"
"strconv"
)
func checkPackets(table Table, logger Logger) bool {
packets := getPackets(table[1:], logger)
return CheckAll(packets)
}
func getPackets(table Table, logger Logger) []Test {
return Map(table, func(item []string) Test {
packetLogger := logger.AddEntry("Packet", item[1])
return Test(Packet(Packet{
cells: item,
logger: packetLogger,
}))
})
}
type Packet struct {
cells []string
logger Logger
}
func (packet Packet) Run() bool {
if !CheckId(packet.cells[0]) {
packet.logger.Error(fmt.Errorf("packet id is not valid: %s", packet.cells[0]))
return false
}
if !CheckPacketType(packet.cells[2]) {
packet.logger.Error(fmt.Errorf("packet type invalid: %s", packet.cells[2]))
return false
}
return true
}
func CheckId(id string) bool {
_, err := strconv.ParseUint(id, 10, 16)
return err == nil
}
func CheckPacketType(kind string) bool {
return kind == "data" || kind == "order" || kind == "stateOrder"
}