Skip to content

lightpaw/bufreader

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 

Repository files navigation

buf reader Build Status codecov

It's like bufio.Reader that reads as much bytes as possible in one read call to reduce the number of Read calls to underlying net.Conn which results in system calls.

But it returns its internal buffer to the caller to reduce memory copies. Most of the times, the caller unmarshal the slice to something else (like protobuf or just make an int out of 4 bytes).

Internally it uses sync.Pool to further reduce gc.

    reader := bufreader.NewBufReader(conn, 1024) // use the reader to read the content in conn
    length, err := reader.ReadFull(2) // read 2 bytes for length
    data, err := reader.ReadFull(int(binary.LittleEndian.Uint16(length))) // read data

About

like bufio.Reader, but returns internal buffer to reduce slice copy

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages