@@ -22,13 +22,9 @@ JavascriptReplyParser.prototype._parseResult = function (type) {
22
22
23
23
if ( type === 43 || type === 58 || type === 45 ) { // + or : or -
24
24
// up to the delimiter
25
- end = this . _packetEndOffset ( ) - 1 ;
25
+ end = this . _packetEndOffset ( ) ;
26
26
start = this . _offset ;
27
27
28
- if ( end > this . _buffer . length ) {
29
- throw new IncompleteReadBuffer ( 'Wait for more data.' ) ;
30
- }
31
-
32
28
// include the delimiter
33
29
this . _offset = end + 2 ;
34
30
@@ -91,13 +87,15 @@ JavascriptReplyParser.prototype._parseResult = function (type) {
91
87
}
92
88
93
89
return reply ;
90
+ } else {
91
+ return null ;
94
92
}
95
93
} ;
96
94
97
95
JavascriptReplyParser . prototype . execute = function ( buffer ) {
98
96
this . append ( buffer ) ;
99
97
100
- var type , ret , offset ;
98
+ var type , offset ;
101
99
102
100
while ( true ) {
103
101
offset = this . _offset ;
@@ -109,30 +107,16 @@ JavascriptReplyParser.prototype.execute = function (buffer) {
109
107
try {
110
108
type = this . _buffer [ this . _offset ++ ] ;
111
109
112
- if ( type === 43 ) { // Strings +
113
- ret = this . _parseResult ( type ) ;
114
-
115
- this . send_reply ( ret ) ;
110
+ if ( type === 43 || type === 58 || type === 36 ) { // Strings + // Integers : // Bulk strings $
111
+ this . send_reply ( this . _parseResult ( type ) ) ;
116
112
} else if ( type === 45 ) { // Errors -
117
- ret = this . _parseResult ( type ) ;
118
-
119
- this . send_error ( ret ) ;
120
- } else if ( type === 58 ) { // Integers :
121
- ret = this . _parseResult ( type ) ;
122
-
123
- this . send_reply ( ret ) ;
124
- } else if ( type === 36 ) { // Bulk strings $
125
- ret = this . _parseResult ( type ) ;
126
-
127
- this . send_reply ( ret ) ;
113
+ this . send_error ( this . _parseResult ( type ) ) ;
128
114
} else if ( type === 42 ) { // Arrays *
129
115
// set a rewind point. if a failure occurs,
130
116
// wait for the next execute()/append() and try again
131
117
offset = this . _offset - 1 ;
132
118
133
- ret = this . _parseResult ( type ) ;
134
-
135
- this . send_reply ( ret ) ;
119
+ this . send_reply ( this . _parseResult ( type ) ) ;
136
120
} else if ( type === 10 || type === 13 ) {
137
121
break ;
138
122
} else {
@@ -162,7 +146,7 @@ JavascriptReplyParser.prototype.append = function (newBuffer) {
162
146
} ;
163
147
164
148
JavascriptReplyParser . prototype . parseHeader = function ( ) {
165
- var end = this . _packetEndOffset ( ) ,
149
+ var end = this . _packetEndOffset ( ) + 1 ,
166
150
value = this . _buffer . toString ( 'ascii' , this . _offset , end - 1 ) | 0 ;
167
151
168
152
this . _offset = end + 1 ;
@@ -182,7 +166,6 @@ JavascriptReplyParser.prototype._packetEndOffset = function () {
182
166
}
183
167
}
184
168
185
- offset ++ ;
186
169
return offset ;
187
170
} ;
188
171
0 commit comments