package pgtype

import (
	
	
	
)
Network address family is dependent on server socket.h value for AF_INET. In practice, all platforms appear to have the same value. See src/include/utils/inet.h for more information.
const (
	defaultAFInet  = 2
	defaultAFInet6 = 3
)
Inet represents both inet and cidr PostgreSQL types.
type Inet struct {
	IPNet  *net.IPNet
	Status Status
}

func ( *Inet) ( interface{}) error {
	if  == nil {
		* = Inet{Status: Null}
		return nil
	}

	if ,  := .(interface{ () interface{} });  {
		 := .()
		if  !=  {
			return .()
		}
	}

	switch value := .(type) {
	case net.IPNet:
		* = Inet{IPNet: &, Status: Present}
	case net.IP:
		if len() == 0 {
			* = Inet{Status: Null}
		} else {
			 := len() * 8
			 := net.CIDRMask(, )
			* = Inet{IPNet: &net.IPNet{Mask: , IP: }, Status: Present}
		}
	case string:
		, ,  := net.ParseCIDR()
		if  != nil {
			return 
		}
		* = Inet{IPNet: , Status: Present}
	case *net.IPNet:
		if  == nil {
			* = Inet{Status: Null}
		} else {
			return .(*)
		}
	case *net.IP:
		if  == nil {
			* = Inet{Status: Null}
		} else {
			return .(*)
		}
	case *string:
		if  == nil {
			* = Inet{Status: Null}
		} else {
			return .(*)
		}
	default:
		if ,  := underlyingPtrType();  {
			return .()
		}
		return fmt.Errorf("cannot convert %v to Inet", )
	}

	return nil
}

func ( Inet) () interface{} {
	switch .Status {
	case Present:
		return .IPNet
	case Null:
		return nil
	default:
		return .Status
	}
}

func ( *Inet) ( interface{}) error {
	switch .Status {
	case Present:
		switch v := .(type) {
		case *net.IPNet:
			* = net.IPNet{
				IP:   make(net.IP, len(.IPNet.IP)),
				Mask: make(net.IPMask, len(.IPNet.Mask)),
			}
			copy(.IP, .IPNet.IP)
			copy(.Mask, .IPNet.Mask)
			return nil
		case *net.IP:
			if ,  := .IPNet.Mask.Size();  !=  {
				return fmt.Errorf("cannot assign %v to %T", , )
			}
			* = make(net.IP, len(.IPNet.IP))
			copy(*, .IPNet.IP)
			return nil
		default:
			if ,  := GetAssignToDstType();  {
				return .()
			}
			return fmt.Errorf("unable to assign to %T", )
		}
	case Null:
		return NullAssignTo()
	}

	return fmt.Errorf("cannot decode %#v into %T", , )
}

func ( *Inet) ( *ConnInfo,  []byte) error {
	if  == nil {
		* = Inet{Status: Null}
		return nil
	}

	var  *net.IPNet
	var  error

	if  := net.ParseIP(string());  != nil {
		 := .To4()
		if  != nil {
			 = 
		}
		 := len() * 8
		 := net.CIDRMask(, )
		 = &net.IPNet{Mask: , IP: }
	} else {
		_, ,  = net.ParseCIDR(string())
		if  != nil {
			return 
		}
	}

	* = Inet{IPNet: , Status: Present}
	return nil
}

func ( *Inet) ( *ConnInfo,  []byte) error {
	if  == nil {
		* = Inet{Status: Null}
		return nil
	}

	if len() != 8 && len() != 20 {
		return fmt.Errorf("Received an invalid size for a inet: %d", len())
	}
ignore family
ignore is_cidr
	 := [3]

	var  net.IPNet
	.IP = make(net.IP, int())
	copy(.IP, [4:])
	.Mask = net.CIDRMask(int(), int()*8)

	* = Inet{IPNet: &, Status: Present}

	return nil
}

func ( Inet) ( *ConnInfo,  []byte) ([]byte, error) {
	switch .Status {
	case Null:
		return nil, nil
	case Undefined:
		return nil, errUndefined
	}

	return append(, .IPNet.String()...), nil
}
EncodeBinary encodes src into w.
func ( Inet) ( *ConnInfo,  []byte) ([]byte, error) {
	switch .Status {
	case Null:
		return nil, nil
	case Undefined:
		return nil, errUndefined
	}

	var  byte
	switch len(.IPNet.IP) {
	case net.IPv4len:
		 = defaultAFInet
	case net.IPv6len:
		 = defaultAFInet6
	default:
		return nil, fmt.Errorf("Unexpected IP length: %v", len(.IPNet.IP))
	}

	 = append(, )

	,  := .IPNet.Mask.Size()
	 = append(, byte())
is_cidr is ignored on server
	 = append(, 0)

	 = append(, byte(len(.IPNet.IP)))

	return append(, .IPNet.IP...), nil
}
Scan implements the database/sql Scanner interface.
func ( *Inet) ( interface{}) error {
	if  == nil {
		* = Inet{Status: Null}
		return nil
	}

	switch src := .(type) {
	case string:
		return .DecodeText(nil, []byte())
	case []byte:
		 := make([]byte, len())
		copy(, )
		return .DecodeText(nil, )
	}

	return fmt.Errorf("cannot scan %T", )
}
Value implements the database/sql/driver Valuer interface.
func ( Inet) () (driver.Value, error) {
	return EncodeValueText()