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
1 changed files with 7 additions and 7 deletions

View File

@ -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