mirror of
https://github.com/netbirdio/gvisor.git
synced 2026-05-22 17:12:49 -07:00
Add a method that returns an owned copy of the data in a View.
PiperOrigin-RevId: 463703416
This commit is contained in:
committed by
gVisor bot
parent
1dbab069cb
commit
502cc29f87
@@ -161,6 +161,16 @@ func (v *View) AsSlice() []byte {
|
||||
return v.chunk.data[v.read:v.write]
|
||||
}
|
||||
|
||||
// ToSlice returns an owned copy of the data in this view.
|
||||
func (v *View) ToSlice() []byte {
|
||||
if v.Size() == 0 {
|
||||
return nil
|
||||
}
|
||||
s := make([]byte, v.Size())
|
||||
copy(s, v.AsSlice())
|
||||
return s
|
||||
}
|
||||
|
||||
// AvailableSize returns the number of bytes available for writing.
|
||||
func (v *View) AvailableSize() int {
|
||||
if v == nil {
|
||||
|
||||
Reference in New Issue
Block a user