mirror of
https://github.com/netbirdio/gvisor.git
synced 2026-05-22 17:12:49 -07:00
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:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user