mirror of
https://github.com/jwetzell/psn-go.git
synced 2026-08-23 16:09:14 +00:00
Compare commits
9 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| e0d4b58606 | |||
| 2df4cd56f7 | |||
| 145c13a976 | |||
| e7bdeb46ff | |||
| a79bca637c | |||
| eb8c6aba19 | |||
| 0b20f3ffb9 | |||
| 98a458ca43 | |||
| e3a7268487 |
+7
-8
@@ -6,12 +6,10 @@ import (
|
||||
)
|
||||
|
||||
type Decoder struct {
|
||||
lastInfoPacketHeader *chunks.PacketHeaderChunk
|
||||
lastDataPacketHeader *chunks.PacketHeaderChunk
|
||||
infoPacketFrames map[uint8][]chunks.InfoPacketChunk
|
||||
dataPacketFrames map[uint8][]chunks.DataPacketChunk
|
||||
Trackers map[uint16]*Tracker
|
||||
SystemName string
|
||||
infoPacketFrames map[uint8][]chunks.InfoPacketChunk
|
||||
dataPacketFrames map[uint8][]chunks.DataPacketChunk
|
||||
Trackers map[uint16]*Tracker
|
||||
SystemName string
|
||||
}
|
||||
|
||||
func NewDecoder() *Decoder {
|
||||
@@ -58,7 +56,8 @@ func (d *Decoder) Decode(bytes []byte) error {
|
||||
return err
|
||||
}
|
||||
|
||||
if chunk.Header.Id == 0x6756 {
|
||||
switch chunk.Header.Id {
|
||||
case 0x6756:
|
||||
infoPacket, err := decoders.DecodeInfoPacketChunk(bytes)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -76,7 +75,7 @@ func (d *Decoder) Decode(bytes []byte) error {
|
||||
d.updateInfo(d.infoPacketFrames[currentInfoPacketHeader.Data.FrameId])
|
||||
delete(d.infoPacketFrames, currentInfoPacketHeader.Data.FrameId)
|
||||
}
|
||||
} else if chunk.Header.Id == 0x6755 {
|
||||
case 0x6755:
|
||||
dataPacket, err := decoders.DecodeDataPacketChunk(bytes)
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
+2
-2
@@ -18,7 +18,7 @@ func (e *Encoder) ResetInfoFrameId() {
|
||||
e.infoFrameId = 1
|
||||
}
|
||||
|
||||
func (e *Encoder) GetInfoPackets(timestamp uint64, trackers []Tracker) [][]byte {
|
||||
func (e *Encoder) GetInfoPackets(timestamp uint64, trackers []*Tracker) [][]byte {
|
||||
systemNameChunk := encoders.EncodeInfoSystemNameChunk(e.SystemName)
|
||||
|
||||
trackerChunks := [][]byte{}
|
||||
@@ -58,7 +58,7 @@ func (e *Encoder) GetInfoPackets(timestamp uint64, trackers []Tracker) [][]byte
|
||||
return infoPackets
|
||||
}
|
||||
|
||||
func (e *Encoder) GetDataPackets(timestamp uint64, trackers []Tracker) [][]byte {
|
||||
func (e *Encoder) GetDataPackets(timestamp uint64, trackers []*Tracker) [][]byte {
|
||||
trackerChunks := [][]byte{}
|
||||
|
||||
for _, tracker := range trackers {
|
||||
|
||||
+16
-10
@@ -7,11 +7,11 @@ import (
|
||||
"github.com/jwetzell/psn-go"
|
||||
)
|
||||
|
||||
func getNTrackers(n int) []psn.Tracker {
|
||||
trackers := []psn.Tracker{}
|
||||
func getNTrackers(n int) []*psn.Tracker {
|
||||
trackers := []*psn.Tracker{}
|
||||
|
||||
for index := 0; index < n; index++ {
|
||||
tracker := psn.Tracker{Id: uint16(index), Name: "Tracker"}
|
||||
for index := range n {
|
||||
tracker := &psn.Tracker{Id: uint16(index), Name: "Tracker"}
|
||||
tracker.SetPos(0, 0, 0)
|
||||
tracker.SetSpeed(0, 0, 0)
|
||||
tracker.SetOri(0, 0, 0)
|
||||
@@ -61,31 +61,37 @@ func benchmark(trackerCount int, iterations int, encoder psn.Encoder, decoder ps
|
||||
|
||||
latestEncodedPackets := [][]byte{}
|
||||
|
||||
for index := 0; index < iterations; index++ {
|
||||
for range iterations {
|
||||
latestEncodedPackets = encoder.GetDataPackets(uint64(timestamp), trackers)
|
||||
}
|
||||
benchmarkResults.data.encode = float64(time.Now().UnixMicro()-dataEncoderStart) / 1000.0
|
||||
|
||||
_ = latestEncodedPackets
|
||||
dataDecodedStart := time.Now().UnixMicro()
|
||||
for index := 0; index < iterations; index++ {
|
||||
for range iterations {
|
||||
for _, packet := range latestEncodedPackets {
|
||||
decoder.Decode(packet)
|
||||
err := decoder.Decode(packet)
|
||||
if err != nil {
|
||||
fmt.Printf("failed to decode packet, error: %v\n", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
benchmarkResults.data.decode = float64(time.Now().UnixMicro()-dataDecodedStart) / 1000.0
|
||||
|
||||
// INFO
|
||||
infoEncoderStart := time.Now().UnixMicro()
|
||||
for index := 0; index < iterations; index++ {
|
||||
for range iterations {
|
||||
latestEncodedPackets = encoder.GetInfoPackets(uint64(timestamp), trackers)
|
||||
}
|
||||
benchmarkResults.info.encode = float64(time.Now().UnixMicro()-infoEncoderStart) / 1000.0
|
||||
|
||||
infoDecodeStart := time.Now().UnixMicro()
|
||||
for index := 0; index < iterations; index++ {
|
||||
for range iterations {
|
||||
for _, packet := range latestEncodedPackets {
|
||||
decoder.Decode(packet)
|
||||
err := decoder.Decode(packet)
|
||||
if err != nil {
|
||||
fmt.Printf("failed to decode packet, error: %v\n", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
benchmarkResults.info.decode = float64(time.Now().UnixMicro()-infoDecodeStart) / 1000.0
|
||||
|
||||
@@ -13,14 +13,14 @@ func main() {
|
||||
VersionLow: 3,
|
||||
}
|
||||
|
||||
tracker := psn.Tracker{
|
||||
tracker := &psn.Tracker{
|
||||
Id: 1,
|
||||
Name: "Tracker 1",
|
||||
}
|
||||
|
||||
tracker.SetPos(1.0, 1.0, 1.0)
|
||||
|
||||
trackers := []psn.Tracker{
|
||||
trackers := []*psn.Tracker{
|
||||
tracker,
|
||||
}
|
||||
|
||||
|
||||
+44
-36
@@ -23,62 +23,70 @@ func main() {
|
||||
VersionLow: 0,
|
||||
}
|
||||
|
||||
trackers := []psn.Tracker{}
|
||||
trackers := []*psn.Tracker{}
|
||||
|
||||
trackers = append(trackers, psn.Tracker{Id: 0, Name: "Sun"})
|
||||
trackers = append(trackers, psn.Tracker{Id: 1, Name: "Mercury"})
|
||||
trackers = append(trackers, psn.Tracker{Id: 2, Name: "Venus"})
|
||||
trackers = append(trackers, psn.Tracker{Id: 3, Name: "Earth"})
|
||||
trackers = append(trackers, psn.Tracker{Id: 4, Name: "Mars"})
|
||||
trackers = append(trackers, psn.Tracker{Id: 5, Name: "Jupiter"})
|
||||
trackers = append(trackers, psn.Tracker{Id: 6, Name: "Saturn"})
|
||||
trackers = append(trackers, psn.Tracker{Id: 7, Name: "Uranus"})
|
||||
trackers = append(trackers, psn.Tracker{Id: 8, Name: "Neptune"})
|
||||
trackers = append(trackers, psn.Tracker{Id: 9, Name: "Pluto"})
|
||||
trackers = append(trackers, &psn.Tracker{Id: 0, Name: "Sun"})
|
||||
trackers = append(trackers, &psn.Tracker{Id: 1, Name: "Mercury"})
|
||||
trackers = append(trackers, &psn.Tracker{Id: 2, Name: "Venus"})
|
||||
trackers = append(trackers, &psn.Tracker{Id: 3, Name: "Earth"})
|
||||
trackers = append(trackers, &psn.Tracker{Id: 4, Name: "Mars"})
|
||||
trackers = append(trackers, &psn.Tracker{Id: 5, Name: "Jupiter"})
|
||||
trackers = append(trackers, &psn.Tracker{Id: 6, Name: "Saturn"})
|
||||
trackers = append(trackers, &psn.Tracker{Id: 7, Name: "Uranus"})
|
||||
trackers = append(trackers, &psn.Tracker{Id: 8, Name: "Neptune"})
|
||||
trackers = append(trackers, &psn.Tracker{Id: 9, Name: "Pluto"})
|
||||
|
||||
orbits := []float32{1.0, 88.0, 224.7, 365.2, 687, 4332, 10760, 30700, 60200, 90600}
|
||||
distFromSun := []float32{0, 0.58, 1.08, 1.5, 2.28, 7.78, 14.29, 28.71, 45.04, 59.13}
|
||||
|
||||
timestamp := 0
|
||||
|
||||
lastInfoMillis := time.Now().UnixMilli()
|
||||
lastDataMillis := time.Now().UnixMilli()
|
||||
dataTicker := time.NewTicker(time.Millisecond * 16)
|
||||
infoTicker := time.NewTicker(time.Millisecond * 1000)
|
||||
|
||||
for {
|
||||
if (time.Now().UnixMilli() - lastInfoMillis) > 500 {
|
||||
slog.Info("Sending Info Packets")
|
||||
infoPackets := encoder.GetInfoPackets(uint64(timestamp), trackers)
|
||||
for _, infoPacket := range infoPackets {
|
||||
client.Write(infoPacket)
|
||||
}
|
||||
lastInfoMillis = time.Now().UnixMilli()
|
||||
}
|
||||
|
||||
if (time.Now().UnixMilli() - lastDataMillis) > 5 {
|
||||
for index, orbit := range orbits {
|
||||
go func() {
|
||||
for {
|
||||
for index, tracker := range trackers {
|
||||
orbit := orbits[index]
|
||||
a := 1.0 / orbit
|
||||
b := distFromSun[index]
|
||||
x := timestamp
|
||||
cb := math.Cos(float64(a*float32(x))) * float64(b)
|
||||
sb := math.Sin(float64(a*float32(x))) * float64(b)
|
||||
|
||||
trackers[index].SetPos(float32(sb), 0, float32(cb))
|
||||
trackers[index].SetSpeed(a*float32(cb), 0, -a*float32(sb))
|
||||
trackers[index].SetOri(0, float32(x)/1000.0, 0)
|
||||
trackers[index].SetAccel(-a*a*float32(sb), 0, -a*a*float32(cb))
|
||||
trackers[index].SetTrgtPos(3, 14, 16)
|
||||
trackers[index].SetStatus(float32(index) / 10.0)
|
||||
trackers[index].SetTimestamp(uint64(timestamp))
|
||||
tracker.SetPos(float32(sb), 0, float32(cb))
|
||||
tracker.SetSpeed(a*float32(cb), 0, -a*float32(sb))
|
||||
tracker.SetOri(0, float32(x)/1000.0, 0)
|
||||
tracker.SetAccel(-a*a*float32(sb), 0, -a*a*float32(cb))
|
||||
tracker.SetTrgtPos(3, 14, 16)
|
||||
tracker.SetStatus(float32(index) / 10.0)
|
||||
tracker.SetTimestamp(uint64(timestamp))
|
||||
}
|
||||
time.Sleep(time.Millisecond * 16)
|
||||
}
|
||||
}()
|
||||
|
||||
for {
|
||||
select {
|
||||
case <-infoTicker.C:
|
||||
slog.Info("Sending Info Packets")
|
||||
infoPackets := encoder.GetInfoPackets(uint64(timestamp), trackers)
|
||||
for _, infoPacket := range infoPackets {
|
||||
_, err := client.Write(infoPacket)
|
||||
if err != nil {
|
||||
slog.Error("failed to send info packet", "error", err)
|
||||
}
|
||||
}
|
||||
case <-dataTicker.C:
|
||||
slog.Info("Sending Data Packets")
|
||||
dataPackets := encoder.GetDataPackets(uint64(timestamp), trackers)
|
||||
for _, DataPacket := range dataPackets {
|
||||
client.Write(DataPacket)
|
||||
for _, dataPacket := range dataPackets {
|
||||
_, err := client.Write(dataPacket)
|
||||
if err != nil {
|
||||
slog.Error("failed to send data packet", "error", err)
|
||||
}
|
||||
}
|
||||
lastDataMillis = time.Now().UnixMilli()
|
||||
timestamp += 1
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@ func DecodeChunk(bytes []byte) (chunks.Chunk, error) {
|
||||
|
||||
data_len := lengthAndFlag
|
||||
|
||||
has_subchunks := lengthAndFlag > 32768
|
||||
has_subchunks := lengthAndFlag >= 32768
|
||||
|
||||
if has_subchunks {
|
||||
data_len = data_len - 32768
|
||||
@@ -30,6 +30,10 @@ func DecodeChunk(bytes []byte) (chunks.Chunk, error) {
|
||||
HasSubchunks: has_subchunks,
|
||||
}
|
||||
|
||||
if len(bytes) < 4+int(header.DataLen) {
|
||||
return chunks.Chunk{}, errors.New("chunk data length is greater than the number of bytes")
|
||||
}
|
||||
|
||||
chunk_data := bytes[4 : 4+header.DataLen]
|
||||
|
||||
return chunks.Chunk{
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package decoders
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"reflect"
|
||||
"strings"
|
||||
"testing"
|
||||
@@ -58,19 +57,17 @@ func TestGoodChunkDecoding(t *testing.T) {
|
||||
}
|
||||
|
||||
for _, testCase := range testCases {
|
||||
t.Run(testCase.description, func(t *testing.T) {
|
||||
actual, err := DecodeChunk(testCase.bytes)
|
||||
|
||||
actual, err := DecodeChunk(testCase.bytes)
|
||||
if err != nil {
|
||||
t.Errorf("failed to decode chunk properly, error: %v", err)
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
t.Errorf("Test '%s' failed to decode chunk properly", testCase.description)
|
||||
fmt.Println(err)
|
||||
}
|
||||
|
||||
if !reflect.DeepEqual(actual, testCase.expected) {
|
||||
t.Errorf("Test '%s' failed to decode chunk properly", testCase.description)
|
||||
fmt.Printf("expected: %v\n", testCase.expected)
|
||||
fmt.Printf("actual: %v\n", actual)
|
||||
}
|
||||
if !reflect.DeepEqual(actual, testCase.expected) {
|
||||
t.Errorf("failed to decode chunk properly, expected: %+v, actual: %+v", testCase.expected, actual)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -88,18 +85,53 @@ func TestBadChunkDecoding(t *testing.T) {
|
||||
}
|
||||
|
||||
for _, testCase := range testCases {
|
||||
t.Run(testCase.description, func(t *testing.T) {
|
||||
_, err := DecodeChunk(testCase.bytes)
|
||||
|
||||
_, err := DecodeChunk(testCase.bytes)
|
||||
|
||||
if err == nil {
|
||||
t.Errorf("Test '%s' should have failed fail to decode chunk properly", testCase.description)
|
||||
}
|
||||
|
||||
if !strings.Contains(err.Error(), testCase.errorShouldContain) {
|
||||
t.Errorf("Test '%s' did not return the correct error", testCase.description)
|
||||
fmt.Printf("expected: %v\n", testCase.errorShouldContain)
|
||||
fmt.Printf("actual: %v\n", err.Error())
|
||||
}
|
||||
if err == nil {
|
||||
t.Error("should have failed fail to decode chunk properly")
|
||||
}
|
||||
|
||||
if !strings.Contains(err.Error(), testCase.errorShouldContain) {
|
||||
t.Errorf("did not return the correct error expected: %s, got: %s", testCase.errorShouldContain, err.Error())
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkChunkDecoding(b *testing.B) {
|
||||
data := []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,
|
||||
}
|
||||
for b.Loop() {
|
||||
_, err := DecodeChunk(data)
|
||||
if err != nil {
|
||||
b.Errorf("failed to decode chunk properly, error: %v", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func FuzzChunkDecoding(f *testing.F) {
|
||||
seedCases := [][]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,
|
||||
},
|
||||
{
|
||||
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,
|
||||
},
|
||||
}
|
||||
|
||||
for _, seed := range seedCases {
|
||||
f.Add(seed)
|
||||
}
|
||||
|
||||
f.Fuzz(func(t *testing.T, bytes []byte) {
|
||||
_, _ = DecodeChunk(bytes)
|
||||
})
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package decoders
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
@@ -155,18 +154,16 @@ func TestGoodDataPacketChunkDecoding(t *testing.T) {
|
||||
}
|
||||
|
||||
for _, testCase := range testCases {
|
||||
t.Run(testCase.description, func(t *testing.T) {
|
||||
actual, err := DecodeDataPacketChunk(testCase.bytes)
|
||||
|
||||
actual, err := DecodeDataPacketChunk(testCase.bytes)
|
||||
if err != nil {
|
||||
t.Errorf("failed to decode chunk properly, error: %v", err)
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
t.Errorf("Test '%s' failed to decode chunk properly", testCase.description)
|
||||
fmt.Println(err)
|
||||
}
|
||||
|
||||
if !reflect.DeepEqual(actual, testCase.expected) {
|
||||
t.Errorf("Test '%s' failed to decode chunk properly", testCase.description)
|
||||
fmt.Printf("expected: %+v\n", testCase.expected)
|
||||
fmt.Printf("actual: %+v\n", actual)
|
||||
}
|
||||
if !reflect.DeepEqual(actual, testCase.expected) {
|
||||
t.Errorf("failed to decode chunk properly, expected: %+v, actual: %+v", testCase.expected, actual)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package decoders
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
@@ -111,18 +110,16 @@ func TestGoodDataTrackerChunkDecoding(t *testing.T) {
|
||||
}
|
||||
|
||||
for _, testCase := range testCases {
|
||||
t.Run(testCase.description, func(t *testing.T) {
|
||||
actual, err := DecodeDataTrackerChunk(testCase.bytes)
|
||||
|
||||
actual, err := DecodeDataTrackerChunk(testCase.bytes)
|
||||
if err != nil {
|
||||
t.Errorf("failed to decode chunk properly, error: %v", err)
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
t.Errorf("Test '%s' failed to decode chunk properly", testCase.description)
|
||||
fmt.Println(err)
|
||||
}
|
||||
|
||||
if !reflect.DeepEqual(actual, testCase.expected) {
|
||||
t.Errorf("Test '%s' failed to decode chunk properly", testCase.description)
|
||||
fmt.Printf("expected: %+v\n", testCase.expected)
|
||||
fmt.Printf("actual: %+v\n", actual)
|
||||
}
|
||||
if !reflect.DeepEqual(actual, testCase.expected) {
|
||||
t.Errorf("failed to decode chunk properly, expected: %+v, actual: %+v", testCase.expected, actual)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package decoders
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
@@ -126,18 +125,16 @@ func TestGoodDataTrackerListChunkDecoding(t *testing.T) {
|
||||
}
|
||||
|
||||
for _, testCase := range testCases {
|
||||
t.Run(testCase.description, func(t *testing.T) {
|
||||
actual, err := DecodeDataTrackerListChunk(testCase.bytes)
|
||||
|
||||
actual, err := DecodeDataTrackerListChunk(testCase.bytes)
|
||||
if err != nil {
|
||||
t.Errorf("failed to decode chunk properly, error: %v", err)
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
t.Errorf("Test '%s' failed to decode chunk properly", testCase.description)
|
||||
fmt.Println(err)
|
||||
}
|
||||
|
||||
if !reflect.DeepEqual(actual, testCase.expected) {
|
||||
t.Errorf("Test '%s' failed to decode chunk properly", testCase.description)
|
||||
fmt.Printf("expected: %+v\n", testCase.expected)
|
||||
fmt.Printf("actual: %+v\n", actual)
|
||||
}
|
||||
if !reflect.DeepEqual(actual, testCase.expected) {
|
||||
t.Errorf("failed to decode chunk properly, expected: %+v, actual: %+v", testCase.expected, actual)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package decoders
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
@@ -31,19 +30,17 @@ func TestGoodDataTrackerStatusChunk(t *testing.T) {
|
||||
}
|
||||
|
||||
for _, testCase := range testCases {
|
||||
t.Run(testCase.description, func(t *testing.T) {
|
||||
actual, err := DecodeDataTrackerStatusChunk(testCase.bytes)
|
||||
|
||||
actual, err := DecodeDataTrackerStatusChunk(testCase.bytes)
|
||||
if err != nil {
|
||||
t.Errorf("failed to decode chunk properly, error: %v", err)
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
t.Errorf("Test '%s' failed to decode chunk properly", testCase.description)
|
||||
fmt.Println(err)
|
||||
}
|
||||
|
||||
if !reflect.DeepEqual(actual, testCase.expected) {
|
||||
t.Errorf("Test '%s' failed to decode chunk properly", testCase.description)
|
||||
fmt.Printf("expected: %v\n", testCase.expected)
|
||||
fmt.Printf("actual: %v\n", actual)
|
||||
}
|
||||
if !reflect.DeepEqual(actual, testCase.expected) {
|
||||
t.Errorf("failed to decode chunk properly, expected: %+v, actual: %+v", testCase.expected, actual)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package decoders
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
@@ -32,18 +31,17 @@ func TestGoodDataTrackerTimestampChunk(t *testing.T) {
|
||||
|
||||
for _, testCase := range testCases {
|
||||
|
||||
actual, err := DecodeDataTrackerTimestampChunk(testCase.bytes)
|
||||
t.Run(testCase.description, func(t *testing.T) {
|
||||
actual, err := DecodeDataTrackerTimestampChunk(testCase.bytes)
|
||||
|
||||
if err != nil {
|
||||
t.Errorf("Test '%s' failed to decode chunk properly", testCase.description)
|
||||
fmt.Println(err)
|
||||
}
|
||||
if err != nil {
|
||||
t.Errorf("failed to decode chunk properly, error: %v", err)
|
||||
}
|
||||
|
||||
if !reflect.DeepEqual(actual, testCase.expected) {
|
||||
t.Errorf("Test '%s' failed to decode chunk properly", testCase.description)
|
||||
fmt.Printf("expected: %v\n", testCase.expected)
|
||||
fmt.Printf("actual: %v\n", actual)
|
||||
}
|
||||
if !reflect.DeepEqual(actual, testCase.expected) {
|
||||
t.Errorf("failed to decode chunk properly, expected: %+v, actual: %+v", testCase.expected, actual)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package decoders
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
@@ -93,19 +92,17 @@ func TestGoodDataTrackerXYZChunk(t *testing.T) {
|
||||
}
|
||||
|
||||
for _, testCase := range testCases {
|
||||
t.Run(testCase.description, func(t *testing.T) {
|
||||
actual, err := DecodeDataTrackerXYZChunk(testCase.bytes)
|
||||
|
||||
actual, err := DecodeDataTrackerXYZChunk(testCase.bytes)
|
||||
if err != nil {
|
||||
t.Errorf("failed to decode chunk properly, error: %v", err)
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
t.Errorf("Test '%s' failed to decode chunk properly", testCase.description)
|
||||
fmt.Println(err)
|
||||
}
|
||||
|
||||
if !reflect.DeepEqual(actual, testCase.expected) {
|
||||
t.Errorf("Test '%s' failed to decode chunk properly", testCase.description)
|
||||
fmt.Printf("expected: %v\n", testCase.expected)
|
||||
fmt.Printf("actual: %v\n", actual)
|
||||
}
|
||||
if !reflect.DeepEqual(actual, testCase.expected) {
|
||||
t.Errorf("failed to decode chunk properly, expected: %+v, actual: %+v", testCase.expected, actual)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package decoders
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
@@ -81,21 +80,69 @@ func TestGoodInfoPacketChunkDecoding(t *testing.T) {
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
description: "empty InfoPacketChunk",
|
||||
bytes: []byte{
|
||||
0x56, 0x67, 0x22, 0x80, 0x00, 0x00, 0x0C, 0x00, 0x3D, 0x2C, 0x91, 0xDB, 0x9A, 0x01, 0x00, 0x00, 0x02, 0x00, 0x00,
|
||||
0x01, 0x01, 0x00, 0x0A, 0x00, 0x50, 0x53, 0x4E, 0x20, 0x53, 0x65, 0x72, 0x76, 0x65, 0x72, 0x02, 0x00, 0x00, 0x80,
|
||||
},
|
||||
expected: chunks.InfoPacketChunk{
|
||||
Chunk: chunks.Chunk{
|
||||
ChunkData: []byte{
|
||||
0x00, 0x00, 0x0C, 0x00, 0x3D, 0x2C, 0x91, 0xDB, 0x9A, 0x01, 0x00, 0x00, 0x02, 0x00, 0x00,
|
||||
0x01, 0x01, 0x00, 0x0A, 0x00, 0x50, 0x53, 0x4E, 0x20, 0x53, 0x65, 0x72, 0x76, 0x65, 0x72, 0x02, 0x00, 0x00, 0x80,
|
||||
},
|
||||
Header: chunks.ChunkHeader{DataLen: 34, Id: 26454, HasSubchunks: true},
|
||||
},
|
||||
Data: chunks.InfoPacketChunkData{
|
||||
PacketHeader: &chunks.PacketHeaderChunk{
|
||||
Chunk: chunks.Chunk{
|
||||
ChunkData: []byte{0x3D, 0x2C, 0x91, 0xDB, 0x9A, 0x01, 0x00, 0x00, 0x02, 0x00, 0x00, 0x01},
|
||||
Header: chunks.ChunkHeader{DataLen: 12, Id: 0, HasSubchunks: false},
|
||||
},
|
||||
Data: chunks.PacketHeaderChunkData{
|
||||
PacketTimestamp: 1764620315709,
|
||||
VersionHigh: 2,
|
||||
VersionLow: 0,
|
||||
FrameId: 0,
|
||||
FramePacketCount: 1,
|
||||
},
|
||||
},
|
||||
SystemName: &chunks.InfoSystemNameChunk{
|
||||
Chunk: chunks.Chunk{
|
||||
ChunkData: []byte{80, 83, 78, 32, 83, 101, 114, 118, 101, 114},
|
||||
Header: chunks.ChunkHeader{DataLen: 10, Id: 1, HasSubchunks: false},
|
||||
},
|
||||
Data: chunks.InfoSystemNameChunkData{
|
||||
SystemName: "PSN Server",
|
||||
},
|
||||
},
|
||||
TrackerList: &chunks.InfoTrackerListChunk{
|
||||
Chunk: chunks.Chunk{
|
||||
ChunkData: []byte{},
|
||||
Header: chunks.ChunkHeader{DataLen: 0, Id: 2, HasSubchunks: true},
|
||||
},
|
||||
Data: chunks.InfoTrackerListChunkData{
|
||||
Trackers: []chunks.InfoTrackerChunk{},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
for _, testCase := range testCases {
|
||||
|
||||
actual, err := DecodeInfoPacketChunk(testCase.bytes)
|
||||
t.Run(testCase.description, func(t *testing.T) {
|
||||
actual, err := DecodeInfoPacketChunk(testCase.bytes)
|
||||
|
||||
if err != nil {
|
||||
t.Errorf("Test '%s' failed to decode chunk properly", testCase.description)
|
||||
fmt.Println(err)
|
||||
}
|
||||
if err != nil {
|
||||
t.Errorf("failed to decode chunk properly, error: %v", err)
|
||||
}
|
||||
|
||||
if !reflect.DeepEqual(actual, testCase.expected) {
|
||||
t.Errorf("Test '%s' failed to decode chunk properly", testCase.description)
|
||||
fmt.Printf("expected: %+v\n", testCase.expected)
|
||||
fmt.Printf("actual: %+v\n", actual)
|
||||
}
|
||||
if !reflect.DeepEqual(actual, testCase.expected) {
|
||||
t.Errorf("failed to decode chunk properly, expected: %+v, actual: %+v", testCase.expected, actual)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package decoders
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
@@ -32,18 +31,16 @@ func TestGoodInfoSystemNameChunkDecoding(t *testing.T) {
|
||||
}
|
||||
|
||||
for _, testCase := range testCases {
|
||||
t.Run(testCase.description, func(t *testing.T) {
|
||||
actual, err := DecodeInfoSystemNameChunk(testCase.bytes)
|
||||
|
||||
actual, err := DecodeInfoSystemNameChunk(testCase.bytes)
|
||||
if err != nil {
|
||||
t.Errorf("failed to decode chunk properly, error: %v", err)
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
t.Errorf("Test '%s' failed to decode chunk properly", testCase.description)
|
||||
fmt.Println(err)
|
||||
}
|
||||
|
||||
if !reflect.DeepEqual(actual, testCase.expected) {
|
||||
t.Errorf("Test '%s' failed to decode chunk properly", testCase.description)
|
||||
fmt.Printf("expected: %+v\n", testCase.expected)
|
||||
fmt.Printf("actual: %+v\n", actual)
|
||||
}
|
||||
if !reflect.DeepEqual(actual, testCase.expected) {
|
||||
t.Errorf("failed to decode chunk properly, expected: %+v, actual: %+v", testCase.expected, actual)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package decoders
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
@@ -40,18 +39,16 @@ func TestGoodInfoTrackerChunkDecoding(t *testing.T) {
|
||||
}
|
||||
|
||||
for _, testCase := range testCases {
|
||||
t.Run(testCase.description, func(t *testing.T) {
|
||||
actual, err := DecodeInfoTrackerChunk(testCase.bytes)
|
||||
|
||||
actual, err := DecodeInfoTrackerChunk(testCase.bytes)
|
||||
if err != nil {
|
||||
t.Errorf("failed to decode chunk properly, error: %v", err)
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
t.Errorf("Test '%s' failed to decode chunk properly", testCase.description)
|
||||
fmt.Println(err)
|
||||
}
|
||||
|
||||
if !reflect.DeepEqual(actual, testCase.expected) {
|
||||
t.Errorf("Test '%s' failed to decode chunk properly", testCase.description)
|
||||
fmt.Printf("expected: %+v\n", testCase.expected)
|
||||
fmt.Printf("actual: %+v\n", actual)
|
||||
}
|
||||
if !reflect.DeepEqual(actual, testCase.expected) {
|
||||
t.Errorf("failed to decode chunk properly, expected: %+v, actual: %+v", testCase.expected, actual)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package decoders
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
@@ -50,18 +49,16 @@ func TestGoodInfoTrackerListChunkDecoding(t *testing.T) {
|
||||
}
|
||||
|
||||
for _, testCase := range testCases {
|
||||
t.Run(testCase.description, func(t *testing.T) {
|
||||
actual, err := DecodeInfoTrackerListChunk(testCase.bytes)
|
||||
|
||||
actual, err := DecodeInfoTrackerListChunk(testCase.bytes)
|
||||
if err != nil {
|
||||
t.Errorf("failed to decode chunk properly, error: %v", err)
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
t.Errorf("Test '%s' failed to decode chunk properly", testCase.description)
|
||||
fmt.Println(err)
|
||||
}
|
||||
|
||||
if !reflect.DeepEqual(actual, testCase.expected) {
|
||||
t.Errorf("Test '%s' failed to decode chunk properly", testCase.description)
|
||||
fmt.Printf("expected: %+v\n", testCase.expected)
|
||||
fmt.Printf("actual: %+v\n", actual)
|
||||
}
|
||||
if !reflect.DeepEqual(actual, testCase.expected) {
|
||||
t.Errorf("failed to decode chunk properly, expected: %+v, actual: %+v", testCase.expected, actual)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package decoders
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
@@ -33,17 +32,16 @@ func TestGoodInfoTrackerNameChunkDecoding(t *testing.T) {
|
||||
|
||||
for _, testCase := range testCases {
|
||||
|
||||
actual, err := DecodeInfoTrackerNameChunk(testCase.bytes)
|
||||
t.Run(testCase.description, func(t *testing.T) {
|
||||
actual, err := DecodeInfoTrackerNameChunk(testCase.bytes)
|
||||
|
||||
if err != nil {
|
||||
t.Errorf("Test '%s' failed to decode chunk properly", testCase.description)
|
||||
fmt.Println(err)
|
||||
}
|
||||
if err != nil {
|
||||
t.Errorf("failed to decode chunk properly, error: %v", err)
|
||||
}
|
||||
|
||||
if !reflect.DeepEqual(actual, testCase.expected) {
|
||||
t.Errorf("Test '%s' failed to decode chunk properly", testCase.description)
|
||||
fmt.Printf("expected: %+v\n", testCase.expected)
|
||||
fmt.Printf("actual: %+v\n", actual)
|
||||
}
|
||||
if !reflect.DeepEqual(actual, testCase.expected) {
|
||||
t.Errorf("failed to decode chunk properly, expected: %+v, actual: %+v", testCase.expected, actual)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package decoders
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
@@ -36,18 +35,16 @@ func TestGoodPacketHeaderChunkDecoding(t *testing.T) {
|
||||
}
|
||||
|
||||
for _, testCase := range testCases {
|
||||
t.Run(testCase.description, func(t *testing.T) {
|
||||
actual, err := DecodePacketHeaderChunk(testCase.bytes)
|
||||
|
||||
actual, err := DecodePacketHeaderChunk(testCase.bytes)
|
||||
if err != nil {
|
||||
t.Errorf("failed to decode chunk properly, error: %v", err)
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
t.Errorf("Test '%s' failed to decode chunk properly", testCase.description)
|
||||
fmt.Println(err)
|
||||
}
|
||||
|
||||
if !reflect.DeepEqual(actual, testCase.expected) {
|
||||
t.Errorf("Test '%s' failed to decode chunk properly", testCase.description)
|
||||
fmt.Printf("expected: %+v\n", testCase.expected)
|
||||
fmt.Printf("actual: %+v\n", actual)
|
||||
}
|
||||
if !reflect.DeepEqual(actual, testCase.expected) {
|
||||
t.Errorf("failed to decode chunk properly, expected: %+v, actual: %+v", testCase.expected, actual)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
go test fuzz v1
|
||||
[]byte("0000")
|
||||
@@ -1,7 +1,6 @@
|
||||
package encoders
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
@@ -57,13 +56,30 @@ func TestChunkEncoding(t *testing.T) {
|
||||
}
|
||||
|
||||
for _, testCase := range testCases {
|
||||
t.Run(testCase.description, func(t *testing.T) {
|
||||
actual := EncodeChunk(testCase.chunk.Header.Id, testCase.chunk.ChunkData, testCase.chunk.Header.HasSubchunks)
|
||||
|
||||
actual := EncodeChunk(testCase.chunk.Header.Id, testCase.chunk.ChunkData, testCase.chunk.Header.HasSubchunks)
|
||||
|
||||
if !reflect.DeepEqual(actual, testCase.expected) {
|
||||
t.Errorf("Test '%s' failed to encode chunk properly", testCase.description)
|
||||
fmt.Printf("expected: %v\n", testCase.expected)
|
||||
fmt.Printf("actual: %v\n", actual)
|
||||
}
|
||||
if !reflect.DeepEqual(actual, testCase.expected) {
|
||||
t.Errorf("failed to encode chunk properly, expected: %v, actual: %v\n", testCase.expected, actual)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkChunkEncoding(b *testing.B) {
|
||||
chunk := chunks.Chunk{
|
||||
Header: chunks.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,
|
||||
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,
|
||||
},
|
||||
}
|
||||
for b.Loop() {
|
||||
EncodeChunk(chunk.Header.Id, chunk.ChunkData, chunk.Header.HasSubchunks)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package encoders
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
@@ -28,13 +27,12 @@ func TestDataTrackerAccelChunkEncoding(t *testing.T) {
|
||||
}
|
||||
|
||||
for _, testCase := range testCases {
|
||||
t.Run(testCase.description, func(t *testing.T) {
|
||||
actual := EncodeDataTrackerAccelChunk(testCase.data.X, testCase.data.Y, testCase.data.Z)
|
||||
|
||||
actual := EncodeDataTrackerAccelChunk(testCase.data.X, testCase.data.Y, testCase.data.Z)
|
||||
|
||||
if !reflect.DeepEqual(actual, testCase.expected) {
|
||||
t.Errorf("Test '%s' failed to encode chunk properly", testCase.description)
|
||||
fmt.Printf("expected: %v\n", testCase.expected)
|
||||
fmt.Printf("actual: %v\n", actual)
|
||||
}
|
||||
if !reflect.DeepEqual(actual, testCase.expected) {
|
||||
t.Errorf("failed to encode chunk properly, expected: %v, actual: %v\n", testCase.expected, actual)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package encoders
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
@@ -28,13 +27,12 @@ func TestDataTrackerOriChunkEncoding(t *testing.T) {
|
||||
}
|
||||
|
||||
for _, testCase := range testCases {
|
||||
t.Run(testCase.description, func(t *testing.T) {
|
||||
actual := EncodeDataTrackerOriChunk(testCase.data.X, testCase.data.Y, testCase.data.Z)
|
||||
|
||||
actual := EncodeDataTrackerOriChunk(testCase.data.X, testCase.data.Y, testCase.data.Z)
|
||||
|
||||
if !reflect.DeepEqual(actual, testCase.expected) {
|
||||
t.Errorf("Test '%s' failed to encode chunk properly", testCase.description)
|
||||
fmt.Printf("expected: %v\n", testCase.expected)
|
||||
fmt.Printf("actual: %v\n", actual)
|
||||
}
|
||||
if !reflect.DeepEqual(actual, testCase.expected) {
|
||||
t.Errorf("failed to encode chunk properly, expected: %v, actual: %v\n", testCase.expected, actual)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package encoders
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
@@ -28,13 +27,12 @@ func TestDataTrackerPosChunkEncoding(t *testing.T) {
|
||||
}
|
||||
|
||||
for _, testCase := range testCases {
|
||||
t.Run(testCase.description, func(t *testing.T) {
|
||||
actual := EncodeDataTrackerPosChunk(testCase.data.X, testCase.data.Y, testCase.data.Z)
|
||||
|
||||
actual := EncodeDataTrackerPosChunk(testCase.data.X, testCase.data.Y, testCase.data.Z)
|
||||
|
||||
if !reflect.DeepEqual(actual, testCase.expected) {
|
||||
t.Errorf("Test '%s' failed to encode chunk properly", testCase.description)
|
||||
fmt.Printf("expected: %v\n", testCase.expected)
|
||||
fmt.Printf("actual: %v\n", actual)
|
||||
}
|
||||
if !reflect.DeepEqual(actual, testCase.expected) {
|
||||
t.Errorf("failed to encode chunk properly, expected: %v, actual: %v\n", testCase.expected, actual)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package encoders
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
@@ -28,13 +27,12 @@ func TestDataTrackerSpeedChunkEncoding(t *testing.T) {
|
||||
}
|
||||
|
||||
for _, testCase := range testCases {
|
||||
t.Run(testCase.description, func(t *testing.T) {
|
||||
actual := EncodeDataTrackerSpeedChunk(testCase.data.X, testCase.data.Y, testCase.data.Z)
|
||||
|
||||
actual := EncodeDataTrackerSpeedChunk(testCase.data.X, testCase.data.Y, testCase.data.Z)
|
||||
|
||||
if !reflect.DeepEqual(actual, testCase.expected) {
|
||||
t.Errorf("Test '%s' failed to encode chunk properly", testCase.description)
|
||||
fmt.Printf("expected: %v\n", testCase.expected)
|
||||
fmt.Printf("actual: %v\n", actual)
|
||||
}
|
||||
if !reflect.DeepEqual(actual, testCase.expected) {
|
||||
t.Errorf("failed to encode chunk properly, expected: %v, actual: %v\n", testCase.expected, actual)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package encoders
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
@@ -26,13 +25,12 @@ func TestDataTrackerStatusChunkEncoding(t *testing.T) {
|
||||
}
|
||||
|
||||
for _, testCase := range testCases {
|
||||
t.Run(testCase.description, func(t *testing.T) {
|
||||
actual := EncodeDataTrackerStatusChunk(testCase.data.Validity)
|
||||
|
||||
actual := EncodeDataTrackerStatusChunk(testCase.data.Validity)
|
||||
|
||||
if !reflect.DeepEqual(actual, testCase.expected) {
|
||||
t.Errorf("Test '%s' failed to encode chunk properly", testCase.description)
|
||||
fmt.Printf("expected: %v\n", testCase.expected)
|
||||
fmt.Printf("actual: %v\n", actual)
|
||||
}
|
||||
if !reflect.DeepEqual(actual, testCase.expected) {
|
||||
t.Errorf("failed to encode chunk properly, expected: %v, actual: %v\n", testCase.expected, actual)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package encoders
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
@@ -26,13 +25,12 @@ func TestDataTrackerTimestampChunkEncoding(t *testing.T) {
|
||||
}
|
||||
|
||||
for _, testCase := range testCases {
|
||||
t.Run(testCase.description, func(t *testing.T) {
|
||||
actual := EncodeDataTrackerTimestampChunk(testCase.data.Timestamp)
|
||||
|
||||
actual := EncodeDataTrackerTimestampChunk(testCase.data.Timestamp)
|
||||
|
||||
if !reflect.DeepEqual(actual, testCase.expected) {
|
||||
t.Errorf("Test '%s' failed to encode chunk properly", testCase.description)
|
||||
fmt.Printf("expected: %v\n", testCase.expected)
|
||||
fmt.Printf("actual: %v\n", actual)
|
||||
}
|
||||
if !reflect.DeepEqual(actual, testCase.expected) {
|
||||
t.Errorf("failed to encode chunk properly, expected: %v, actual: %v\n", testCase.expected, actual)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package encoders
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
@@ -28,13 +27,13 @@ func TestDataTrackerTrgtPosChunkEncoding(t *testing.T) {
|
||||
}
|
||||
|
||||
for _, testCase := range testCases {
|
||||
t.Run(testCase.description, func(t *testing.T) {
|
||||
|
||||
actual := EncodeDataTrackerTrgtPosChunk(testCase.data.X, testCase.data.Y, testCase.data.Z)
|
||||
actual := EncodeDataTrackerTrgtPosChunk(testCase.data.X, testCase.data.Y, testCase.data.Z)
|
||||
|
||||
if !reflect.DeepEqual(actual, testCase.expected) {
|
||||
t.Errorf("Test '%s' failed to encode chunk properly", testCase.description)
|
||||
fmt.Printf("expected: %v\n", testCase.expected)
|
||||
fmt.Printf("actual: %v\n", actual)
|
||||
}
|
||||
if !reflect.DeepEqual(actual, testCase.expected) {
|
||||
t.Errorf("failed to encode chunk properly, expected: %v, actual: %v\n", testCase.expected, actual)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package encoders
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
@@ -26,13 +25,12 @@ func TestInfoSystemNameChunkEncoding(t *testing.T) {
|
||||
}
|
||||
|
||||
for _, testCase := range testCases {
|
||||
t.Run(testCase.description, func(t *testing.T) {
|
||||
actual := EncodeInfoSystemNameChunk(testCase.data.SystemName)
|
||||
|
||||
actual := EncodeInfoSystemNameChunk(testCase.data.SystemName)
|
||||
|
||||
if !reflect.DeepEqual(actual, testCase.expected) {
|
||||
t.Errorf("Test '%s' failed to encode chunk properly", testCase.description)
|
||||
fmt.Printf("expected: %v\n", testCase.expected)
|
||||
fmt.Printf("actual: %v\n", actual)
|
||||
}
|
||||
if !reflect.DeepEqual(actual, testCase.expected) {
|
||||
t.Errorf("failed to encode chunk properly, expected: %v, actual: %v\n", testCase.expected, actual)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package encoders
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
@@ -40,13 +39,12 @@ func TestInfoTrackerChunkEncoding(t *testing.T) {
|
||||
}
|
||||
|
||||
for _, testCase := range testCases {
|
||||
t.Run(testCase.description, func(t *testing.T) {
|
||||
actual := EncodeInfoTrackerChunk(testCase.chunk.Chunk.Header.Id, EncodeInfoTrackerNameChunk(testCase.chunk.Data.TrackerName.Data.TrackerName))
|
||||
|
||||
actual := EncodeInfoTrackerChunk(testCase.chunk.Chunk.Header.Id, EncodeInfoTrackerNameChunk(testCase.chunk.Data.TrackerName.Data.TrackerName))
|
||||
|
||||
if !reflect.DeepEqual(actual, testCase.expected) {
|
||||
t.Errorf("Test '%s' failed to encode chunk properly", testCase.description)
|
||||
fmt.Printf("expected: %v\n", testCase.expected)
|
||||
fmt.Printf("actual: %v\n", actual)
|
||||
}
|
||||
if !reflect.DeepEqual(actual, testCase.expected) {
|
||||
t.Errorf("failed to encode chunk properly, expected: %v, actual: %v\n", testCase.expected, actual)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package encoders
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
@@ -50,18 +49,17 @@ func TestInfoTrackerListChunkEncoding(t *testing.T) {
|
||||
}
|
||||
|
||||
for _, testCase := range testCases {
|
||||
t.Run(testCase.description, func(t *testing.T) {
|
||||
trackerChunks := [][]byte{}
|
||||
for _, tracker := range testCase.chunk.Data.Trackers {
|
||||
trackerChunks = append(trackerChunks, EncodeInfoTrackerChunk(tracker.Chunk.Header.Id, EncodeInfoTrackerNameChunk(tracker.Data.TrackerName.Data.TrackerName)))
|
||||
}
|
||||
|
||||
trackerChunks := [][]byte{}
|
||||
for _, tracker := range testCase.chunk.Data.Trackers {
|
||||
trackerChunks = append(trackerChunks, EncodeInfoTrackerChunk(tracker.Chunk.Header.Id, EncodeInfoTrackerNameChunk(tracker.Data.TrackerName.Data.TrackerName)))
|
||||
}
|
||||
actual := EncodeInfoTrackerListChunk(trackerChunks)
|
||||
|
||||
actual := EncodeInfoTrackerListChunk(trackerChunks)
|
||||
|
||||
if !reflect.DeepEqual(actual, testCase.expected) {
|
||||
t.Errorf("Test '%s' failed to encode chunk properly", testCase.description)
|
||||
fmt.Printf("expected: %v\n", testCase.expected)
|
||||
fmt.Printf("actual: %v\n", actual)
|
||||
}
|
||||
if !reflect.DeepEqual(actual, testCase.expected) {
|
||||
t.Errorf("failed to encode chunk properly, expected: %v, actual: %v\n", testCase.expected, actual)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package encoders
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
@@ -26,13 +25,12 @@ func TestInfoTrackerNameChunkEncoding(t *testing.T) {
|
||||
}
|
||||
|
||||
for _, testCase := range testCases {
|
||||
t.Run(testCase.description, func(t *testing.T) {
|
||||
actual := EncodeInfoTrackerNameChunk(testCase.data.TrackerName)
|
||||
|
||||
actual := EncodeInfoTrackerNameChunk(testCase.data.TrackerName)
|
||||
|
||||
if !reflect.DeepEqual(actual, testCase.expected) {
|
||||
t.Errorf("Test '%s' failed to encode chunk properly", testCase.description)
|
||||
fmt.Printf("expected: %v\n", testCase.expected)
|
||||
fmt.Printf("actual: %v\n", actual)
|
||||
}
|
||||
if !reflect.DeepEqual(actual, testCase.expected) {
|
||||
t.Errorf("failed to encode chunk properly, expected: %v, actual: %v\n", testCase.expected, actual)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package encoders
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
@@ -30,13 +29,12 @@ func TestPacketHeaderChunkEncoding(t *testing.T) {
|
||||
}
|
||||
|
||||
for _, testCase := range testCases {
|
||||
t.Run(testCase.description, func(t *testing.T) {
|
||||
actual := EncodePacketHeaderChunk(testCase.data.PacketTimestamp, testCase.data.VersionHigh, testCase.data.VersionLow, testCase.data.FrameId, testCase.data.FramePacketCount)
|
||||
|
||||
actual := EncodePacketHeaderChunk(testCase.data.PacketTimestamp, testCase.data.VersionHigh, testCase.data.VersionLow, testCase.data.FrameId, testCase.data.FramePacketCount)
|
||||
|
||||
if !reflect.DeepEqual(actual, testCase.expected) {
|
||||
t.Errorf("Test '%s' failed to encode chunk properly", testCase.description)
|
||||
fmt.Printf("expected: %v\n", testCase.expected)
|
||||
fmt.Printf("actual: %v\n", actual)
|
||||
}
|
||||
if !reflect.DeepEqual(actual, testCase.expected) {
|
||||
t.Errorf("failed to encode chunk properly, expected: %v, actual: %v\n", testCase.expected, actual)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user