/* netstring -- netstring format serialization library Copyright (C) 2015 Sergey Matveev 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 the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ // netstring format serialization library. // // This is implementation of netstring // (http://cr.yp.to/proto/netstrings.txt) format for binary string // serialization. // // buf := bytes.NewBuffer(nil) // w := netstring.NewWriter(buf) // w.Write([]byte("hello")) // buf contains "5:hello," // w.Write([]byte("world!")) // buf contains "5:hello,6:world!," // r := netstring.NewReader(buf) // size, err := r.Iter() // size is 5 // r.Discard() // discard (skip) current netstring ("hello") // size, err = r.Iter() // size is 6 // out := make([]byte, size) // r.Read(out) // out contains "world!" bytes // // Pay attention that netstring uses bufio for Reader and Writer. package netstring import ( "errors" ) const ( MaxPrefixSize = 21 ) var ( ErrBufSize error = errors.New("Invalid destination buffer size") ErrState error = errors.New("Invalid state") ErrTerminator error = errors.New("Invalid terminator") )