forked from sijms/go-ora
-
Notifications
You must be signed in to change notification settings - Fork 0
/
refuse_packet.go
45 lines (41 loc) · 1.01 KB
/
refuse_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
package network
import "encoding/binary"
type RefusePacket struct {
packet Packet
//dataOffset uint16
//Len uint16
//packetType PacketType
//Flag uint8
SystemReason uint8
UserReason uint8
message string
}
func (pck *RefusePacket) bytes() []byte {
output := pck.packet.bytes()
output[8] = pck.SystemReason
output[9] = pck.UserReason
data := []byte(pck.message)
binary.BigEndian.PutUint16(output[10:], uint16(len(data)))
output = append(output, data...)
return output
}
func (pck *RefusePacket) getPacketType() PacketType {
return pck.packet.packetType
}
func newRefusePacketFromData(packetData []byte) *RefusePacket {
if len(packetData) < 12 {
return nil
}
dataLen := binary.BigEndian.Uint16(packetData[10:])
return &RefusePacket{
packet: Packet{
dataOffset: 12,
length: binary.BigEndian.Uint16(packetData),
packetType: PacketType(packetData[4]),
flag: 0,
},
SystemReason: packetData[9],
UserReason: packetData[8],
message: string(packetData[12 : 12+dataLen]),
}
}