Renamed to OutMessage.

geesefs-0-30-9
Aaron Jacobs 2015-07-24 14:11:03 +10:00
parent 5166631830
commit b3d13508fb
1 changed files with 8 additions and 8 deletions

View File

@ -21,25 +21,25 @@ import (
"github.com/jacobsa/fuse/internal/fusekernel"
)
// Buffer provides a mechanism for constructing a single contiguous fuse
// OutMessage provides a mechanism for constructing a single contiguous fuse
// message from multiple segments, where the first segment is always a
// fusekernel.OutHeader message.
//
// Must be created with New. Exception: the zero value has Bytes() == nil.
type Buffer struct {
type OutMessage struct {
slice []byte
}
// Create a new buffer whose initial contents are a zeroed fusekernel.OutHeader
// message, and with room enough to grow by extra bytes.
func New(extra uintptr) (b Buffer) {
func NewOutMessage(extra uintptr) (b OutMessage) {
const headerSize = unsafe.Sizeof(fusekernel.OutHeader{})
b.slice = make([]byte, headerSize, headerSize+extra)
return
}
// Return a pointer to the header at the start of the buffer.
func (b *Buffer) OutHeader() (h *fusekernel.OutHeader) {
func (b *OutMessage) OutHeader() (h *fusekernel.OutHeader) {
sh := (*reflect.SliceHeader)(unsafe.Pointer(&b.slice))
h = (*fusekernel.OutHeader)(unsafe.Pointer(sh.Data))
return
@ -48,7 +48,7 @@ func (b *Buffer) OutHeader() (h *fusekernel.OutHeader) {
// Grow the buffer by the supplied number of bytes, returning a pointer to the
// start of the new segment. The sum of the arguments given to Grow must not
// exceed the argument given to New when creating the buffer.
func (b *Buffer) Grow(size uintptr) (p unsafe.Pointer) {
func (b *OutMessage) Grow(size uintptr) (p unsafe.Pointer) {
sh := (*reflect.SliceHeader)(unsafe.Pointer(&b.slice))
p = unsafe.Pointer(sh.Data + uintptr(sh.Len))
b.slice = b.slice[:len(b.slice)+int(size)]
@ -56,7 +56,7 @@ func (b *Buffer) Grow(size uintptr) (p unsafe.Pointer) {
}
// Equivalent to growing by the length of p, then copying p into the new segment.
func (b *Buffer) Append(p []byte) {
func (b *OutMessage) Append(p []byte) {
sh := reflect.SliceHeader{
Data: uintptr(b.Grow(uintptr(len(p)))),
Len: len(p),
@ -67,7 +67,7 @@ func (b *Buffer) Append(p []byte) {
}
// Equivalent to growing by the length of s, then copying s into the new segment.
func (b *Buffer) AppendString(s string) {
func (b *OutMessage) AppendString(s string) {
sh := reflect.SliceHeader{
Data: uintptr(b.Grow(uintptr(len(s)))),
Len: len(s),
@ -78,6 +78,6 @@ func (b *Buffer) AppendString(s string) {
}
// Return a reference to the current contents of the buffer.
func (b *Buffer) Bytes() []byte {
func (b *OutMessage) Bytes() []byte {
return b.slice
}