This commit is contained in:
2024-12-19 21:48:46 -06:00
parent a6cfd3db86
commit ea184a936d
22 changed files with 29 additions and 39 deletions
-1
View File
@@ -39,5 +39,4 @@ func DecodeChunk(bytes []byte) Chunk {
Header: header,
ChunkData: chunk_data,
}
}
+16 -9
View File
@@ -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,
},
},
},
}
-1
View File
@@ -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:])
-1
View File
@@ -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,
}
}
-1
View File
@@ -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,
}
}
-1
View File
@@ -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,
}
}
-1
View File
@@ -36,5 +36,4 @@ func DecodePacketHeaderChunk(bytes []byte) PacketHeaderChunk {
Chunk: chunk,
Data: data,
}
}
-1
View File
@@ -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)