From 240492520ea77236574197dccf7870b846af6ff2 Mon Sep 17 00:00:00 2001 From: Stephen McQuay Date: Sun, 9 Mar 2014 21:53:55 -0700 Subject: [PATCH] I was passing around a member variable. I just realized that there is no need to pass around a slice to something to which protoTalker already has access. --- player.go | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/player.go b/player.go index ac6e211..97b303d 100644 --- a/player.go +++ b/player.go @@ -47,20 +47,20 @@ func (pt *protoTalker) sender() { log.Printf("%s: spectator sender close", pt.Id) } -func (pt *protoTalker) readJSON(buff []byte) (map[string]Instruction, error) { +func (pt *protoTalker) readJSON() (map[string]Instruction, error) { msg := map[string]Instruction{} - n, err := pt.ws.Read(buff) + n, err := pt.ws.Read(pt.buff) if err != nil { log.Printf("%s: problem reading from player: %s", pt.Id, err) return nil, err } pt.bw.AddRx <- n - if n == len(buff) { - errMsg := fmt.Sprintf("%s: read buffer overfull: %s", pt.Id, string(buff)) + if n == len(pt.buff) { + errMsg := fmt.Sprintf("%s: read buffer overfull: %s", pt.Id, string(pt.buff)) log.Printf(errMsg) return msg, errors.New(errMsg) } - err = json.Unmarshal(buff[:n], &msg) + err = json.Unmarshal(pt.buff[:n], &msg) if err != nil { log.Printf("%s: problem reading from player: %s", pt.Id, err) return nil, err @@ -83,7 +83,7 @@ func NewPlayer(id string, ws *websocket.Conn, bw *bandwidth.Bandwidth) *player { func (p *player) recv() { for { - msgs, err := p.readJSON(p.buff) + msgs, err := p.readJSON() if err != nil { log.Printf("%s: %s", p.Id, err) break @@ -164,7 +164,7 @@ func NewSpectator(id string, ws *websocket.Conn, bw *bandwidth.Bandwidth) *Spect func (s *Spectator) recv() { for { - _, err := s.readJSON(s.buff) + _, err := s.readJSON() if err != nil { log.Printf("%s: %s", s.Id, err) break