Change the recorder to save data in the binary format replay reads
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
package mockserver
|
package mockserver
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/gob"
|
"encoding/binary"
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
"time"
|
"time"
|
||||||
@@ -9,6 +9,9 @@ import (
|
|||||||
bngsdk "github.com/ESilva15/gobngsdk"
|
bngsdk "github.com/ESilva15/gobngsdk"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// NOTE: add some visual feedback of whats happening.
|
||||||
|
// Maybe reuse the replay view function
|
||||||
|
|
||||||
// Record records data from the UDP connection created by address and port
|
// Record records data from the UDP connection created by address and port
|
||||||
func Record(address string, port int, filePath string) error {
|
func Record(address string, port int, filePath string) error {
|
||||||
ticker := time.NewTicker(time.Second / 60)
|
ticker := time.NewTicker(time.Second / 60)
|
||||||
@@ -19,6 +22,7 @@ func Record(address string, port int, filePath string) error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
defer bin.Close()
|
||||||
|
|
||||||
// Create the BeamNGSDK instance
|
// Create the BeamNGSDK instance
|
||||||
beam, err := bngsdk.Init(address, port)
|
beam, err := bngsdk.Init(address, port)
|
||||||
@@ -27,15 +31,17 @@ func Record(address string, port int, filePath string) error {
|
|||||||
}
|
}
|
||||||
defer beam.Close()
|
defer beam.Close()
|
||||||
|
|
||||||
enc := gob.NewEncoder(bin)
|
|
||||||
for {
|
for {
|
||||||
err := beam.ReadData()
|
err := beam.ReadData()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if err := enc.Encode(beam.Data); err != nil {
|
|
||||||
|
err = binary.Write(bin, binary.LittleEndian, beam.Data)
|
||||||
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
<-ticker.C
|
<-ticker.C
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user