X-Git-Url: http://www.git.cypherpunks.ru/?p=netstring.git;a=blobdiff_plain;f=r.go;fp=r.go;h=68a93ca4985d19ad81966c4f9327f350d7c24452;hp=7a6d28452521f0f03eb5a09822ab1e8c8b69092a;hb=3a61c7072642334ab9aa738230063811cba8db25;hpb=5f0a9472b5bf641e0fcaddd86b7f1e87a44ed739 diff --git a/r.go b/r.go index 7a6d284..68a93ca 100644 --- a/r.go +++ b/r.go @@ -19,7 +19,6 @@ package netstring import ( "bufio" - "bytes" "errors" "io" "strconv" @@ -44,19 +43,12 @@ func (r *Reader) Next() (uint64, error) { if !r.eof { return 0, errors.New("current chunk is unread") } - p, _ := r.r.Peek(21) - if len(p) == 0 { - return 0, io.EOF - } - idx := bytes.IndexByte(p, ':') - if idx == -1 { - return 0, errors.New("no length separator found") - } - size, err := strconv.ParseUint(string(p[:idx]), 10, 64) + lenRaw, err := r.r.ReadSlice(':') if err != nil { return 0, err } - if _, err = r.r.Discard(idx + 1); err != nil { + size, err := strconv.ParseUint(string(lenRaw[:len(lenRaw)-1]), 10, 64) + if err != nil { return 0, err } r.left = size