From 69d2c50dc554f8c637f9d56d9253e22e6a09d728 Mon Sep 17 00:00:00 2001 From: stephen mcquay Date: Wed, 4 Feb 2015 21:41:00 -0800 Subject: [PATCH] Fixed bug where zero value was not being used if you read gob docs it states the following: " If a field has the zero value for its type, it is omitted from the transmission." That's powerful savings. I didn't know. Now it works as one would expect. --- cmd/rclient/main.go | 4 ++-- cmd/rserver/main.go | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/cmd/rclient/main.go b/cmd/rclient/main.go index 71e2596..f46cc31 100644 --- a/cmd/rclient/main.go +++ b/cmd/rclient/main.go @@ -49,8 +49,8 @@ func main() { } point.X, point.Y = x, y - fmt.Printf("sending: %s\n", txt) - err = enc.Encode(&point) + fmt.Printf("sending: %+v\n", point) + err = enc.Encode(point) if err != nil { break } diff --git a/cmd/rserver/main.go b/cmd/rserver/main.go index 31c4b8e..6c7c24e 100644 --- a/cmd/rserver/main.go +++ b/cmd/rserver/main.go @@ -19,7 +19,6 @@ func main() { log.Println("locked and loaded") - point := robo.Point{} for { var err error conn, err := ln.Accept() @@ -30,6 +29,7 @@ func main() { dec := gob.NewDecoder(conn) for { + point := robo.Point{} err = dec.Decode(&point) if err != nil { break @@ -40,6 +40,6 @@ func main() { fmt.Fprintf(os.Stderr, "%v\n", err) } - fmt.Printf("disconnect: %+v\n", conn) + log.Printf("disconnect: %+v\n", conn) } }