Package msgconn implements a wrapper that encodes and decodes variable-length messages to and from a bytestream.
go get github.com/boljen/msgconn
go get gopkg.in/boljen/msgconn.v1
// Creating a new MsgConn instance
tcpConn, _ := ln.AcceptTCP()
conn := &MsgConn{
Reader: tcpConn,
Writer: tcpConn,
Closer: tcpConn,
}
// Reading and writing messages
msg, _ := conn.ReadMessage()
conn.WriteMessage([]byte("message"))
This package is released under the MIT license.