Change the recorder to save data in the binary format replay reads
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
package mockserver
|
||||
|
||||
import (
|
||||
"encoding/gob"
|
||||
"encoding/binary"
|
||||
"log"
|
||||
"os"
|
||||
"time"
|
||||
@@ -9,6 +9,9 @@ import (
|
||||
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
|
||||
func Record(address string, port int, filePath string) error {
|
||||
ticker := time.NewTicker(time.Second / 60)
|
||||
@@ -19,6 +22,7 @@ func Record(address string, port int, filePath string) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer bin.Close()
|
||||
|
||||
// Create the BeamNGSDK instance
|
||||
beam, err := bngsdk.Init(address, port)
|
||||
@@ -27,15 +31,17 @@ func Record(address string, port int, filePath string) error {
|
||||
}
|
||||
defer beam.Close()
|
||||
|
||||
enc := gob.NewEncoder(bin)
|
||||
for {
|
||||
err := beam.ReadData()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if err := enc.Encode(beam.Data); err != nil {
|
||||
|
||||
err = binary.Write(bin, binary.LittleEndian, beam.Data)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
<-ticker.C
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user