Code generated by erb. DO NOT EDIT.

package pgtype

import (
	
	
	
	
	

	
)

type CIDRArray struct {
	Elements   []CIDR
	Dimensions []ArrayDimension
	Status     Status
}

untyped nil and typed nil interfaces are different
	if  == nil {
		* = CIDRArray{Status: Null}
		return nil
	}

	if ,  := .(interface{ () interface{} });  {
		 := .()
		if  !=  {
			return .()
		}
	}
Attempt to match to select common types:
	switch value := .(type) {

	case []*net.IPNet:
		if  == nil {
			* = CIDRArray{Status: Null}
		} else if len() == 0 {
			* = CIDRArray{Status: Present}
		} else {
			 := make([]CIDR, len())
			for  := range  {
				if  := [].Set([]);  != nil {
					return 
				}
			}
			* = CIDRArray{
				Elements:   ,
				Dimensions: []ArrayDimension{{Length: int32(len()), LowerBound: 1}},
				Status:     Present,
			}
		}

	case []net.IP:
		if  == nil {
			* = CIDRArray{Status: Null}
		} else if len() == 0 {
			* = CIDRArray{Status: Present}
		} else {
			 := make([]CIDR, len())
			for  := range  {
				if  := [].Set([]);  != nil {
					return 
				}
			}
			* = CIDRArray{
				Elements:   ,
				Dimensions: []ArrayDimension{{Length: int32(len()), LowerBound: 1}},
				Status:     Present,
			}
		}

	case []*net.IP:
		if  == nil {
			* = CIDRArray{Status: Null}
		} else if len() == 0 {
			* = CIDRArray{Status: Present}
		} else {
			 := make([]CIDR, len())
			for  := range  {
				if  := [].Set([]);  != nil {
					return 
				}
			}
			* = CIDRArray{
				Elements:   ,
				Dimensions: []ArrayDimension{{Length: int32(len()), LowerBound: 1}},
				Status:     Present,
			}
		}

	case []CIDR:
		if  == nil {
			* = CIDRArray{Status: Null}
		} else if len() == 0 {
			* = CIDRArray{Status: Present}
		} else {
			* = CIDRArray{
				Elements:   ,
				Dimensions: []ArrayDimension{{Length: int32(len()), LowerBound: 1}},
				Status:     Present,
			}
		}
Fallback to reflection if an optimised match was not found. The reflection is necessary for arrays and multidimensional slices, but it comes with a 20-50% performance penalty for large arrays/slices
		 := reflect.ValueOf()
		if !.IsValid() || .IsZero() {
			* = CIDRArray{Status: Null}
			return nil
		}

		, ,  := findDimensionsFromValue(, nil, 0)
		if ! {
			return fmt.Errorf("cannot find dimensions of %v for CIDRArray", )
		}
		if  == 0 {
			* = CIDRArray{Status: Present}
			return nil
		}
		if len() == 0 {
			if ,  := underlyingSliceType();  {
				return .()
			}
			return fmt.Errorf("cannot convert %v to CIDRArray", )
		}

		* = CIDRArray{
			Elements:   make([]CIDR, ),
			Dimensions: ,
			Status:     Present,
		}
		,  := .setRecursive(, 0, 0)
Maybe the target was one dimension too far, try again:
			if len(.Dimensions) > 1 {
				.Dimensions = .Dimensions[:len(.Dimensions)-1]
				 = 0
				for ,  := range .Dimensions {
					if  == 0 {
						 = int(.Length)
					} else {
						 *= int(.Length)
					}
				}
				.Elements = make([]CIDR, )
				,  = .setRecursive(, 0, 0)
				if  != nil {
					return 
				}
			} else {
				return 
			}
		}
		if  != len(.Elements) {
			return fmt.Errorf("cannot convert %v to CIDRArray, expected %d dst.Elements, but got %d instead", , len(.Elements), )
		}
	}

	return nil
}

func ( *CIDRArray) ( reflect.Value, ,  int) (int, error) {
	switch .Kind() {
	case reflect.Array:
		fallthrough
	case reflect.Slice:
		if len(.Dimensions) ==  {
			break
		}

		 := .Len()
		if int32() != .Dimensions[].Length {
			return 0, fmt.Errorf("multidimensional arrays must have array expressions with matching dimensions")
		}
		for  := 0;  < ; ++ {
			var  error
			,  = .(.Index(), , +1)
			if  != nil {
				return 0, 
			}
		}

		return , nil
	}
	if !.CanInterface() {
		return 0, fmt.Errorf("cannot convert all values to CIDRArray")
	}
	if  := .Elements[].Set(.Interface());  != nil {
		return 0, fmt.Errorf("%v in CIDRArray", )
	}
	++

	return , nil
}

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

func ( *CIDRArray) ( interface{}) error {
	switch .Status {
	case Present:
Attempt to match to select common types:
			switch v := .(type) {

			case *[]*net.IPNet:
				* = make([]*net.IPNet, len(.Elements))
				for  := range .Elements {
					if  := .Elements[].AssignTo(&((*)[]));  != nil {
						return 
					}
				}
				return nil

			case *[]net.IP:
				* = make([]net.IP, len(.Elements))
				for  := range .Elements {
					if  := .Elements[].AssignTo(&((*)[]));  != nil {
						return 
					}
				}
				return nil

			case *[]*net.IP:
				* = make([]*net.IP, len(.Elements))
				for  := range .Elements {
					if  := .Elements[].AssignTo(&((*)[]));  != nil {
						return 
					}
				}
				return nil

			}
		}
Try to convert to something AssignTo can use directly.
		if ,  := GetAssignToDstType();  {
			return .()
		}
Fallback to reflection if an optimised match was not found. The reflection is necessary for arrays and multidimensional slices, but it comes with a 20-50% performance penalty for large arrays/slices
		 := reflect.ValueOf()
		if .Kind() == reflect.Ptr {
			 = .Elem()
		}

		switch .Kind() {
		case reflect.Array, reflect.Slice:
		default:
			return fmt.Errorf("cannot assign %T to %T", , )
		}

		if len(.Elements) == 0 {
			if .Kind() == reflect.Slice {
				.Set(reflect.MakeSlice(.Type(), 0, 0))
				return nil
			}
		}

		,  := .assignToRecursive(, 0, 0)
		if  != nil {
			return 
		}
		if  != len(.Elements) {
			return fmt.Errorf("cannot assign %v, needed to assign %d elements, but only assigned %d", , len(.Elements), )
		}

		return nil
	case Null:
		return NullAssignTo()
	}

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

