]> Cypherpunks.ru repositories - netstring.git/blob - netstring.go
Raise copyright years
[netstring.git] / netstring.go
1 /*
2 netstring -- netstring format serialization library
3 Copyright (C) 2015-2020 Sergey Matveev <stargrave@stargrave.org>
4
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.
8
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.
13
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/>.
16 */
17
18 // netstring format serialization library.
19 //
20 // This is implementation of netstring
21 // (http://cr.yp.to/proto/netstrings.txt) format for binary string
22 // serialization.
23 //
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
34 //
35 // Pay attention that netstring uses bufio for Reader and Writer.
36 package netstring
37
38 import (
39         "errors"
40 )
41
42 const (
43         MaxPrefixSize = 21
44 )
45
46 var (
47         ErrBufSize    error = errors.New("Invalid destination buffer size")
48         ErrState      error = errors.New("Invalid state")
49         ErrTerminator error = errors.New("Invalid terminator")
50 )