Commit c0e60edb authored by Aaron Jacobs's avatar Aaron Jacobs

Defined the new OutMessage API.

parent 3371ab70
...@@ -15,7 +15,6 @@ ...@@ -15,7 +15,6 @@
package buffer package buffer
import ( import (
"reflect"
"unsafe" "unsafe"
"github.com/jacobsa/fuse/internal/fusekernel" "github.com/jacobsa/fuse/internal/fusekernel"
...@@ -35,54 +34,47 @@ type OutMessage struct { ...@@ -35,54 +34,47 @@ type OutMessage struct {
storage [outMessageSize]byte storage [outMessageSize]byte
} }
// Create a new buffer whose initial contents are a zeroed fusekernel.OutHeader // Reset the message so that it is ready to be used again. Afterward, the
// message, and with room enough to grow by extra bytes. // contents are solely a zeroed header.
func NewOutMessage(extra uintptr) (b OutMessage) { func (m *OutMessage) Reset() {
const headerSize = unsafe.Sizeof(fusekernel.OutHeader{}) panic("TODO")
b.slice = make([]byte, headerSize, headerSize+extra)
return
} }
// Return a pointer to the header at the start of the buffer. // Return a pointer to the header at the start of the message.
func (b *OutMessage) OutHeader() (h *fusekernel.OutHeader) { func (b *OutMessage) OutHeader() (h *fusekernel.OutHeader) {
sh := (*reflect.SliceHeader)(unsafe.Pointer(&b.slice)) panic("TODO")
h = (*fusekernel.OutHeader)(unsafe.Pointer(sh.Data))
return
} }
// 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, which is zeroed. If there is no space left, return
// exceed the argument given to New when creating the buffer. // the nil pointer.
func (b *OutMessage) Grow(size uintptr) (p unsafe.Pointer) { func (b *OutMessage) Grow(size uintptr) (p unsafe.Pointer) {
sh := (*reflect.SliceHeader)(unsafe.Pointer(&b.slice)) panic("TODO")
p = unsafe.Pointer(sh.Data + uintptr(sh.Len))
b.slice = b.slice[:len(b.slice)+int(size)]
return
} }
// Equivalent to growing by the length of p, then copying p into the new segment. // Equivalent to Grow, except the new segment is not zeroed. Use with caution!
func (b *OutMessage) Append(p []byte) { func (b *OutMessage) GrowNoZero(size uintptr) (p unsafe.Pointer) {
sh := reflect.SliceHeader{ panic("TODO")
Data: uintptr(b.Grow(uintptr(len(p)))), }
Len: len(p),
Cap: len(p),
}
copy(*(*[]byte)(unsafe.Pointer(&sh)), p) // Equivalent to growing by the length of p, then copying p over the new
// segment.
func (b *OutMessage) Append(p []byte) {
panic("TODO")
} }
// 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 over the new
// segment.
func (b *OutMessage) AppendString(s string) { func (b *OutMessage) AppendString(s string) {
sh := reflect.SliceHeader{ panic("TODO")
Data: uintptr(b.Grow(uintptr(len(s)))), }
Len: len(s),
Cap: len(s),
}
copy(*(*[]byte)(unsafe.Pointer(&sh)), s) // Return the current size of the buffer.
func (b *OutMessage) Len() int {
panic("TODO")
} }
// Return a reference to the current contents of the buffer. // Return a reference to the current contents of the buffer.
func (b *OutMessage) Bytes() []byte { func (b *OutMessage) Bytes() []byte {
return b.slice panic("TODO")
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment