func (p *ByteBufferIO) Read(b []byte) (n int, err error) {
	var buf []byte
	readable := p.buffer.ReadableLen()
	if readable == 0 {
		return 0, io.EOF
	} else if len(b) <= readable {
		buf, err = p.buffer.Next(len(b))
		if err != nil {
			return
		}
		n = len(b)
	} else {
		buf, err = p.buffer.Next(readable)
		if err != nil {
			return
		}
		n = readable
	}
	copy(b, buf)
	return
}
Read implements the io.ReadWriter interface.
package remote
import (
	"io"
	"net"
)
type ByteBufferFactory interface {
	NewByteBuffer(conn net.Conn) (ByteBuffer, error)
}
type NocopyWrite interface {
	WriteDirect(buf []byte, remainCap int) error
}
type ByteBuffer interface {
	io.ReadWriter
	Next(n int) (p []byte, err error)
	Peek(n int) (buf []byte, err error)
	Skip(n int) (err error)
	Release(e error) (err error)
	ReadableLen() (n int)
	ReadLen() (n int)
	ReadString(n int) (s string, err error)
	ReadBinary(n int) (p []byte, err error)
	Malloc(n int) (buf []byte, err error)
	MallocLen() (length int)
	WriteString(s string) (n int, err error)
	WriteBinary(b []byte) (n int, err error)
	Flush() (err error)
	NewBuffer() ByteBuffer
	AppendBuffer(buf ByteBuffer) (n int, err error)
	Bytes() (buf []byte, err error)
}
type ByteBufferIO struct {
	buffer ByteBuffer
}
func NewByteBufferIO(buffer ByteBuffer) io.ReadWriter {
	return &ByteBufferIO{
		buffer: buffer,
	}
}
func (p *ByteBufferIO) Write(b []byte) (int, error) {
	return p.buffer.WriteBinary(b)
}