X-Git-Url: http://www.git.cypherpunks.ru/?a=blobdiff_plain;f=ns.go;fp=netstring.go;h=af1159f39262f4b6a23f0aac8a325284345e56af;hb=refs%2Ftags%2Fv2.0.0;hp=8345556198e2836a3b7205221e36b84f529bd369;hpb=468e7a678129bddbbbda4b6b2c2b8a555fd47468;p=netstring.git diff --git a/netstring.go b/ns.go similarity index 53% rename from netstring.go rename to ns.go index 8345556..af1159f 100644 --- a/netstring.go +++ b/ns.go @@ -21,30 +21,15 @@ along with this program. If not, see . // (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. +// var b bytes.Buffer +// w := netstring.NewWriter(&b) +// n, _ = w.WriteChunk([]byte("hello")) // n is 8, "5:hello," +// n, _ = w.WriteSize(6) // n is 2 +// n, _ = w.Write([]byte("wor")) // n is 3 +// n, _ = w.Write([]byte("ld!")) // n is 3, "5:hello,6:world!," +// r := netstring.NewReader(&b) +// size, err := r.Next() // size is 5 +// r.Discard() // skip that chunk +// size, err = r.Next() // size is 6 +// data, _ := ioutil.ReadAll(r) // data contains "world!" 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") -)