/*
netstring -- netstring format serialization library
-Copyright (C) 2015-2022 Sergey Matveev <stargrave@stargrave.org>
+Copyright (C) 2015-2023 Sergey Matveev <stargrave@stargrave.org>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
import (
"bufio"
- "bytes"
"errors"
"io"
"strconv"
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