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