func ( *CIDRArray) ( reflect.Value, ,  int) (int, error) {
	switch  := .Kind();  {
	case reflect.Array:
		fallthrough
	case reflect.Slice:
		if len(.Dimensions) ==  {
			break
		}

		 := int(.Dimensions[].Length)
		if reflect.Array ==  {
			 := .Type()
			if .Len() !=  {
				return 0, fmt.Errorf("expected size %d array, but %s has size %d array", , , .Len())
			}
			.Set(reflect.New().Elem())
		} else {
			.Set(reflect.MakeSlice(.Type(), , ))
		}

		var  error
		for  := 0;  < ; ++ {
			,  = .(.Index(), , +1)
			if  != nil {
				return 0, 
			}
		}

		return , nil
	}
	if len(.Dimensions) !=  {
		return 0, fmt.Errorf("incorrect dimensions, expected %d, found %d", len(.Dimensions), )
	}
	if !.CanAddr() {
		return 0, fmt.Errorf("cannot assign all values from CIDRArray")
	}
	 := .Addr()
	if !.CanInterface() {
		return 0, fmt.Errorf("cannot assign all values from CIDRArray")
	}
	if  := .Elements[].AssignTo(.Interface());  != nil {
		return 0, 
	}
	++
	return , nil
}

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

	,  := ParseUntypedTextArray(string())
	if  != nil {
		return 
	}

	var  []CIDR

	if len(.Elements) > 0 {
		 = make([]CIDR, len(.Elements))

		for ,  := range .Elements {
			var  CIDR
			var  []byte
			if  != "NULL" || .Quoted[] {
				 = []byte()
			}
			 = .DecodeText(, )
			if  != nil {
				return 
			}

			[] = 
		}
	}

	* = CIDRArray{Elements: , Dimensions: .Dimensions, Status: Present}

	return nil
}

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

	var  ArrayHeader
	,  := .DecodeBinary(, )
	if  != nil {
		return 
	}

	if len(.Dimensions) == 0 {
		* = CIDRArray{Dimensions: .Dimensions, Status: Present}
		return nil
	}

	 := .Dimensions[0].Length
	for ,  := range .Dimensions[1:] {
		 *= .Length
	}

	 := make([]CIDR, )

	for  := range  {
		 := int(int32(binary.BigEndian.Uint32([:])))
		 += 4
		var  []byte
		if  >= 0 {
			 = [ : +]
			 += 
		}
		 = [].DecodeBinary(, )
		if  != nil {
			return 
		}
	}

	* = CIDRArray{Elements: , Dimensions: .Dimensions, Status: Present}
	return nil
}

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

	if len(.Dimensions) == 0 {
		return append(, '{', '}'), nil
	}

	 = EncodeTextArrayDimensions(, .Dimensions)
dimElemCounts is the multiples of elements that each array lies on. For example, a single dimension array of length 4 would have a dimElemCounts of [4]. A multi-dimensional array of lengths [3,5,2] would have a dimElemCounts of [30,10,2]. This is used to simplify when to render a '{' or '}'.
	 := make([]int, len(.Dimensions))
	[len(.Dimensions)-1] = int(.Dimensions[len(.Dimensions)-1].Length)
	for  := len(.Dimensions) - 2;  > -1; -- {
		[] = int(.Dimensions[].Length) * [+1]
	}

	 := make([]byte, 0, 32)
	for ,  := range .Elements {
		if  > 0 {
			 = append(, ',')
		}

		for ,  := range  {
			if % == 0 {
				 = append(, '{')
			}
		}

		,  := .EncodeText(, )
		if  != nil {
			return nil, 
		}
		if  == nil {
			 = append(, `NULL`...)
		} else {
			 = append(, QuoteArrayElementIfNeeded(string())...)
		}

		for ,  := range  {
			if (+1)% == 0 {
				 = append(, '}')
			}
		}
	}

	return , nil
}

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

	 := ArrayHeader{
		Dimensions: .Dimensions,
	}

	if ,  := .DataTypeForName("cidr");  {
		.ElementOID = int32(.OID)
	} else {
		return nil, fmt.Errorf("unable to find oid for type name %v", "cidr")
	}

	for  := range .Elements {
		if .Elements[].Status == Null {
			.ContainsNull = true
			break
		}
	}

	 = .EncodeBinary(, )

	for  := range .Elements {
		 := len()
		 = pgio.AppendInt32(, -1)

		,  := .Elements[].EncodeBinary(, )
		if  != nil {
			return nil, 
		}
		if  != nil {
			 = 
			pgio.SetInt32([:], int32(len([:])-4))
		}
	}

	return , nil
}
Scan implements the database/sql Scanner interface.
func ( *CIDRArray) ( interface{}) error {
	if  == nil {
		return .DecodeText(nil, 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 ( CIDRArray) () (driver.Value, error) {
	,  := .EncodeText(nil, nil)
	if  != nil {
		return nil, 
	}
	if  == nil {
		return nil, nil
	}

	return string(), nil