2 netstring -- netstring format serialization library
3 Copyright (C) 2015-2018 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, either version 3 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
19 // netstring format serialization library.
21 // This is implementation of netstring
22 // (http://cr.yp.to/proto/netstrings.txt) format for binary string
25 // buf := bytes.NewBuffer(nil)
26 // w := netstring.NewWriter(buf)
27 // w.Write([]byte("hello")) // buf contains "5:hello,"
28 // w.Write([]byte("world!")) // buf contains "5:hello,6:world!,"
29 // r := netstring.NewReader(buf)
30 // size, err := r.Iter() // size is 5
31 // r.Discard() // discard (skip) current netstring ("hello")
32 // size, err = r.Iter() // size is 6
33 // out := make([]byte, size)
34 // r.Read(out) // out contains "world!" bytes
36 // Pay attention that netstring uses bufio for Reader and Writer.
48 ErrBufSize error = errors.New("Invalid destination buffer size")
49 ErrState error = errors.New("Invalid state")
50 ErrTerminator error = errors.New("Invalid terminator")