From 5344e1384ebfcbb7d138d1982f78db6f6af55bf8 Mon Sep 17 00:00:00 2001 From: Neven Miculinic Date: Sun, 17 Feb 2019 15:42:55 +0100 Subject: [PATCH] Added parser type safety --- server/parser.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/server/parser.go b/server/parser.go index 0b397e5a..d294c9fd 100644 --- a/server/parser.go +++ b/server/parser.go @@ -28,8 +28,9 @@ type pubArg struct { size int } +type parserState int type parseState struct { - state int + state parserState as int drop int pa pubArg @@ -40,7 +41,7 @@ type parseState struct { // Parser constants const ( - OP_START = iota + OP_START parserState = iota OP_PLUS OP_PLUS_O OP_PLUS_OK @@ -205,7 +206,7 @@ func (c *client) parse(buf []byte) error { if err := c.processPub(c.trace, arg); err != nil { return err } - c.drop, c.as, c.state = OP_START, i+1, MSG_PAYLOAD + c.drop, c.as, c.state = 0, i+1, MSG_PAYLOAD // If we don't have a saved buffer then jump ahead with // the index. If this overruns what is left we fall out // and process split buffer.