| 2274 | } |
| 2275 | |
| 2276 | func (r *natsReader) ReadString(delim byte) (string, error) { |
| 2277 | var s string |
| 2278 | build_string: |
| 2279 | // First look if we have something in the buffer |
| 2280 | if r.off >= 0 { |
| 2281 | i := bytes.IndexByte(r.buf[r.off:r.n], delim) |
| 2282 | if i >= 0 { |
| 2283 | end := r.off + i + 1 |
| 2284 | s += string(r.buf[r.off:end]) |
| 2285 | r.off = end |
| 2286 | if r.off >= r.n { |
| 2287 | r.off = -1 |
| 2288 | } |
| 2289 | return s, nil |
| 2290 | } |
| 2291 | // We did not find the delim, so will have to read more. |
| 2292 | s += string(r.buf[r.off:r.n]) |
| 2293 | r.off = -1 |
| 2294 | } |
| 2295 | if _, err := r.Read(); err != nil { |
| 2296 | return s, err |
| 2297 | } |
| 2298 | r.off = 0 |
| 2299 | goto build_string |
| 2300 | } |
| 2301 | |
| 2302 | // createConn will connect to the server and wrap the appropriate |
| 2303 | // bufio structures. It will do the right thing when an existing |