Standard library / net

net.Buffers.Read()

Read consecutive slices as a byte stream, advancing the receiver. The original byte contents are not modified. Expected stdout: '3 abc d\n'.

Formal Syntax & Structure

go syntaxgo
func (v *Buffers) Read(p []byte) (n int, err error)

Parameters & Attributes

NameTypeDescription
p[]byteDestination byte buffer.

Return Value

(n int, err error)

Operation result; check errors and validity indicators when returned.

Working Example

Example Snippetgo
package main
import (  "fmt"  "net")
func main() {  v := net.Buffers{[]byte("ab"), []byte("cd")}  b := make([]byte, 3)  n := must(v.Read(b))  fmt.Println(n, string(b), string(v[0]))}
func must[T any](v T, e error) T {  if e != nil {    panic(e)  }  return v}func check(e error) {  if e != nil {    panic(e)  }}
Go Reference