mirror of
https://github.com/jwetzell/psn-go.git
synced 2026-07-26 10:38:43 +00:00
gofumpt
This commit is contained in:
+5
-3
@@ -1,5 +1,7 @@
|
||||
package psn
|
||||
|
||||
var PACKET_HEADER_SIZE = 16
|
||||
var MAX_UDP_PACKET_SIZE = 1500
|
||||
var CHUNK_HEADER_SIZE = 4
|
||||
const (
|
||||
PACKET_HEADER_SIZE = 16
|
||||
MAX_UDP_PACKET_SIZE = 1500
|
||||
CHUNK_HEADER_SIZE = 4
|
||||
)
|
||||
|
||||
@@ -59,7 +59,6 @@ func (e *Encoder) GetInfoPackets(timestamp uint64, trackers []Tracker) [][]byte
|
||||
}
|
||||
|
||||
func (e *Encoder) GetDataPackets(timestamp uint64, trackers []Tracker) [][]byte {
|
||||
|
||||
trackerChunks := [][]byte{}
|
||||
|
||||
for _, tracker := range trackers {
|
||||
|
||||
@@ -25,7 +25,6 @@ func getNTrackers(n int) []psn.Tracker {
|
||||
}
|
||||
|
||||
func main() {
|
||||
|
||||
testSizes := []int{1, 10, 100, 1000}
|
||||
encoder := psn.Encoder{
|
||||
SystemName: "test encoder",
|
||||
@@ -39,7 +38,6 @@ func main() {
|
||||
benchmark(trackerCount, iterations, encoder, *decoder)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
type BenchmarkResults struct {
|
||||
|
||||
@@ -10,13 +10,17 @@ import (
|
||||
func main() {
|
||||
decoder := psn.NewDecoder()
|
||||
|
||||
infoPacketBytes := []byte{0x56, 0x67, 0x34, 0x80, 0x00, 0x00, 0x0c, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x03, 0x01,
|
||||
infoPacketBytes := []byte{
|
||||
0x56, 0x67, 0x34, 0x80, 0x00, 0x00, 0x0c, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x03, 0x01,
|
||||
0x01, 0x01, 0x00, 0x0b, 0x00, 0x53, 0x65, 0x72, 0x76, 0x65, 0x72, 0x20, 0x4e, 0x61, 0x6d, 0x65, 0x02, 0x00, 0x11,
|
||||
0x80, 0x01, 0x00, 0x0d, 0x80, 0x00, 0x00, 0x09, 0x00, 0x54, 0x72, 0x61, 0x63, 0x6b, 0x65, 0x72, 0x20, 0x31}
|
||||
0x80, 0x01, 0x00, 0x0d, 0x80, 0x00, 0x00, 0x09, 0x00, 0x54, 0x72, 0x61, 0x63, 0x6b, 0x65, 0x72, 0x20, 0x31,
|
||||
}
|
||||
|
||||
dataPacketBytes := []byte{0x55, 0x67, 0x28, 0x80, 0x00, 0x00, 0x0c, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x03, 0x01,
|
||||
dataPacketBytes := []byte{
|
||||
0x55, 0x67, 0x28, 0x80, 0x00, 0x00, 0x0c, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x03, 0x01,
|
||||
0x01, 0x01, 0x00, 0x14, 0x80, 0x01, 0x00, 0x10, 0x80, 0x00, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x80, 0x3f, 0x00, 0x00,
|
||||
0x80, 0x3f, 0x00, 0x00, 0x80, 0x3f}
|
||||
0x80, 0x3f, 0x00, 0x00, 0x80, 0x3f,
|
||||
}
|
||||
|
||||
decoder.Decode(infoPacketBytes)
|
||||
decoder.Decode(dataPacketBytes)
|
||||
|
||||
@@ -7,7 +7,6 @@ import (
|
||||
)
|
||||
|
||||
func main() {
|
||||
|
||||
encoder := psn.Encoder{
|
||||
SystemName: "Server Name",
|
||||
VersionHigh: 2,
|
||||
@@ -41,5 +40,4 @@ func main() {
|
||||
fmt.Printf("%v\n", infoPacket)
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -16,7 +16,6 @@ func main() {
|
||||
}
|
||||
|
||||
client, err := net.ListenMulticastUDP("udp", nil, addr)
|
||||
|
||||
if err != nil {
|
||||
fmt.Printf("Error %v\n", err)
|
||||
return
|
||||
@@ -31,7 +30,6 @@ func main() {
|
||||
buffer := make([]byte, 2048)
|
||||
|
||||
length, _, err := client.ReadFromUDP(buffer)
|
||||
|
||||
if err != nil {
|
||||
fmt.Printf("Error %v", err)
|
||||
}
|
||||
|
||||
@@ -11,7 +11,6 @@ import (
|
||||
|
||||
func main() {
|
||||
client, err := net.Dial("udp", "236.10.10.10:56565")
|
||||
|
||||
if err != nil {
|
||||
fmt.Printf("Error %v\n", err)
|
||||
return
|
||||
@@ -81,5 +80,4 @@ func main() {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -39,5 +39,4 @@ func DecodeChunk(bytes []byte) Chunk {
|
||||
Header: header,
|
||||
ChunkData: chunk_data,
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -7,7 +7,6 @@ import (
|
||||
)
|
||||
|
||||
func TestChunkDecoding(t *testing.T) {
|
||||
|
||||
testCases := []struct {
|
||||
description string
|
||||
bytes []byte
|
||||
@@ -15,34 +14,42 @@ func TestChunkDecoding(t *testing.T) {
|
||||
}{
|
||||
{
|
||||
description: "info packet",
|
||||
bytes: []byte{0x56, 0x67, 0x34, 0x80, 0x00, 0x00, 0x0c, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x03, 0x01,
|
||||
bytes: []byte{
|
||||
0x56, 0x67, 0x34, 0x80, 0x00, 0x00, 0x0c, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x03, 0x01,
|
||||
0x01, 0x01, 0x00, 0x0b, 0x00, 0x53, 0x65, 0x72, 0x76, 0x65, 0x72, 0x20, 0x4e, 0x61, 0x6d, 0x65, 0x02, 0x00, 0x11,
|
||||
0x80, 0x01, 0x00, 0x0d, 0x80, 0x00, 0x00, 0x09, 0x00, 0x54, 0x72, 0x61, 0x63, 0x6b, 0x65, 0x72, 0x20, 0x31},
|
||||
0x80, 0x01, 0x00, 0x0d, 0x80, 0x00, 0x00, 0x09, 0x00, 0x54, 0x72, 0x61, 0x63, 0x6b, 0x65, 0x72, 0x20, 0x31,
|
||||
},
|
||||
expected: Chunk{
|
||||
Header: ChunkHeader{
|
||||
Id: uint16(26454),
|
||||
DataLen: uint16(52),
|
||||
HasSubchunks: true,
|
||||
},
|
||||
ChunkData: []byte{0x00, 0x00, 0x0c, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x03, 0x01,
|
||||
ChunkData: []byte{
|
||||
0x00, 0x00, 0x0c, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x03, 0x01,
|
||||
0x01, 0x01, 0x00, 0x0b, 0x00, 0x53, 0x65, 0x72, 0x76, 0x65, 0x72, 0x20, 0x4e, 0x61, 0x6d, 0x65, 0x02, 0x00, 0x11,
|
||||
0x80, 0x01, 0x00, 0x0d, 0x80, 0x00, 0x00, 0x09, 0x00, 0x54, 0x72, 0x61, 0x63, 0x6b, 0x65, 0x72, 0x20, 0x31},
|
||||
0x80, 0x01, 0x00, 0x0d, 0x80, 0x00, 0x00, 0x09, 0x00, 0x54, 0x72, 0x61, 0x63, 0x6b, 0x65, 0x72, 0x20, 0x31,
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
description: "data packet",
|
||||
bytes: []byte{0x55, 0x67, 0x28, 0x80, 0x00, 0x00, 0x0c, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x03, 0x01,
|
||||
bytes: []byte{
|
||||
0x55, 0x67, 0x28, 0x80, 0x00, 0x00, 0x0c, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x03, 0x01,
|
||||
0x01, 0x01, 0x00, 0x14, 0x80, 0x01, 0x00, 0x10, 0x80, 0x00, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x80, 0x3f, 0x00, 0x00,
|
||||
0x80, 0x3f, 0x00, 0x00, 0x80, 0x3f},
|
||||
0x80, 0x3f, 0x00, 0x00, 0x80, 0x3f,
|
||||
},
|
||||
expected: Chunk{
|
||||
Header: ChunkHeader{
|
||||
Id: uint16(26453),
|
||||
DataLen: uint16(40),
|
||||
HasSubchunks: true,
|
||||
},
|
||||
ChunkData: []byte{0x00, 0x00, 0x0c, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x03, 0x01,
|
||||
ChunkData: []byte{
|
||||
0x00, 0x00, 0x0c, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x03, 0x01,
|
||||
0x01, 0x01, 0x00, 0x14, 0x80, 0x01, 0x00, 0x10, 0x80, 0x00, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x80, 0x3f, 0x00, 0x00,
|
||||
0x80, 0x3f, 0x00, 0x00, 0x80, 0x3f},
|
||||
0x80, 0x3f, 0x00, 0x00, 0x80, 0x3f,
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
@@ -23,7 +23,6 @@ func DecodeDataPacketChunk(bytes []byte) DataPacketChunk {
|
||||
offset := 0
|
||||
|
||||
for offset < int(chunk.Header.DataLen) {
|
||||
|
||||
switch id := binary.LittleEndian.Uint16(chunk.ChunkData[offset : offset+2]); id {
|
||||
case 0:
|
||||
packet_header := DecodePacketHeaderChunk(chunk.ChunkData[offset:])
|
||||
|
||||
@@ -28,7 +28,6 @@ func DecodeDataTrackerChunk(bytes []byte) DataTrackerChunk {
|
||||
offset := 0
|
||||
|
||||
for offset < int(chunk.Header.DataLen) {
|
||||
|
||||
switch id := binary.LittleEndian.Uint16(chunk.ChunkData[offset : offset+2]); id {
|
||||
case 0:
|
||||
pos := DecodeDataTrackerXYZChunk(chunk.ChunkData[offset:])
|
||||
|
||||
@@ -32,5 +32,4 @@ func DecodeDataTrackerListChunk(bytes []byte) DataTrackerListChunk {
|
||||
Chunk: chunk,
|
||||
Data: data,
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -27,5 +27,4 @@ func DecodeDataTrackerStatusChunk(bytes []byte) DataTrackerStatusChunk {
|
||||
Chunk: chunk,
|
||||
Data: data,
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -26,5 +26,4 @@ func DecodeDataTrackerTimestampChunk(bytes []byte) DataTrackerTimestampChunk {
|
||||
Chunk: chunk,
|
||||
Data: data,
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -33,5 +33,4 @@ func DecodeDataTrackerXYZChunk(bytes []byte) DataTrackerXYZChunk {
|
||||
Chunk: chunk,
|
||||
Data: data,
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -24,7 +24,6 @@ func DecodeInfoPacketChunk(bytes []byte) InfoPacketChunk {
|
||||
offset := 0
|
||||
|
||||
for offset < int(chunk.Header.DataLen) {
|
||||
|
||||
switch id := binary.LittleEndian.Uint16(chunk.ChunkData[offset : offset+2]); id {
|
||||
case 0:
|
||||
packet_header := DecodePacketHeaderChunk(chunk.ChunkData[offset:])
|
||||
|
||||
@@ -21,5 +21,4 @@ func DecodeInfoSystemNameChunk(bytes []byte) InfoSystemNameChunk {
|
||||
Chunk: chunk,
|
||||
Data: data,
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -22,7 +22,6 @@ func DecodeInfoTrackerChunk(bytes []byte) InfoTrackerChunk {
|
||||
offset := 0
|
||||
|
||||
for offset < int(chunk.Header.DataLen) {
|
||||
|
||||
switch id := binary.LittleEndian.Uint16(chunk.ChunkData[offset : offset+2]); id {
|
||||
case 0:
|
||||
tracker_name := DecodeInfoTrackerNameChunk(chunk.ChunkData[offset:])
|
||||
|
||||
@@ -33,5 +33,4 @@ func DecodeInfoTrackerListChunk(bytes []byte) InfoTrackerListChunk {
|
||||
Chunk: chunk,
|
||||
Data: data,
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -22,5 +22,4 @@ func DecodeInfoTrackerNameChunk(bytes []byte) InfoTrackerNameChunk {
|
||||
Chunk: chunk,
|
||||
Data: data,
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -36,5 +36,4 @@ func DecodePacketHeaderChunk(bytes []byte) PacketHeaderChunk {
|
||||
Chunk: chunk,
|
||||
Data: data,
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -3,7 +3,6 @@ package encoders
|
||||
import "encoding/binary"
|
||||
|
||||
func EncodeChunk(id uint16, chunkData []byte, hasSubchunks bool) []byte {
|
||||
|
||||
header := []byte{}
|
||||
|
||||
header = binary.LittleEndian.AppendUint16(header, id)
|
||||
|
||||
Reference in New Issue
Block a user