switch from single point to Event
This commit is contained in:
+5
-21
@@ -3,12 +3,11 @@ package main
|
||||
import (
|
||||
"bufio"
|
||||
"encoding/gob"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"log"
|
||||
"net"
|
||||
"os"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"mcquay.me/robo"
|
||||
)
|
||||
@@ -22,7 +21,6 @@ func main() {
|
||||
}
|
||||
|
||||
var err error
|
||||
var x, y float64
|
||||
conn, err := net.Dial("tcp", fmt.Sprintf("%s:%d", os.Args[1], robo.Port))
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "%v\n", err)
|
||||
@@ -32,26 +30,12 @@ func main() {
|
||||
enc := gob.NewEncoder(conn)
|
||||
|
||||
s := bufio.NewScanner(os.Stdin)
|
||||
point := robo.Point{}
|
||||
e := robo.Event{}
|
||||
for s.Scan() {
|
||||
txt := s.Text()
|
||||
parts := strings.Split(txt, ",")
|
||||
if len(parts) != 2 {
|
||||
err = fmt.Errorf("bad parse from stdin: %q", txt)
|
||||
break
|
||||
}
|
||||
x, err = strconv.ParseFloat(parts[0], 32)
|
||||
if err != nil {
|
||||
break
|
||||
}
|
||||
y, err = strconv.ParseFloat(parts[1], 32)
|
||||
if err != nil {
|
||||
break
|
||||
}
|
||||
point.X, point.Y = x, y
|
||||
json.Unmarshal(s.Bytes(), &e)
|
||||
|
||||
log.Printf("sending: %+v\n", point)
|
||||
err = enc.Encode(point)
|
||||
log.Printf("sending: %+v\n", e)
|
||||
err = enc.Encode(e)
|
||||
if err != nil {
|
||||
break
|
||||
}
|
||||
|
||||
+1
-1
@@ -29,7 +29,7 @@ func main() {
|
||||
|
||||
dec := gob.NewDecoder(conn)
|
||||
for {
|
||||
point := robo.Point{}
|
||||
point := robo.Event{}
|
||||
err = dec.Decode(&point)
|
||||
if err != nil {
|
||||
break
|
||||
|
||||
Reference in New Issue
Block a user