Standard library / net/netip
netip.Prefix.MarshalBinary()
Serialize to the package binary representation and recover the same value. Expected stdout: 'true\n'.
Formal Syntax & Structure
go syntaxgo
func (p Prefix) MarshalBinary() ([]byte, error)Return Value
([]byte, error)
Operation result; check errors and validity indicators when returned.
Working Example
Example Snippetgo
package main
import ( "fmt" "net/netip")
func main() { v := netip.MustParsePrefix("192.0.2.7/24") b := must(v.MarshalBinary()) var w netip.Prefix check(w.UnmarshalBinary(b)) fmt.Println(v == w)}
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) }}