summaryrefslogtreecommitdiffhomepage
path: root/pkg/tcpip/buffer
diff options
context:
space:
mode:
authorgVisor bot <gvisor-bot@google.com>2020-03-26 21:08:58 +0000
committergVisor bot <gvisor-bot@google.com>2020-03-26 21:08:58 +0000
commit98c58a207c4b3dfc9dd9b0d0ccab4e85fe82be75 (patch)
tree290b0559d6e42abb33d944e407b59996cc940e74 /pkg/tcpip/buffer
parentabd55c233ce4ceca722a6b5dcf52727db48987b0 (diff)
parentfbe80460a7eb34147b928fa1023b28a3c094c070 (diff)
Merge release-20200219.0-247-gfbe8046 (automated)
Diffstat (limited to 'pkg/tcpip/buffer')
-rw-r--r--pkg/tcpip/buffer/view.go20
1 files changed, 20 insertions, 0 deletions
diff --git a/pkg/tcpip/buffer/view.go b/pkg/tcpip/buffer/view.go
index 17e94c562..8d42cd066 100644
--- a/pkg/tcpip/buffer/view.go
+++ b/pkg/tcpip/buffer/view.go
@@ -15,6 +15,10 @@
// Package buffer provides the implementation of a buffer view.
package buffer
+import (
+ "bytes"
+)
+
// View is a slice of a buffer, with convenience methods.
type View []byte
@@ -45,6 +49,13 @@ func (v *View) CapLength(length int) {
*v = (*v)[:length:length]
}
+// Reader returns a bytes.Reader for v.
+func (v *View) Reader() bytes.Reader {
+ var r bytes.Reader
+ r.Reset(*v)
+ return r
+}
+
// ToVectorisedView returns a VectorisedView containing the receiver.
func (v View) ToVectorisedView() VectorisedView {
return NewVectorisedView(len(v), []View{v})
@@ -162,3 +173,12 @@ func (vv *VectorisedView) AppendView(v View) {
vv.views = append(vv.views, v)
vv.size += len(v)
}
+
+// Readers returns a bytes.Reader for each of vv's views.
+func (vv *VectorisedView) Readers() []bytes.Reader {
+ readers := make([]bytes.Reader, 0, len(vv.views))
+ for _, v := range vv.views {
+ readers = append(readers, v.Reader())
+ }
+ return readers
+}