Standard library / net/netip

netip.AddrPort.MarshalBinary()

Serialize to the package binary representation and recover the same value. Expected stdout: 'true\n'.

Formal Syntax & Structure

go syntaxgo
func (p AddrPort) 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.MustParseAddrPort("192.0.2.7:80")  b := must(v.MarshalBinary())  var w netip.AddrPort  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)  }}
Go Reference