Renamed to OutMessage.
parent
5166631830
commit
b3d13508fb
|
@ -21,25 +21,25 @@ import (
|
||||||
"github.com/jacobsa/fuse/internal/fusekernel"
|
"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
|
// message from multiple segments, where the first segment is always a
|
||||||
// fusekernel.OutHeader message.
|
// fusekernel.OutHeader message.
|
||||||
//
|
//
|
||||||
// Must be created with New. Exception: the zero value has Bytes() == nil.
|
// Must be created with New. Exception: the zero value has Bytes() == nil.
|
||||||
type Buffer struct {
|
type OutMessage struct {
|
||||||
slice []byte
|
slice []byte
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create a new buffer whose initial contents are a zeroed fusekernel.OutHeader
|
// Create a new buffer whose initial contents are a zeroed fusekernel.OutHeader
|
||||||
// message, and with room enough to grow by extra bytes.
|
// 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{})
|
const headerSize = unsafe.Sizeof(fusekernel.OutHeader{})
|
||||||
b.slice = make([]byte, headerSize, headerSize+extra)
|
b.slice = make([]byte, headerSize, headerSize+extra)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Return a pointer to the header at the start of the buffer.
|
// 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))
|
sh := (*reflect.SliceHeader)(unsafe.Pointer(&b.slice))
|
||||||
h = (*fusekernel.OutHeader)(unsafe.Pointer(sh.Data))
|
h = (*fusekernel.OutHeader)(unsafe.Pointer(sh.Data))
|
||||||
return
|
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
|
// 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
|
// 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.
|
// 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))
|
sh := (*reflect.SliceHeader)(unsafe.Pointer(&b.slice))
|
||||||
p = unsafe.Pointer(sh.Data + uintptr(sh.Len))
|
p = unsafe.Pointer(sh.Data + uintptr(sh.Len))
|
||||||
b.slice = b.slice[:len(b.slice)+int(size)]
|
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.
|
// 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{
|
sh := reflect.SliceHeader{
|
||||||
Data: uintptr(b.Grow(uintptr(len(p)))),
|
Data: uintptr(b.Grow(uintptr(len(p)))),
|
||||||
Len: 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.
|
// 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{
|
sh := reflect.SliceHeader{
|
||||||
Data: uintptr(b.Grow(uintptr(len(s)))),
|
Data: uintptr(b.Grow(uintptr(len(s)))),
|
||||||
Len: 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.
|
// Return a reference to the current contents of the buffer.
|
||||||
func (b *Buffer) Bytes() []byte {
|
func (b *OutMessage) Bytes() []byte {
|
||||||
return b.slice
|
return b.slice
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue