Make {Un}Marshal{Bytes/Unsafe} return remaining buffer.

Change marshal.Marshallable method signatures to return the remaining buffer.
This makes it easier to implement these method manually. Without this, we would
have to manually do buffer shifting which is error prone.

tools/go_marshal/test:benchmark test does not show change in performance.
Additionally fixed some marshalling bugs in fsimpl/fuse.

Updated multiple callpoints to get rid of redundant slice indexing work and
simplified code using this new signature.

Updates #6450

PiperOrigin-RevId: 407857019
This commit is contained in:
Ayush Ranjan
2021-11-05 10:43:49 -07:00
committed by gVisor bot
parent 822a647018
commit ce4f4283ba
41 changed files with 631 additions and 754 deletions
+6 -6
View File
@@ -82,15 +82,15 @@ func (b *MsgBuf) SizeBytes() int {
}
// MarshalBytes implements marshal.Marshallable.MarshalBytes.
func (b *MsgBuf) MarshalBytes(dst []byte) {
b.Type.MarshalUnsafe(dst)
b.Text.MarshalBytes(dst[b.Type.SizeBytes():])
func (b *MsgBuf) MarshalBytes(dst []byte) []byte {
dst = b.Type.MarshalUnsafe(dst)
return b.Text.MarshalBytes(dst)
}
// UnmarshalBytes implements marshal.Marshallable.UnmarshalBytes.
func (b *MsgBuf) UnmarshalBytes(src []byte) {
b.Type.UnmarshalUnsafe(src)
b.Text.UnmarshalBytes(src[b.Type.SizeBytes():])
func (b *MsgBuf) UnmarshalBytes(src []byte) []byte {
src = b.Type.UnmarshalUnsafe(src)
return b.Text.UnmarshalBytes(src)
}
// MsgInfo is equivelant to struct msginfo. Source: include/uapi/linux/msg.h