@@ -4,37 +4,39 @@ import (
44 "encoding/binary"
55 "errors"
66 "fmt"
7- "github.com/OneOfOne/xxhash"
87 "log"
98 "math"
109 "net"
1110 "strings"
11+
12+ "github.com/OneOfOne/xxhash"
1213)
1314
1415const (
15- PacketSize = 1500
16- NamespaceSize = 64
17- DataValueSize = 1419
16+ PacketSize int = 1500
17+ NamespaceSize int = 64
18+ DataValueSize int = 1419
1819
1920 CmdCount byte = 'C'
2021 CmdPut byte = 'P'
2122 CmdPutReplicate byte = 'R'
2223 CmdCountNamespace byte = 'N'
2324 CmdCountServer byte = 'S'
2425
25- CmdTCPOnlyKeys byte = 'K'
26- CmdTCPOnlyValues byte = 'V'
27- CmdTCPOnlyStore byte = 'T'
28- CmdTCPOnlyRetrieve byte = 'I'
26+ CmdTCPOnlyKeys byte = 'K'
27+ CmdTCPOnlyValues byte = 'V'
28+ CmdTCPOnlyStore byte = 'T'
29+ CmdTCPOnlyRetrieve byte = 'I'
30+ CmdTCPOnlyNamespaces byte = 'L'
2931
3032 // ResError is a Cmd
3133 ResError byte = 'E'
3234
3335 space byte = ' '
34- spaceIndex1 = 1
35- spaceIndex2 = 10
36- spaceIndex3 = 15
37- spaceIndex4 = 80
36+ spaceIndex1 int = 1
37+ spaceIndex2 int = 10
38+ spaceIndex3 int = 15
39+ spaceIndex4 int = 80
3840)
3941
4042var (
@@ -56,7 +58,7 @@ func IsRequestCmd(c byte) bool {
5658}
5759
5860func IsTcpOnlyCmd (c byte ) bool {
59- return c == CmdTCPOnlyKeys || c == CmdTCPOnlyRetrieve || c == CmdTCPOnlyValues || c == CmdTCPOnlyStore
61+ return c == CmdTCPOnlyKeys || c == CmdTCPOnlyRetrieve || c == CmdTCPOnlyValues || c == CmdTCPOnlyStore || c == CmdTCPOnlyNamespaces
6062}
6163
6264// IsResponseCmd indicates if the client should accept this as a command
@@ -106,7 +108,8 @@ func (p *Packet) DataValueString() string {
106108}
107109
108110// ParsePacket parses a packet like:
109- // [Command char][space][xxhash of pre shared key + id + ns + data][space][Message ID uint32][space][Namespace 64 bytes][space][data remaining bytes]
111+ //
112+ // [Command char][space][xxhash of pre shared key + id + ns + data][space][Message ID uint32][space][Namespace 64 bytes][space][data remaining bytes]
110113//
111114// The MTU of 1500 is the maximum allowed packet size. That means the data key can only be 1419
112115// bytes max.
@@ -125,7 +128,7 @@ func ParsePacket(buf []byte) (*Packet, error) {
125128 idBytes := buf [spaceIndex2 + 1 : spaceIndex3 ]
126129 nsBytes := buf [spaceIndex3 + 1 : spaceIndex4 ]
127130 // allows shorter packet to be turned into 1500 byte total packet
128- endAt := int (math .Min (float64 (len (buf )), PacketSize ))
131+ endAt := int (math .Min (float64 (len (buf )), float64 ( PacketSize ) ))
129132 messageIData := buf [spaceIndex4 + 1 : endAt ]
130133 rightSizeData := * PadRight (& messageIData , DataValueSize )
131134 p := Packet {
@@ -173,7 +176,7 @@ func ParsePacket(buf []byte) (*Packet, error) {
173176}
174177
175178// bytes formats the packet for transport. The first 8 bytes are a header.
176- //// The last byte should be a line break. The data is a UTF-8 string.
179+ // // The last byte should be a line break. The data is a UTF-8 string.
177180func (p * Packet ) bytes () []byte {
178181 //fmt.Println("Bytes() message id", p.MessageID, "|")
179182 //fmt.Println("Bytes() Namespace", p.Namespace, "|", len(p.Namespace))
0 commit comments