Standard library / net/netip

netip.Prefix.UnmarshalBinary()

Decode the binary representation generated by MarshalBinary into the receiver. Expected stdout: '192.0.2.7/24\n'.

Formal Syntax & Structure

go syntaxgo
func (p *Prefix) UnmarshalBinary(b []byte) error

Parameters & Attributes

NameTypeDescription
b[]byteByte buffer, binary representation or prefix length as indicated by its type.

Return Value

error

Operation result; check errors and validity indicators when returned.

Working Example

Example Snippetgo
package main
import (  "fmt"  "net/netip")
func main() {  b := must(netip.MustParsePrefix("192.0.2.7/24").MarshalBinary())  var v netip.Prefix  check(v.UnmarshalBinary(b))  fmt.Println(v)}
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