summaryrefslogtreecommitdiffhomepage
path: root/pkg/lisafs/message.go
diff options
context:
space:
mode:
authorAyush Ranjan <ayushranjan@google.com>2021-11-08 00:37:24 -0800
committergVisor bot <gvisor-bot@google.com>2021-11-08 00:39:46 -0800
commit4622e17bccc7c40a2698e8314d29bbde87090cec (patch)
treeebf9e83a9c9275bfb90367f301902072d8526028 /pkg/lisafs/message.go
parentce4f4283badb6b07baf9f8e6d99e7a5fd15c92db (diff)
Simplify {Un}MarshalUnsafeSlice method signatures.
Earlier this function was returning (int, error) much like the Copy{In/Out} methods. The returned error was always nil. The returned int was never used. Instead make it returned the shifted buffer which is more useful. Updates #6450 PiperOrigin-RevId: 408268327
Diffstat (limited to 'pkg/lisafs/message.go')
-rw-r--r--pkg/lisafs/message.go52
1 files changed, 12 insertions, 40 deletions
diff --git a/pkg/lisafs/message.go b/pkg/lisafs/message.go
index 0d7c30ce3..c5474d804 100644
--- a/pkg/lisafs/message.go
+++ b/pkg/lisafs/message.go
@@ -307,11 +307,7 @@ func (m *MountResp) MarshalBytes(dst []byte) []byte {
dst = m.MaxMessageSize.MarshalUnsafe(dst)
numSupported := primitive.Uint16(len(m.SupportedMs))
dst = numSupported.MarshalBytes(dst)
- n, err := MarshalUnsafeMIDSlice(m.SupportedMs, dst)
- if err != nil {
- panic(err)
- }
- return dst[n:]
+ return MarshalUnsafeMIDSlice(m.SupportedMs, dst)
}
// UnmarshalBytes implements marshal.Marshallable.UnmarshalBytes.
@@ -320,12 +316,12 @@ func (m *MountResp) UnmarshalBytes(src []byte) []byte {
src = m.MaxMessageSize.UnmarshalUnsafe(src)
var numSupported primitive.Uint16
src = numSupported.UnmarshalBytes(src)
- m.SupportedMs = make([]MID, numSupported)
- n, err := UnmarshalUnsafeMIDSlice(m.SupportedMs, src)
- if err != nil {
- panic(err)
+ if cap(m.SupportedMs) < int(numSupported) {
+ m.SupportedMs = make([]MID, numSupported)
+ } else {
+ m.SupportedMs = m.SupportedMs[:numSupported]
}
- return src[n:]
+ return UnmarshalUnsafeMIDSlice(m.SupportedMs, src)
}
// ChannelResp is the response to the create channel request.
@@ -440,11 +436,7 @@ func (w *WalkResp) MarshalBytes(dst []byte) []byte {
numInodes := primitive.Uint32(len(w.Inodes))
dst = numInodes.MarshalUnsafe(dst)
- n, err := MarshalUnsafeInodeSlice(w.Inodes, dst)
- if err != nil {
- panic(err)
- }
- return dst[n:]
+ return MarshalUnsafeInodeSlice(w.Inodes, dst)
}
// UnmarshalBytes implements marshal.Marshallable.UnmarshalBytes.
@@ -459,11 +451,7 @@ func (w *WalkResp) UnmarshalBytes(src []byte) []byte {
} else {
w.Inodes = w.Inodes[:numInodes]
}
- n, err := UnmarshalUnsafeInodeSlice(w.Inodes, src)
- if err != nil {
- panic(err)
- }
- return src[n:]
+ return UnmarshalUnsafeInodeSlice(w.Inodes, src)
}
// WalkStatResp is used to communicate stat results for WalkStat.
@@ -481,11 +469,7 @@ func (w *WalkStatResp) MarshalBytes(dst []byte) []byte {
numStats := primitive.Uint32(len(w.Stats))
dst = numStats.MarshalUnsafe(dst)
- n, err := linux.MarshalUnsafeStatxSlice(w.Stats, dst)
- if err != nil {
- panic(err)
- }
- return dst[n:]
+ return linux.MarshalUnsafeStatxSlice(w.Stats, dst)
}
// UnmarshalBytes implements marshal.Marshallable.UnmarshalBytes.
@@ -498,11 +482,7 @@ func (w *WalkStatResp) UnmarshalBytes(src []byte) []byte {
} else {
w.Stats = w.Stats[:numStats]
}
- n, err := linux.UnmarshalUnsafeStatxSlice(w.Stats, src)
- if err != nil {
- panic(err)
- }
- return src[n:]
+ return linux.UnmarshalUnsafeStatxSlice(w.Stats, src)
}
// OpenAtReq is used to open existing FDs with the specified flags.
@@ -578,11 +558,7 @@ func (f *FdArray) SizeBytes() int {
func (f *FdArray) MarshalBytes(dst []byte) []byte {
arrLen := primitive.Uint32(len(*f))
dst = arrLen.MarshalUnsafe(dst)
- n, err := MarshalUnsafeFDIDSlice(*f, dst)
- if err != nil {
- panic(err)
- }
- return dst[n:]
+ return MarshalUnsafeFDIDSlice(*f, dst)
}
// UnmarshalBytes implements marshal.Marshallable.UnmarshalBytes.
@@ -594,11 +570,7 @@ func (f *FdArray) UnmarshalBytes(src []byte) []byte {
} else {
*f = (*f)[:arrLen]
}
- n, err := UnmarshalUnsafeFDIDSlice(*f, src)
- if err != nil {
- panic(err)
- }
- return src[n:]
+ return UnmarshalUnsafeFDIDSlice(*f, src)
}
// CloseReq is used to close(2) FDs.