MCPcopy
hub / github.com/nats-io/nats.go / parse

Method parse

parser.go:77–418  ·  view source on GitHub ↗

parse is the fast protocol parser engine.

(buf []byte)

Source from the content-addressed store, hash-verified

75
76// parse is the fast protocol parser engine.
77func (nc *Conn) parse(buf []byte) error {
78 var i int
79 var b byte
80
81 // Move to loop instead of range syntax to allow jumping of i
82 for i = 0; i < len(buf); i++ {
83 b = buf[i]
84
85 switch nc.ps.state {
86 case OP_START:
87 switch b {
88 case 'M', 'm':
89 nc.ps.state = OP_M
90 nc.ps.hdr = -1
91 nc.ps.ma.hdr = -1
92 case 'H', 'h':
93 nc.ps.state = OP_H
94 nc.ps.hdr = 0
95 nc.ps.ma.hdr = 0
96 case 'P', 'p':
97 nc.ps.state = OP_P
98 case '+':
99 nc.ps.state = OP_PLUS
100 case '-':
101 nc.ps.state = OP_MINUS
102 case 'I', 'i':
103 nc.ps.state = OP_I
104 default:
105 goto parseErr
106 }
107 case OP_H:
108 switch b {
109 case 'M', 'm':
110 nc.ps.state = OP_M
111 default:
112 goto parseErr
113 }
114 case OP_M:
115 switch b {
116 case 'S', 's':
117 nc.ps.state = OP_MS
118 default:
119 goto parseErr
120 }
121 case OP_MS:
122 switch b {
123 case 'G', 'g':
124 nc.ps.state = OP_MSG
125 default:
126 goto parseErr
127 }
128 case OP_MSG:
129 switch b {
130 case ' ', '\t':
131 nc.ps.state = OP_MSG_SPC
132 default:
133 goto parseErr
134 }

Callers 9

TestParserPingFunction · 0.95
TestParserErrFunction · 0.95
TestParserOKFunction · 0.95
TestParserShouldFailFunction · 0.95
TestParserSplitMsgFunction · 0.95
TestAsyncINFOFunction · 0.95
TestConnServersFunction · 0.95
readLoopMethod · 0.95

Calls 9

processMsgArgsMethod · 0.95
processMsgMethod · 0.95
processOKMethod · 0.95
processErrMethod · 0.95
processPongMethod · 0.95
processPingMethod · 0.95
processAsyncInfoMethod · 0.95
cloneMsgArgMethod · 0.95
ErrorfMethod · 0.80

Tested by 8

TestParserPingFunction · 0.76
TestParserErrFunction · 0.76
TestParserOKFunction · 0.76
TestParserShouldFailFunction · 0.76
TestParserSplitMsgFunction · 0.76
TestAsyncINFOFunction · 0.76
TestConnServersFunction · 0.76