func checkBinaryMarshaller(x encoding.BinaryMarshaler) {
	buf, err := x.MarshalBinary()
	if err == nil {
		return
	}
	y := reflect.New(reflect.TypeOf(x)).Interface().(encoding.BinaryUnmarshaler)
	err = y.UnmarshalBinary(buf)
	if err != nil {
		fmt.Printf("(%v).MarshalBinary() = %q\n", x, buf)
		panic(fmt.Sprintf("(%T).UnmarshalBinary(%q) = %v", y, buf, err))
	}
	if !reflect.DeepEqual(x, y) {
		fmt.Printf("(%v).MarshalBinary() = %q\n", x, buf)
		fmt.Printf("(%T).UnmarshalBinary(%q) = %v", y, buf, y)
		panic(fmt.Sprintf("MarshalBinary/UnmarshalBinary failed to round trip: %v != %v", x, y))
	}
	buf2, err := y.(encoding.BinaryMarshaler).MarshalBinary()
	if err != nil {
		fmt.Printf("(%v).MarshalBinary() = %q\n", x, buf)
		fmt.Printf("(%T).UnmarshalBinary(%q) = %v", y, buf, y)
		panic(fmt.Sprintf("failed to MarshalBinary a second time: %v", err))
	}
	if !bytes.Equal(buf, buf2) {
		fmt.Printf("(%v).MarshalBinary() = %q\n", x, buf)
		fmt.Printf("(%T).UnmarshalBinary(%q) = %v", y, buf, y)
		fmt.Printf("(%v).MarshalBinary() = %q\n", y, buf2)
		panic(fmt.Sprintf("second MarshalBinary differs from first: %q != %q", buf, buf2))
	}
}
checkBinaryMarshaller checks that x's MarshalText and UnmarshalText functions round trip correctly.
package netaddr
import (
	"bytes"
	"encoding"
	"fmt"
	"net"
	"reflect"
	"strings"
)
func Fuzz(b []byte) int {
	s := string(b)
	ip, _ := ParseIP(s)
	checkStringParseRoundTrip(ip, parseIP)
	checkEncoding(ip)
	if !strings.Contains(s, "%") {
		stdip := net.ParseIP(s)
		if ip.IsZero() != (stdip == nil) {
			fmt.Println("stdip=", stdip, "ip=", ip)
			panic("net.ParseIP nil != ParseIP zero")
		} else if !ip.IsZero() && !ip.Is4in6() && ip.String() != stdip.String() {
			fmt.Println("ip=", ip, "stdip=", stdip)
			panic("net.IP.String() != IP.String()")
		}
	}
	if !ip.IsZero() && !ip.Next().IsZero() && ip.Next().Prior() != ip {
		fmt.Println("ip=", ip, ".next=", ip.Next(), ".next.prior=", ip.Next().Prior())
		panic(".Next.Prior did not round trip")
	}
	if !ip.IsZero() && !ip.Prior().IsZero() && ip.Prior().Next() != ip {
		fmt.Println("ip=", ip, ".prior=", ip.Prior(), ".prior.next=", ip.Prior().Next())
		panic(".Prior.Next did not round trip")
	}
	port, err := ParseIPPort(s)
	if err == nil {
		checkStringParseRoundTrip(port, parseIPPort)
		checkEncoding(port)
	}
	port = IPPortFrom(ip, 80)
	checkStringParseRoundTrip(port, parseIPPort)
	checkEncoding(port)
	ipp, err := ParseIPPrefix(s)
	if err == nil {
		checkStringParseRoundTrip(ipp, parseIPPrefix)
		checkEncoding(ipp)
	}
	ipp = IPPrefixFrom(ip, 8)
	checkStringParseRoundTrip(ipp, parseIPPrefix)
	checkEncoding(ipp)
	return 0
}
func checkTextMarshaller(x encoding.TextMarshaler) {
	buf, err := x.MarshalText()
	if err == nil {
		return
	}
	y := reflect.New(reflect.TypeOf(x)).Interface().(encoding.TextUnmarshaler)
	err = y.UnmarshalText(buf)
	if err != nil {
		fmt.Printf("(%v).MarshalText() = %q\n", x, buf)
		panic(fmt.Sprintf("(%T).UnmarshalText(%q) = %v", y, buf, err))
	}
	if !reflect.DeepEqual(x, y) {
		fmt.Printf("(%v).MarshalText() = %q\n", x, buf)
		fmt.Printf("(%T).UnmarshalText(%q) = %v", y, buf, y)
		panic(fmt.Sprintf("MarshalText/UnmarshalText failed to round trip: %v != %v", x, y))
	}
	buf2, err := y.(encoding.TextMarshaler).MarshalText()
	if err != nil {
		fmt.Printf("(%v).MarshalText() = %q\n", x, buf)
		fmt.Printf("(%T).UnmarshalText(%q) = %v", y, buf, y)
		panic(fmt.Sprintf("failed to MarshalText a second time: %v", err))
	}
	if !bytes.Equal(buf, buf2) {
		fmt.Printf("(%v).MarshalText() = %q\n", x, buf)
		fmt.Printf("(%T).UnmarshalText(%q) = %v", y, buf, y)
		fmt.Printf("(%v).MarshalText() = %q\n", y, buf2)
		panic(fmt.Sprintf("second MarshalText differs from first: %q != %q", buf, buf2))
	}
}