buffer: define OutMessage's contents.

geesefs-0-30-9
Aaron Jacobs 2016-12-19 12:53:32 +11:00
parent 6e5247d16d
commit 9eb5e0793f
1 changed files with 20 additions and 2 deletions

View File

@ -33,12 +33,18 @@ const OutMessageHeaderSize = unsafe.Sizeof(fusekernel.OutHeader{})
//
// Must be initialized with Reset.
type OutMessage struct {
// The offset into payload to which we're currently writing.
payloadOffset int
header [OutMessageHeaderSize]byte
payload [MaxReadSize]byte
}
// Make sure alignment works out correctly, at least for the header.
// Make sure that the header field is aligned correctly for
// fusekernel.OutHeader type punning.
func init() {
a := unsafe.Alignof(OutMessage{})
o := unsafe.Offsetof(OutMessage{}.storage)
o := unsafe.Offsetof(OutMessage{}.header)
e := unsafe.Alignof(fusekernel.OutHeader{})
if a%e != 0 || o%e != 0 {
@ -46,6 +52,18 @@ func init() {
}
}
// Make sure that the header and payload are contiguous.
func init() {
a := unsafe.Offsetof(OutMessage{}.header) + OutMessageHeaderSize
b := unsafe.Offsetof(OutMessage{}.payload)
if a != b {
log.Panicf(
"header ends at offset %d, but payload starts at offset %d",
a, b)
}
}
// Reset resets m so that it's ready to be used again. Afterward, the contents
// are solely a zeroed fusekernel.OutHeader struct.
func (m *OutMessage) Reset()