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.
This commit is contained in:
Stephen McQuay 2014-03-09 21:53:55 -07:00
parent 67ad90d7a4
commit 240492520e

View File

@ -47,20 +47,20 @@ func (pt *protoTalker) sender() {
log.Printf("%s: spectator sender close", pt.Id) 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{} msg := map[string]Instruction{}
n, err := pt.ws.Read(buff) n, err := pt.ws.Read(pt.buff)
if err != nil { if err != nil {
log.Printf("%s: problem reading from player: %s", pt.Id, err) log.Printf("%s: problem reading from player: %s", pt.Id, err)
return nil, err return nil, err
} }
pt.bw.AddRx <- n pt.bw.AddRx <- n
if n == len(buff) { if n == len(pt.buff) {
errMsg := fmt.Sprintf("%s: read buffer overfull: %s", pt.Id, string(buff)) errMsg := fmt.Sprintf("%s: read buffer overfull: %s", pt.Id, string(pt.buff))
log.Printf(errMsg) log.Printf(errMsg)
return msg, errors.New(errMsg) return msg, errors.New(errMsg)
} }
err = json.Unmarshal(buff[:n], &msg) err = json.Unmarshal(pt.buff[:n], &msg)
if err != nil { if err != nil {
log.Printf("%s: problem reading from player: %s", pt.Id, err) log.Printf("%s: problem reading from player: %s", pt.Id, err)
return nil, err return nil, err
@ -83,7 +83,7 @@ func NewPlayer(id string, ws *websocket.Conn, bw *bandwidth.Bandwidth) *player {
func (p *player) recv() { func (p *player) recv() {
for { for {
msgs, err := p.readJSON(p.buff) msgs, err := p.readJSON()
if err != nil { if err != nil {
log.Printf("%s: %s", p.Id, err) log.Printf("%s: %s", p.Id, err)
break break
@ -164,7 +164,7 @@ func NewSpectator(id string, ws *websocket.Conn, bw *bandwidth.Bandwidth) *Spect
func (s *Spectator) recv() { func (s *Spectator) recv() {
for { for {
_, err := s.readJSON(s.buff) _, err := s.readJSON()
if err != nil { if err != nil {
log.Printf("%s: %s", s.Id, err) log.Printf("%s: %s", s.Id, err)
break break