summaryrefslogtreecommitdiffhomepage
path: root/pkg
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
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')
-rw-r--r--pkg/lisafs/message.go52
-rw-r--r--pkg/lisafs/sample_message.go12
-rw-r--r--pkg/marshal/marshal.go4
3 files changed, 16 insertions, 52 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.
diff --git a/pkg/lisafs/sample_message.go b/pkg/lisafs/sample_message.go
index 745736b6d..3d4c090e4 100644
--- a/pkg/lisafs/sample_message.go
+++ b/pkg/lisafs/sample_message.go
@@ -55,22 +55,14 @@ func (m *MsgDynamic) SizeBytes() int {
// MarshalBytes implements marshal.Marshallable.MarshalBytes.
func (m *MsgDynamic) MarshalBytes(dst []byte) []byte {
dst = m.N.MarshalUnsafe(dst)
- n, err := MarshalUnsafeMsg1Slice(m.Arr, dst)
- if err != nil {
- panic(err)
- }
- return dst[n:]
+ return MarshalUnsafeMsg1Slice(m.Arr, dst)
}
// UnmarshalBytes implements marshal.Marshallable.UnmarshalBytes.
func (m *MsgDynamic) UnmarshalBytes(src []byte) []byte {
src = m.N.UnmarshalUnsafe(src)
m.Arr = make([]MsgSimple, m.N)
- n, err := UnmarshalUnsafeMsg1Slice(m.Arr, src)
- if err != nil {
- panic(err)
- }
- return src[n:]
+ return UnmarshalUnsafeMsg1Slice(m.Arr, src)
}
// Randomize randomizes the contents of m.
diff --git a/pkg/marshal/marshal.go b/pkg/marshal/marshal.go
index 9e34eae80..a48a5835d 100644
--- a/pkg/marshal/marshal.go
+++ b/pkg/marshal/marshal.go
@@ -150,13 +150,13 @@ type Marshallable interface {
// // might be more efficient that repeatedly calling Foo.MarshalUnsafe
// // over a []Foo in a loop if the type is Packed.
// // Preconditions: dst must be at least len(src)*Foo.SizeBytes() in length.
-// func MarshalUnsafeFooSlice(src []Foo, dst []byte) (int, error) { ... }
+// func MarshalUnsafeFooSlice(src []Foo, dst []byte) []byte { ... }
//
// // UnmarshalUnsafeFooSlice is like Foo.UnmarshalUnsafe, buf for a []Foo. It
// // might be more efficient that repeatedly calling Foo.UnmarshalUnsafe
// // over a []Foo in a loop if the type is Packed.
// // Preconditions: src must be at least len(dst)*Foo.SizeBytes() in length.
-// func UnmarshalUnsafeFooSlice(dst []Foo, src []byte) (int, error) { ... }
+// func UnmarshalUnsafeFooSlice(dst []Foo, src []byte) []byte { ... }
//
// // CopyFooSliceIn copies in a slice of Foo objects from the task's memory.
// func CopyFooSliceIn(cc marshal.CopyContext, addr hostarch.Addr, dst []Foo) (int, error) { ... }