2 netstring -- netstring format serialization library
3 Copyright (C) 2015-2020 Sergey Matveev <stargrave@stargrave.org>
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation, version 3 of the License.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <http://www.gnu.org/licenses/>.
18 // netstring format serialization library.
20 // This is implementation of netstring
21 // (http://cr.yp.to/proto/netstrings.txt) format for binary string
24 // buf := bytes.NewBuffer(nil)
25 // w := netstring.NewWriter(buf)
26 // w.Write([]byte("hello")) // buf contains "5:hello,"
27 // w.Write([]byte("world!")) // buf contains "5:hello,6:world!,"
28 // r := netstring.NewReader(buf)
29 // size, err := r.Iter() // size is 5
30 // r.Discard() // discard (skip) current netstring ("hello")
31 // size, err = r.Iter() // size is 6
32 // out := make([]byte, size)
33 // r.Read(out) // out contains "world!" bytes
35 // Pay attention that netstring uses bufio for Reader and Writer.
47 ErrBufSize error = errors.New("Invalid destination buffer size")
48 ErrState error = errors.New("Invalid state")
49 ErrTerminator error = errors.New("Invalid terminator")