aboutsummaryrefslogtreecommitdiff
path: root/car/elegoo/main.go
diff options
context:
space:
mode:
Diffstat (limited to 'car/elegoo/main.go')
-rw-r--r--car/elegoo/main.go15
1 files changed, 7 insertions, 8 deletions
diff --git a/car/elegoo/main.go b/car/elegoo/main.go
index 6f1d945..a17ac2a 100644
--- a/car/elegoo/main.go
+++ b/car/elegoo/main.go
@@ -11,14 +11,13 @@ import (
func Write(w io.Writer, buf []byte) {
sz := proto.EncodeVarint(uint64(len(buf)))
- w.Write(sz)
- w.Write(buf)
+ w.Write(append(sz, buf...))
}
func Read(r io.Reader) []byte {
- buf := [10]byte{}
- r.Read(buf[:])
- sz, n := proto.DecodeVarint(buf[:])
+ buf := make([]byte, 80)
+ n, _ := r.Read(buf)
+ sz, n := proto.DecodeVarint(buf[:n])
nbuf := make([]byte, int(sz))
@@ -58,13 +57,13 @@ func main() {
if err != nil {
log.Fatal(err)
}
- log.Printf("Send: %v", buf)
- Write(s, buf)
+ log.Printf("Send: %x", buf)
+ //Write(s, buf)
go func() {
for {
buf := Read(s)
- log.Printf("Got: %v", buf)
+ log.Printf("Got: %x", buf)
evt := &Event{}
proto.Unmarshal(buf, evt)
log.Println(evt)