package msgioimport ()// LimitedReader wraps an io.Reader with a msgio framed reader. The LimitedReader// will return a reader which will io.EOF when the msg length is done.func ( io.Reader) (io.Reader, error) { , := ReadLen(, nil)returnio.LimitReader(, int64()), }// LimitedWriter wraps an io.Writer with a msgio framed writer. It is the inverse// of LimitedReader: it will buffer all writes until "Flush" is called. When Flush// is called, it will write the size of the buffer first, flush the buffer, reset// the buffer, and begin accept more incoming writes.func ( io.Writer) *LimitedWriter {return &LimitedWriter{W: }}typeLimitedWriterstruct { W io.Writer B bytes.Buffer M sync.Mutex}func ( *LimitedWriter) ( []byte) ( int, error) { .M.Lock() , = .B.Write() .M.Unlock()return , }func ( *LimitedWriter) () error { .M.Lock()defer .M.Unlock()if := WriteLen(.W, .B.Len()); != nil {return } , := .B.WriteTo(.W)return}
The pages are generated with Goldsv0.8.2. (GOOS=linux GOARCH=amd64)
Golds is a Go 101 project developed by Tapir Liu.
PR and bug reports are welcome and can be submitted to the issue list.
Please follow @zigo_101 (reachable from the left QR code) to get the latest news of Golds.