Added uncertainty circle and zipping
This commit is contained in:
Binary file not shown.
+3
-4
@@ -7,7 +7,6 @@ package main
|
||||
|
||||
import (
|
||||
"encoding/gob"
|
||||
"encoding/json"
|
||||
"flag"
|
||||
"fmt"
|
||||
"math"
|
||||
@@ -188,7 +187,7 @@ func backoffFor(retry int) time.Duration {
|
||||
|
||||
// FUNCTION TO SEND THE COLLECTED DATA POINTS TO THE SERVER 🖥🖥🖥🖥🖥🖥🖥🖥🖥🖥🖥🖥🖥🖥🖥🖥🖥🖥🖥🖥🖥🖥
|
||||
//
|
||||
// The payload is JSON, gob-encoded as an opaque []byte. sendBuffer is left
|
||||
// The payload is a ZIP of JSON, gob-encoded as an opaque []byte. sendBuffer is left
|
||||
// untouched on failure so the caller can retry the same points; the caller
|
||||
// clears them once we return without error.
|
||||
func sendToServer(targAddr, targPort string, sendBuffer *[]datapoint.DataPoint, errorChan chan error, retry int) {
|
||||
@@ -209,10 +208,10 @@ func sendToServer(targAddr, targPort string, sendBuffer *[]datapoint.DataPoint,
|
||||
defer con.Close()
|
||||
con.SetWriteDeadline(time.Now().Add(10 * time.Second))
|
||||
|
||||
str, err := json.Marshal(sendBuffer)
|
||||
str, err := datapoint.ZipBatch(*sendBuffer)
|
||||
if err != nil {
|
||||
// Bad data, not a bad connection: retrying will not help.
|
||||
errorChan <- fmt.Errorf("marshal batch: %w", err)
|
||||
errorChan <- fmt.Errorf("zip batch: %w", err)
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
@@ -2,7 +2,6 @@ package main
|
||||
|
||||
import (
|
||||
"encoding/gob"
|
||||
"encoding/json"
|
||||
"net"
|
||||
"testing"
|
||||
"time"
|
||||
@@ -51,7 +50,7 @@ func TestSolidifyData(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// Fake server: gob-decode []byte then JSON-decode, exactly as a real receiver would.
|
||||
// Fake server: gob-decode []byte then unzip JSON, as the real receiver does.
|
||||
func TestSendLoopEndToEnd(t *testing.T) {
|
||||
ln, err := net.Listen("tcp", "127.0.0.1:0")
|
||||
if err != nil {
|
||||
@@ -77,8 +76,8 @@ func TestSendLoopEndToEnd(t *testing.T) {
|
||||
con.Close()
|
||||
continue
|
||||
}
|
||||
var pts []datapoint.DataPoint
|
||||
if err := json.Unmarshal(raw, &pts); err != nil {
|
||||
pts, err := datapoint.UnzipBatch(raw)
|
||||
if err != nil {
|
||||
got <- batch{err: err}
|
||||
con.Close()
|
||||
continue
|
||||
|
||||
Reference in New Issue
Block a user