package pgtype
import (
)
type Int64Scanner interface {
ScanInt64(Int8) error
}
type Int64Valuer interface {
Int64Value() (Int8, error)
}
type Int2 struct {
Int16 int16
Valid bool
}
func ( *Int2) ( Int8) error {
if !.Valid {
* = Int2{}
return nil
}
if .Int64 < math.MinInt16 {
return fmt.Errorf("%d is less than minimum value for Int2", .Int64)
}
if .Int64 > math.MaxInt16 {
return fmt.Errorf("%d is greater than maximum value for Int2", .Int64)
}
* = Int2{Int16: int16(.Int64), Valid: true}
return nil
}
func ( Int2) () (Int8, error) {
return Int8{Int64: int64(.Int16), Valid: .Valid}, nil
}
func ( *Int2) ( any) error {
if == nil {
* = Int2{}
return nil
}
var int64
switch src := .(type) {
case int64:
=
case string:
var error
, = strconv.ParseInt(, 10, 16)
if != nil {
return
}
case []byte:
var error
, = strconv.ParseInt(string(), 10, 16)
if != nil {
return
}
default:
return fmt.Errorf("cannot scan %T", )
}
if < math.MinInt16 {
return fmt.Errorf("%d is less than minimum value for Int2", )
}
if > math.MaxInt16 {
return fmt.Errorf("%d is greater than maximum value for Int2", )
}
* = Int2{Int16: int16(), Valid: true}
return nil
}
func ( Int2) () (driver.Value, error) {
if !.Valid {
return nil, nil
}
return int64(.Int16), nil
}
func ( Int2) () ([]byte, error) {
if !.Valid {
return []byte("null"), nil
}
return []byte(strconv.FormatInt(int64(.Int16), 10)), nil
}
func ( *Int2) ( []byte) error {
var *int16
:= json.Unmarshal(, &)
if != nil {
return
}
if == nil {
* = Int2{}
} else {
* = Int2{Int16: *, Valid: true}
}
return nil
}
type Int2Codec struct{}
func (Int2Codec) ( int16) bool {
return == TextFormatCode || == BinaryFormatCode
}
func (Int2Codec) () int16 {
return BinaryFormatCode
}
func (Int2Codec) ( *Map, uint32, int16, any) EncodePlan {
switch {
case BinaryFormatCode:
switch .(type) {
case int16:
return encodePlanInt2CodecBinaryInt16{}
case Int64Valuer:
return encodePlanInt2CodecBinaryInt64Valuer{}
}
case TextFormatCode:
switch .(type) {
case int16:
return encodePlanInt2CodecTextInt16{}
case Int64Valuer:
return encodePlanInt2CodecTextInt64Valuer{}
}
}
return nil
}
type encodePlanInt2CodecBinaryInt16 struct{}
func (encodePlanInt2CodecBinaryInt16) ( any, []byte) ( []byte, error) {
:= .(int16)
return pgio.AppendInt16(, int16()), nil
}
type encodePlanInt2CodecTextInt16 struct{}
func (encodePlanInt2CodecTextInt16) ( any, []byte) ( []byte, error) {
:= .(int16)
return append(, strconv.FormatInt(int64(), 10)...), nil
}
type encodePlanInt2CodecBinaryInt64Valuer struct{}
func (encodePlanInt2CodecBinaryInt64Valuer) ( any, []byte) ( []byte, error) {
, := .(Int64Valuer).Int64Value()
if != nil {
return nil,
}
if !.Valid {
return nil, nil
}
if .Int64 > math.MaxInt16 {
return nil, fmt.Errorf("%d is greater than maximum value for int2", .Int64)
}
if .Int64 < math.MinInt16 {
return nil, fmt.Errorf("%d is less than minimum value for int2", .Int64)
}
return pgio.AppendInt16(, int16(.Int64)), nil
}
type encodePlanInt2CodecTextInt64Valuer struct{}
func (encodePlanInt2CodecTextInt64Valuer) ( any, []byte) ( []byte, error) {
, := .(Int64Valuer).Int64Value()
if != nil {
return nil,
}
if !.Valid {
return nil, nil
}
if .Int64 > math.MaxInt16 {
return nil, fmt.Errorf("%d is greater than maximum value for int2", .Int64)
}
if .Int64 < math.MinInt16 {
return nil, fmt.Errorf("%d is less than minimum value for int2", .Int64)
}
return append(, strconv.FormatInt(.Int64, 10)...), nil
}
func (Int2Codec) ( *Map, uint32, int16, any) ScanPlan {
switch {
case BinaryFormatCode:
switch .(type) {
case *int8:
return scanPlanBinaryInt2ToInt8{}
case *int16:
return scanPlanBinaryInt2ToInt16{}
case *int32:
return scanPlanBinaryInt2ToInt32{}
case *int64:
return scanPlanBinaryInt2ToInt64{}
case *int:
return scanPlanBinaryInt2ToInt{}
case *uint8:
return scanPlanBinaryInt2ToUint8{}
case *uint16:
return scanPlanBinaryInt2ToUint16{}
case *uint32:
return scanPlanBinaryInt2ToUint32{}
case *uint64:
return scanPlanBinaryInt2ToUint64{}
case *uint:
return scanPlanBinaryInt2ToUint{}
case Int64Scanner:
return scanPlanBinaryInt2ToInt64Scanner{}
case TextScanner:
return scanPlanBinaryInt2ToTextScanner{}
}
case TextFormatCode:
switch .(type) {
case *int8:
return scanPlanTextAnyToInt8{}
case *int16:
return scanPlanTextAnyToInt16{}
case *int32:
return scanPlanTextAnyToInt32{}
case *int64:
return scanPlanTextAnyToInt64{}
case *int:
return scanPlanTextAnyToInt{}
case *uint8:
return scanPlanTextAnyToUint8{}
case *uint16:
return scanPlanTextAnyToUint16{}
case *uint32:
return scanPlanTextAnyToUint32{}
case *uint64:
return scanPlanTextAnyToUint64{}
case *uint:
return scanPlanTextAnyToUint{}
case Int64Scanner:
return scanPlanTextAnyToInt64Scanner{}
}
}
return nil
}
func ( Int2Codec) ( *Map, uint32, int16, []byte) (driver.Value, error) {
if == nil {
return nil, nil
}
var int64
:= codecScan(, , , , , &)
if != nil {
return nil,
}
return , nil
}
func ( Int2Codec) ( *Map, uint32, int16, []byte) (any, error) {
if == nil {
return nil, nil
}
var int16
:= codecScan(, , , , , &)
if != nil {
return nil,
}
return , nil
}
type scanPlanBinaryInt2ToInt8 struct{}
func (scanPlanBinaryInt2ToInt8) ( []byte, any) error {
if == nil {
return fmt.Errorf("cannot scan NULL into %T", )
}
if len() != 2 {
return fmt.Errorf("invalid length for int2: %v", len())
}
, := ().(*int8)
if ! {
return ErrScanTargetTypeChanged
}
:= int16(binary.BigEndian.Uint16())
if < math.MinInt8 {
return fmt.Errorf("%d is less than minimum value for int8", )
} else if > math.MaxInt8 {
return fmt.Errorf("%d is greater than maximum value for int8", )
}
* = int8()
return nil
}
type scanPlanBinaryInt2ToUint8 struct{}
func (scanPlanBinaryInt2ToUint8) ( []byte, any) error {
if == nil {
return fmt.Errorf("cannot scan NULL into %T", )
}
if len() != 2 {
return fmt.Errorf("invalid length for uint2: %v", len())
}
, := ().(*uint8)
if ! {
return ErrScanTargetTypeChanged
}
:= int16(binary.BigEndian.Uint16())
if < 0 {
return fmt.Errorf("%d is less than minimum value for uint8", )
}
if > math.MaxUint8 {
return fmt.Errorf("%d is greater than maximum value for uint8", )
}
* = uint8()
return nil
}
type scanPlanBinaryInt2ToInt16 struct{}
func (scanPlanBinaryInt2ToInt16) ( []byte, any) error {
if == nil {
return fmt.Errorf("cannot scan NULL into %T", )
}
if len() != 2 {
return fmt.Errorf("invalid length for int2: %v", len())
}
, := ().(*int16)
if ! {
return ErrScanTargetTypeChanged
}
* = int16(binary.BigEndian.Uint16())
return nil
}
type scanPlanBinaryInt2ToUint16 struct{}
func (scanPlanBinaryInt2ToUint16) ( []byte, any) error {
if == nil {
return fmt.Errorf("cannot scan NULL into %T", )
}
if len() != 2 {
return fmt.Errorf("invalid length for uint2: %v", len())
}
, := ().(*uint16)
if ! {
return ErrScanTargetTypeChanged
}
:= int16(binary.BigEndian.Uint16())
if < 0 {
return fmt.Errorf("%d is less than minimum value for uint16", )
}
* = uint16()
return nil
}
type scanPlanBinaryInt2ToInt32 struct{}
func (scanPlanBinaryInt2ToInt32) ( []byte, any) error {
if == nil {
return fmt.Errorf("cannot scan NULL into %T", )
}
if len() != 2 {
return fmt.Errorf("invalid length for int2: %v", len())
}
, := ().(*int32)
if ! {
return ErrScanTargetTypeChanged
}
* = int32(int16(binary.BigEndian.Uint16()))
return nil
}
type scanPlanBinaryInt2ToUint32 struct{}
func (scanPlanBinaryInt2ToUint32) ( []byte, any) error {
if == nil {
return fmt.Errorf("cannot scan NULL into %T", )
}
if len() != 2 {
return fmt.Errorf("invalid length for uint2: %v", len())
}
, := ().(*uint32)
if ! {
return ErrScanTargetTypeChanged
}
:= int16(binary.BigEndian.Uint16())
if < 0 {
return fmt.Errorf("%d is less than minimum value for uint32", )
}
* = uint32()
return nil
}
type scanPlanBinaryInt2ToInt64 struct{}
func (scanPlanBinaryInt2ToInt64) ( []byte, any) error {
if == nil {
return fmt.Errorf("cannot scan NULL into %T", )
}
if len() != 2 {
return fmt.Errorf("invalid length for int2: %v", len())
}
, := ().(*int64)
if ! {
return ErrScanTargetTypeChanged
}
* = int64(int16(binary.BigEndian.Uint16()))
return nil
}
type scanPlanBinaryInt2ToUint64 struct{}
func (scanPlanBinaryInt2ToUint64) ( []byte, any) error {
if == nil {
return fmt.Errorf("cannot scan NULL into %T", )
}
if len() != 2 {
return fmt.Errorf("invalid length for uint2: %v", len())
}
, := ().(*uint64)
if ! {
return ErrScanTargetTypeChanged
}
:= int16(binary.BigEndian.Uint16())
if < 0 {
return fmt.Errorf("%d is less than minimum value for uint64", )
}
* = uint64()
return nil
}
type scanPlanBinaryInt2ToInt struct{}
func (scanPlanBinaryInt2ToInt) ( []byte, any) error {
if == nil {
return fmt.Errorf("cannot scan NULL into %T", )
}
if len() != 2 {
return fmt.Errorf("invalid length for int2: %v", len())
}
, := ().(*int)
if ! {
return ErrScanTargetTypeChanged
}
* = int(int16(binary.BigEndian.Uint16()))
return nil
}
type scanPlanBinaryInt2ToUint struct{}
func (scanPlanBinaryInt2ToUint) ( []byte, any) error {
if == nil {
return fmt.Errorf("cannot scan NULL into %T", )
}
if len() != 2 {
return fmt.Errorf("invalid length for uint2: %v", len())
}
, := ().(*uint)
if ! {
return ErrScanTargetTypeChanged
}
:= int64(int16(binary.BigEndian.Uint16()))
if < 0 {
return fmt.Errorf("%d is less than minimum value for uint", )
}
* = uint()
return nil
}
type scanPlanBinaryInt2ToInt64Scanner struct{}
func (scanPlanBinaryInt2ToInt64Scanner) ( []byte, any) error {
, := ().(Int64Scanner)
if ! {
return ErrScanTargetTypeChanged
}
if == nil {
return .ScanInt64(Int8{})
}
if len() != 2 {
return fmt.Errorf("invalid length for int2: %v", len())
}
:= int64(int16(binary.BigEndian.Uint16()))
return .ScanInt64(Int8{Int64: , Valid: true})
}
type scanPlanBinaryInt2ToTextScanner struct{}
func (scanPlanBinaryInt2ToTextScanner) ( []byte, any) error {
, := ().(TextScanner)
if ! {
return ErrScanTargetTypeChanged
}
if == nil {
return .ScanText(Text{})
}
if len() != 2 {
return fmt.Errorf("invalid length for int2: %v", len())
}
:= int64(int16(binary.BigEndian.Uint16()))
return .ScanText(Text{String: strconv.FormatInt(, 10), Valid: true})
}
type Int4 struct {
Int32 int32
Valid bool
}
func ( *Int4) ( Int8) error {
if !.Valid {
* = Int4{}
return nil
}
if .Int64 < math.MinInt32 {
return fmt.Errorf("%d is less than minimum value for Int4", .Int64)
}
if .Int64 > math.MaxInt32 {
return fmt.Errorf("%d is greater than maximum value for Int4", .Int64)
}
* = Int4{Int32: int32(.Int64), Valid: true}
return nil
}
func ( Int4) () (Int8, error) {
return Int8{Int64: int64(.Int32), Valid: .Valid}, nil
}
func ( *Int4) ( any) error {
if == nil {
* = Int4{}
return nil
}
var int64
switch src := .(type) {
case int64:
=
case string:
var error
, = strconv.ParseInt(, 10, 32)
if != nil {
return
}
case []byte:
var error
, = strconv.ParseInt(string(), 10, 32)
if != nil {
return
}
default:
return fmt.Errorf("cannot scan %T", )
}
if < math.MinInt32 {
return fmt.Errorf("%d is less than minimum value for Int4", )
}
if > math.MaxInt32 {
return fmt.Errorf("%d is greater than maximum value for Int4", )
}
* = Int4{Int32: int32(), Valid: true}
return nil
}
func ( Int4) () (driver.Value, error) {
if !.Valid {
return nil, nil
}
return int64(.Int32), nil
}
func ( Int4) () ([]byte, error) {
if !.Valid {
return []byte("null"), nil
}
return []byte(strconv.FormatInt(int64(.Int32), 10)), nil
}
func ( *Int4) ( []byte) error {
var *int32
:= json.Unmarshal(, &)
if != nil {
return
}
if == nil {
* = Int4{}
} else {
* = Int4{Int32: *, Valid: true}
}
return nil
}
type Int4Codec struct{}
func (Int4Codec) ( int16) bool {
return == TextFormatCode || == BinaryFormatCode
}
func (Int4Codec) () int16 {
return BinaryFormatCode
}
func (Int4Codec) ( *Map, uint32, int16, any) EncodePlan {
switch {
case BinaryFormatCode:
switch .(type) {
case int32:
return encodePlanInt4CodecBinaryInt32{}
case Int64Valuer:
return encodePlanInt4CodecBinaryInt64Valuer{}
}
case TextFormatCode:
switch .(type) {
case int32:
return encodePlanInt4CodecTextInt32{}
case Int64Valuer:
return encodePlanInt4CodecTextInt64Valuer{}
}
}
return nil
}
type encodePlanInt4CodecBinaryInt32 struct{}
func (encodePlanInt4CodecBinaryInt32) ( any, []byte) ( []byte, error) {
:= .(int32)
return pgio.AppendInt32(, int32()), nil
}
type encodePlanInt4CodecTextInt32 struct{}
func (encodePlanInt4CodecTextInt32) ( any, []byte) ( []byte, error) {
:= .(int32)
return append(, strconv.FormatInt(int64(), 10)...), nil
}
type encodePlanInt4CodecBinaryInt64Valuer struct{}
func (encodePlanInt4CodecBinaryInt64Valuer) ( any, []byte) ( []byte, error) {
, := .(Int64Valuer).Int64Value()
if != nil {
return nil,
}
if !.Valid {
return nil, nil
}
if .Int64 > math.MaxInt32 {
return nil, fmt.Errorf("%d is greater than maximum value for int4", .Int64)
}
if .Int64 < math.MinInt32 {
return nil, fmt.Errorf("%d is less than minimum value for int4", .Int64)
}
return pgio.AppendInt32(, int32(.Int64)), nil
}
type encodePlanInt4CodecTextInt64Valuer struct{}
func (encodePlanInt4CodecTextInt64Valuer) ( any, []byte) ( []byte, error) {
, := .(Int64Valuer).Int64Value()
if != nil {
return nil,
}
if !.Valid {
return nil, nil
}
if .Int64 > math.MaxInt32 {
return nil, fmt.Errorf("%d is greater than maximum value for int4", .Int64)
}
if .Int64 < math.MinInt32 {
return nil, fmt.Errorf("%d is less than minimum value for int4", .Int64)
}
return append(, strconv.FormatInt(.Int64, 10)...), nil
}
func (Int4Codec) ( *Map, uint32, int16, any) ScanPlan {
switch {
case BinaryFormatCode:
switch .(type) {
case *int8:
return scanPlanBinaryInt4ToInt8{}
case *int16:
return scanPlanBinaryInt4ToInt16{}
case *int32:
return scanPlanBinaryInt4ToInt32{}
case *int64:
return scanPlanBinaryInt4ToInt64{}
case *int:
return scanPlanBinaryInt4ToInt{}
case *uint8:
return scanPlanBinaryInt4ToUint8{}
case *uint16:
return scanPlanBinaryInt4ToUint16{}
case *uint32:
return scanPlanBinaryInt4ToUint32{}
case *uint64:
return scanPlanBinaryInt4ToUint64{}
case *uint:
return scanPlanBinaryInt4ToUint{}
case Int64Scanner:
return scanPlanBinaryInt4ToInt64Scanner{}
case TextScanner:
return scanPlanBinaryInt4ToTextScanner{}
}
case TextFormatCode:
switch .(type) {
case *int8:
return scanPlanTextAnyToInt8{}
case *int16:
return scanPlanTextAnyToInt16{}
case *int32:
return scanPlanTextAnyToInt32{}
case *int64:
return scanPlanTextAnyToInt64{}
case *int:
return scanPlanTextAnyToInt{}
case *uint8:
return scanPlanTextAnyToUint8{}
case *uint16:
return scanPlanTextAnyToUint16{}
case *uint32:
return scanPlanTextAnyToUint32{}
case *uint64:
return scanPlanTextAnyToUint64{}
case *uint:
return scanPlanTextAnyToUint{}
case Int64Scanner:
return scanPlanTextAnyToInt64Scanner{}
}
}
return nil
}
func ( Int4Codec) ( *Map, uint32, int16, []byte) (driver.Value, error) {
if == nil {
return nil, nil
}
var int64
:= codecScan(, , , , , &)
if != nil {
return nil,
}
return , nil
}
func ( Int4Codec) ( *Map, uint32, int16, []byte) (any, error) {
if == nil {
return nil, nil
}
var int32
:= codecScan(, , , , , &)
if != nil {
return nil,
}
return , nil
}
type scanPlanBinaryInt4ToInt8 struct{}
func (scanPlanBinaryInt4ToInt8) ( []byte, any) error {
if == nil {
return fmt.Errorf("cannot scan NULL into %T", )
}
if len() != 4 {
return fmt.Errorf("invalid length for int4: %v", len())
}
, := ().(*int8)
if ! {
return ErrScanTargetTypeChanged
}
:= int32(binary.BigEndian.Uint32())
if < math.MinInt8 {
return fmt.Errorf("%d is less than minimum value for int8", )
} else if > math.MaxInt8 {
return fmt.Errorf("%d is greater than maximum value for int8", )
}
* = int8()
return nil
}
type scanPlanBinaryInt4ToUint8 struct{}
func (scanPlanBinaryInt4ToUint8) ( []byte, any) error {
if == nil {
return fmt.Errorf("cannot scan NULL into %T", )
}
if len() != 4 {
return fmt.Errorf("invalid length for uint4: %v", len())
}
, := ().(*uint8)
if ! {
return ErrScanTargetTypeChanged
}
:= int32(binary.BigEndian.Uint32())
if < 0 {
return fmt.Errorf("%d is less than minimum value for uint8", )
}
if > math.MaxUint8 {
return fmt.Errorf("%d is greater than maximum value for uint8", )
}
* = uint8()
return nil
}
type scanPlanBinaryInt4ToInt16 struct{}
func (scanPlanBinaryInt4ToInt16) ( []byte, any) error {
if == nil {
return fmt.Errorf("cannot scan NULL into %T", )
}
if len() != 4 {
return fmt.Errorf("invalid length for int4: %v", len())
}
, := ().(*int16)
if ! {
return ErrScanTargetTypeChanged
}
:= int32(binary.BigEndian.Uint32())
if < math.MinInt16 {
return fmt.Errorf("%d is less than minimum value for int16", )
} else if > math.MaxInt16 {
return fmt.Errorf("%d is greater than maximum value for int16", )
}
* = int16()
return nil
}
type scanPlanBinaryInt4ToUint16 struct{}
func (scanPlanBinaryInt4ToUint16) ( []byte, any) error {
if == nil {
return fmt.Errorf("cannot scan NULL into %T", )
}
if len() != 4 {
return fmt.Errorf("invalid length for uint4: %v", len())
}
, := ().(*uint16)
if ! {
return ErrScanTargetTypeChanged
}
:= int32(binary.BigEndian.Uint32())
if < 0 {
return fmt.Errorf("%d is less than minimum value for uint16", )
}
if > math.MaxUint16 {
return fmt.Errorf("%d is greater than maximum value for uint16", )
}
* = uint16()
return nil
}
type scanPlanBinaryInt4ToInt32 struct{}
func (scanPlanBinaryInt4ToInt32) ( []byte, any) error {
if == nil {
return fmt.Errorf("cannot scan NULL into %T", )
}
if len() != 4 {
return fmt.Errorf("invalid length for int4: %v", len())
}
, := ().(*int32)
if ! {
return ErrScanTargetTypeChanged
}
* = int32(binary.BigEndian.Uint32())
return nil
}
type scanPlanBinaryInt4ToUint32 struct{}
func (scanPlanBinaryInt4ToUint32) ( []byte, any) error {
if == nil {
return fmt.Errorf("cannot scan NULL into %T", )
}
if len() != 4 {
return fmt.Errorf("invalid length for uint4: %v", len())
}
, := ().(*uint32)
if ! {
return ErrScanTargetTypeChanged
}
:= int32(binary.BigEndian.Uint32())
if < 0 {
return fmt.Errorf("%d is less than minimum value for uint32", )
}
* = uint32()
return nil
}
type scanPlanBinaryInt4ToInt64 struct{}
func (scanPlanBinaryInt4ToInt64) ( []byte, any) error {
if == nil {
return fmt.Errorf("cannot scan NULL into %T", )
}
if len() != 4 {
return fmt.Errorf("invalid length for int4: %v", len())
}
, := ().(*int64)
if ! {
return ErrScanTargetTypeChanged
}
* = int64(int32(binary.BigEndian.Uint32()))
return nil
}
type scanPlanBinaryInt4ToUint64 struct{}
func (scanPlanBinaryInt4ToUint64) ( []byte, any) error {
if == nil {
return fmt.Errorf("cannot scan NULL into %T", )
}
if len() != 4 {
return fmt.Errorf("invalid length for uint4: %v", len())
}
, := ().(*uint64)
if ! {
return ErrScanTargetTypeChanged
}
:= int32(binary.BigEndian.Uint32())
if < 0 {
return fmt.Errorf("%d is less than minimum value for uint64", )
}
* = uint64()
return nil
}
type scanPlanBinaryInt4ToInt struct{}
func (scanPlanBinaryInt4ToInt) ( []byte, any) error {
if == nil {
return fmt.Errorf("cannot scan NULL into %T", )
}
if len() != 4 {
return fmt.Errorf("invalid length for int4: %v", len())
}
, := ().(*int)
if ! {
return ErrScanTargetTypeChanged
}
* = int(int32(binary.BigEndian.Uint32()))
return nil
}
type scanPlanBinaryInt4ToUint struct{}
func (scanPlanBinaryInt4ToUint) ( []byte, any) error {
if == nil {
return fmt.Errorf("cannot scan NULL into %T", )
}
if len() != 4 {
return fmt.Errorf("invalid length for uint4: %v", len())
}
, := ().(*uint)
if ! {
return ErrScanTargetTypeChanged
}
:= int64(int32(binary.BigEndian.Uint32()))
if < 0 {
return fmt.Errorf("%d is less than minimum value for uint", )
}
* = uint()
return nil
}
type scanPlanBinaryInt4ToInt64Scanner struct{}
func (scanPlanBinaryInt4ToInt64Scanner) ( []byte, any) error {
, := ().(Int64Scanner)
if ! {
return ErrScanTargetTypeChanged
}
if == nil {
return .ScanInt64(Int8{})
}
if len() != 4 {
return fmt.Errorf("invalid length for int4: %v", len())
}
:= int64(int32(binary.BigEndian.Uint32()))
return .ScanInt64(Int8{Int64: , Valid: true})
}
type scanPlanBinaryInt4ToTextScanner struct{}
func (scanPlanBinaryInt4ToTextScanner) ( []byte, any) error {
, := ().(TextScanner)
if ! {
return ErrScanTargetTypeChanged
}
if == nil {
return .ScanText(Text{})
}
if len() != 4 {
return fmt.Errorf("invalid length for int4: %v", len())
}
:= int64(int32(binary.BigEndian.Uint32()))
return .ScanText(Text{String: strconv.FormatInt(, 10), Valid: true})
}
type Int8 struct {
Int64 int64
Valid bool
}
func ( *Int8) ( Int8) error {
if !.Valid {
* = Int8{}
return nil
}
if .Int64 < math.MinInt64 {
return fmt.Errorf("%d is less than minimum value for Int8", .Int64)
}
if .Int64 > math.MaxInt64 {
return fmt.Errorf("%d is greater than maximum value for Int8", .Int64)
}
* = Int8{Int64: int64(.Int64), Valid: true}
return nil
}
func ( Int8) () (Int8, error) {
return Int8{Int64: int64(.Int64), Valid: .Valid}, nil
}
func ( *Int8) ( any) error {
if == nil {
* = Int8{}
return nil
}
var int64
switch src := .(type) {
case int64:
=
case string:
var error
, = strconv.ParseInt(, 10, 64)
if != nil {
return
}
case []byte:
var error
, = strconv.ParseInt(string(), 10, 64)
if != nil {
return
}
default:
return fmt.Errorf("cannot scan %T", )
}
if < math.MinInt64 {
return fmt.Errorf("%d is greater than maximum value for Int8", )
}
if > math.MaxInt64 {
return fmt.Errorf("%d is greater than maximum value for Int8", )
}
* = Int8{Int64: int64(), Valid: true}
return nil
}
func ( Int8) () (driver.Value, error) {
if !.Valid {
return nil, nil
}
return int64(.Int64), nil
}
func ( Int8) () ([]byte, error) {
if !.Valid {
return []byte("null"), nil
}
return []byte(strconv.FormatInt(int64(.Int64), 10)), nil
}
func ( *Int8) ( []byte) error {
var *int64
:= json.Unmarshal(, &)
if != nil {
return
}
if == nil {
* = Int8{}
} else {
* = Int8{Int64: *, Valid: true}
}
return nil
}
type Int8Codec struct{}
func (Int8Codec) ( int16) bool {
return == TextFormatCode || == BinaryFormatCode
}
func (Int8Codec) () int16 {
return BinaryFormatCode
}
func (Int8Codec) ( *Map, uint32, int16, any) EncodePlan {
switch {
case BinaryFormatCode:
switch .(type) {
case int64:
return encodePlanInt8CodecBinaryInt64{}
case Int64Valuer:
return encodePlanInt8CodecBinaryInt64Valuer{}
}
case TextFormatCode:
switch .(type) {
case int64:
return encodePlanInt8CodecTextInt64{}
case Int64Valuer:
return encodePlanInt8CodecTextInt64Valuer{}
}
}
return nil
}
type encodePlanInt8CodecBinaryInt64 struct{}
func (encodePlanInt8CodecBinaryInt64) ( any, []byte) ( []byte, error) {
:= .(int64)
return pgio.AppendInt64(, int64()), nil
}
type encodePlanInt8CodecTextInt64 struct{}
func (encodePlanInt8CodecTextInt64) ( any, []byte) ( []byte, error) {
:= .(int64)
return append(, strconv.FormatInt(int64(), 10)...), nil
}
type encodePlanInt8CodecBinaryInt64Valuer struct{}
func (encodePlanInt8CodecBinaryInt64Valuer) ( any, []byte) ( []byte, error) {
, := .(Int64Valuer).Int64Value()
if != nil {
return nil,
}
if !.Valid {
return nil, nil
}
if .Int64 > math.MaxInt64 {
return nil, fmt.Errorf("%d is greater than maximum value for int8", .Int64)
}
if .Int64 < math.MinInt64 {
return nil, fmt.Errorf("%d is less than minimum value for int8", .Int64)
}
return pgio.AppendInt64(, int64(.Int64)), nil
}
type encodePlanInt8CodecTextInt64Valuer struct{}
func (encodePlanInt8CodecTextInt64Valuer) ( any, []byte) ( []byte, error) {
, := .(Int64Valuer).Int64Value()
if != nil {
return nil,
}
if !.Valid {
return nil, nil
}
if .Int64 > math.MaxInt64 {
return nil, fmt.Errorf("%d is greater than maximum value for int8", .Int64)
}
if .Int64 < math.MinInt64 {
return nil, fmt.Errorf("%d is less than minimum value for int8", .Int64)
}
return append(, strconv.FormatInt(.Int64, 10)...), nil
}
func (Int8Codec) ( *Map, uint32, int16, any) ScanPlan {
switch {
case BinaryFormatCode:
switch .(type) {
case *int8:
return scanPlanBinaryInt8ToInt8{}
case *int16:
return scanPlanBinaryInt8ToInt16{}
case *int32:
return scanPlanBinaryInt8ToInt32{}
case *int64:
return scanPlanBinaryInt8ToInt64{}
case *int:
return scanPlanBinaryInt8ToInt{}
case *uint8:
return scanPlanBinaryInt8ToUint8{}
case *uint16:
return scanPlanBinaryInt8ToUint16{}
case *uint32:
return scanPlanBinaryInt8ToUint32{}
case *uint64:
return scanPlanBinaryInt8ToUint64{}
case *uint:
return scanPlanBinaryInt8ToUint{}
case Int64Scanner:
return scanPlanBinaryInt8ToInt64Scanner{}
case TextScanner:
return scanPlanBinaryInt8ToTextScanner{}
}
case TextFormatCode:
switch .(type) {
case *int8:
return scanPlanTextAnyToInt8{}
case *int16:
return scanPlanTextAnyToInt16{}
case *int32:
return scanPlanTextAnyToInt32{}
case *int64:
return scanPlanTextAnyToInt64{}
case *int:
return scanPlanTextAnyToInt{}
case *uint8:
return scanPlanTextAnyToUint8{}
case *uint16:
return scanPlanTextAnyToUint16{}
case *uint32:
return scanPlanTextAnyToUint32{}
case *uint64:
return scanPlanTextAnyToUint64{}
case *uint:
return scanPlanTextAnyToUint{}
case Int64Scanner:
return scanPlanTextAnyToInt64Scanner{}
}
}
return nil
}
func ( Int8Codec) ( *Map, uint32, int16, []byte) (driver.Value, error) {
if == nil {
return nil, nil
}
var int64
:= codecScan(, , , , , &)
if != nil {
return nil,
}
return , nil
}
func ( Int8Codec) ( *Map, uint32, int16, []byte) (any, error) {
if == nil {
return nil, nil
}
var int64
:= codecScan(, , , , , &)
if != nil {
return nil,
}
return , nil
}
type scanPlanBinaryInt8ToInt8 struct{}
func (scanPlanBinaryInt8ToInt8) ( []byte, any) error {
if == nil {
return fmt.Errorf("cannot scan NULL into %T", )
}
if len() != 8 {
return fmt.Errorf("invalid length for int8: %v", len())
}
, := ().(*int8)
if ! {
return ErrScanTargetTypeChanged
}
:= int64(binary.BigEndian.Uint64())
if < math.MinInt8 {
return fmt.Errorf("%d is less than minimum value for int8", )
} else if > math.MaxInt8 {
return fmt.Errorf("%d is greater than maximum value for int8", )
}
* = int8()
return nil
}
type scanPlanBinaryInt8ToUint8 struct{}
func (scanPlanBinaryInt8ToUint8) ( []byte, any) error {
if == nil {
return fmt.Errorf("cannot scan NULL into %T", )
}
if len() != 8 {
return fmt.Errorf("invalid length for uint8: %v", len())
}
, := ().(*uint8)
if ! {
return ErrScanTargetTypeChanged
}
:= int64(binary.BigEndian.Uint64())
if < 0 {
return fmt.Errorf("%d is less than minimum value for uint8", )
}
if > math.MaxUint8 {
return fmt.Errorf("%d is greater than maximum value for uint8", )
}
* = uint8()
return nil
}
type scanPlanBinaryInt8ToInt16 struct{}
func (scanPlanBinaryInt8ToInt16) ( []byte, any) error {
if == nil {
return fmt.Errorf("cannot scan NULL into %T", )
}
if len() != 8 {
return fmt.Errorf("invalid length for int8: %v", len())
}
, := ().(*int16)
if ! {
return ErrScanTargetTypeChanged
}
:= int64(binary.BigEndian.Uint64())
if < math.MinInt16 {
return fmt.Errorf("%d is less than minimum value for int16", )
} else if > math.MaxInt16 {
return fmt.Errorf("%d is greater than maximum value for int16", )
}
* = int16()
return nil
}
type scanPlanBinaryInt8ToUint16 struct{}
func (scanPlanBinaryInt8ToUint16) ( []byte, any) error {
if == nil {
return fmt.Errorf("cannot scan NULL into %T", )
}
if len() != 8 {
return fmt.Errorf("invalid length for uint8: %v", len())
}
, := ().(*uint16)
if ! {
return ErrScanTargetTypeChanged
}
:= int64(binary.BigEndian.Uint64())
if < 0 {
return fmt.Errorf("%d is less than minimum value for uint16", )
}
if > math.MaxUint16 {
return fmt.Errorf("%d is greater than maximum value for uint16", )
}
* = uint16()
return nil
}
type scanPlanBinaryInt8ToInt32 struct{}
func (scanPlanBinaryInt8ToInt32) ( []byte, any) error {
if == nil {
return fmt.Errorf("cannot scan NULL into %T", )
}
if len() != 8 {
return fmt.Errorf("invalid length for int8: %v", len())
}
, := ().(*int32)
if ! {
return ErrScanTargetTypeChanged
}
:= int64(binary.BigEndian.Uint64())
if < math.MinInt32 {
return fmt.Errorf("%d is less than minimum value for int32", )
} else if > math.MaxInt32 {
return fmt.Errorf("%d is greater than maximum value for int32", )
}
* = int32()
return nil
}
type scanPlanBinaryInt8ToUint32 struct{}
func (scanPlanBinaryInt8ToUint32) ( []byte, any) error {
if == nil {
return fmt.Errorf("cannot scan NULL into %T", )
}
if len() != 8 {
return fmt.Errorf("invalid length for uint8: %v", len())
}
, := ().(*uint32)
if ! {
return ErrScanTargetTypeChanged
}
:= int64(binary.BigEndian.Uint64())
if < 0 {
return fmt.Errorf("%d is less than minimum value for uint32", )
}
if > math.MaxUint32 {
return fmt.Errorf("%d is greater than maximum value for uint32", )
}
* = uint32()
return nil
}
type scanPlanBinaryInt8ToInt64 struct{}
func (scanPlanBinaryInt8ToInt64) ( []byte, any) error {
if == nil {
return fmt.Errorf("cannot scan NULL into %T", )
}
if len() != 8 {
return fmt.Errorf("invalid length for int8: %v", len())
}
, := ().(*int64)
if ! {
return ErrScanTargetTypeChanged
}
* = int64(binary.BigEndian.Uint64())
return nil
}
type scanPlanBinaryInt8ToUint64 struct{}
func (scanPlanBinaryInt8ToUint64) ( []byte, any) error {
if == nil {
return fmt.Errorf("cannot scan NULL into %T", )
}
if len() != 8 {
return fmt.Errorf("invalid length for uint8: %v", len())
}
, := ().(*uint64)
if ! {
return ErrScanTargetTypeChanged
}
:= int64(binary.BigEndian.Uint64())
if < 0 {
return fmt.Errorf("%d is less than minimum value for uint64", )
}
* = uint64()
return nil
}
type scanPlanBinaryInt8ToInt struct{}
func (scanPlanBinaryInt8ToInt) ( []byte, any) error {
if == nil {
return fmt.Errorf("cannot scan NULL into %T", )
}
if len() != 8 {
return fmt.Errorf("invalid length for int8: %v", len())
}
, := ().(*int)
if ! {
return ErrScanTargetTypeChanged
}
:= int64(binary.BigEndian.Uint64())
if < math.MinInt {
return fmt.Errorf("%d is less than minimum value for int", )
} else if > math.MaxInt {
return fmt.Errorf("%d is greater than maximum value for int", )
}
* = int()
return nil
}
type scanPlanBinaryInt8ToUint struct{}
func (scanPlanBinaryInt8ToUint) ( []byte, any) error {
if == nil {
return fmt.Errorf("cannot scan NULL into %T", )
}
if len() != 8 {
return fmt.Errorf("invalid length for uint8: %v", len())
}
, := ().(*uint)
if ! {
return ErrScanTargetTypeChanged
}
:= int64(int64(binary.BigEndian.Uint64()))
if < 0 {
return fmt.Errorf("%d is less than minimum value for uint", )
}
if uint64() > math.MaxUint {
return fmt.Errorf("%d is greater than maximum value for uint", )
}
* = uint()
return nil
}
type scanPlanBinaryInt8ToInt64Scanner struct{}
func (scanPlanBinaryInt8ToInt64Scanner) ( []byte, any) error {
, := ().(Int64Scanner)
if ! {
return ErrScanTargetTypeChanged
}
if == nil {
return .ScanInt64(Int8{})
}
if len() != 8 {
return fmt.Errorf("invalid length for int8: %v", len())
}
:= int64(int64(binary.BigEndian.Uint64()))
return .ScanInt64(Int8{Int64: , Valid: true})
}
type scanPlanBinaryInt8ToTextScanner struct{}
func (scanPlanBinaryInt8ToTextScanner) ( []byte, any) error {
, := ().(TextScanner)
if ! {
return ErrScanTargetTypeChanged
}
if == nil {
return .ScanText(Text{})
}
if len() != 8 {
return fmt.Errorf("invalid length for int8: %v", len())
}
:= int64(int64(binary.BigEndian.Uint64()))
return .ScanText(Text{String: strconv.FormatInt(, 10), Valid: true})
}
type scanPlanTextAnyToInt8 struct{}
func (scanPlanTextAnyToInt8) ( []byte, any) error {
if == nil {
return fmt.Errorf("cannot scan NULL into %T", )
}
, := ().(*int8)
if ! {
return ErrScanTargetTypeChanged
}
, := strconv.ParseInt(string(), 10, 8)
if != nil {
return
}
* = int8()
return nil
}
type scanPlanTextAnyToUint8 struct{}
func (scanPlanTextAnyToUint8) ( []byte, any) error {
if == nil {
return fmt.Errorf("cannot scan NULL into %T", )
}
, := ().(*uint8)
if ! {
return ErrScanTargetTypeChanged
}
, := strconv.ParseUint(string(), 10, 8)
if != nil {
return
}
* = uint8()
return nil
}
type scanPlanTextAnyToInt16 struct{}
func (scanPlanTextAnyToInt16) ( []byte, any) error {
if == nil {
return fmt.Errorf("cannot scan NULL into %T", )
}
, := ().(*int16)
if ! {
return ErrScanTargetTypeChanged
}
, := strconv.ParseInt(string(), 10, 16)
if != nil {
return
}
* = int16()
return nil
}
type scanPlanTextAnyToUint16 struct{}
func (scanPlanTextAnyToUint16) ( []byte, any) error {
if == nil {
return fmt.Errorf("cannot scan NULL into %T", )
}
, := ().(*uint16)
if ! {
return ErrScanTargetTypeChanged
}
, := strconv.ParseUint(string(), 10, 16)
if != nil {
return
}
* = uint16()
return nil
}
type scanPlanTextAnyToInt32 struct{}
func (scanPlanTextAnyToInt32) ( []byte, any) error {
if == nil {
return fmt.Errorf("cannot scan NULL into %T", )
}
, := ().(*int32)
if ! {
return ErrScanTargetTypeChanged
}
, := strconv.ParseInt(string(), 10, 32)
if != nil {
return
}
* = int32()
return nil
}
type scanPlanTextAnyToUint32 struct{}
func (scanPlanTextAnyToUint32) ( []byte, any) error {
if == nil {
return fmt.Errorf("cannot scan NULL into %T", )
}
, := ().(*uint32)
if ! {
return ErrScanTargetTypeChanged
}
, := strconv.ParseUint(string(), 10, 32)
if != nil {
return
}
* = uint32()
return nil
}
type scanPlanTextAnyToInt64 struct{}
func (scanPlanTextAnyToInt64) ( []byte, any) error {
if == nil {
return fmt.Errorf("cannot scan NULL into %T", )
}
, := ().(*int64)
if ! {
return ErrScanTargetTypeChanged
}
, := strconv.ParseInt(string(), 10, 64)
if != nil {
return
}
* = int64()
return nil
}
type scanPlanTextAnyToUint64 struct{}
func (scanPlanTextAnyToUint64) ( []byte, any) error {
if == nil {
return fmt.Errorf("cannot scan NULL into %T", )
}
, := ().(*uint64)
if ! {
return ErrScanTargetTypeChanged
}
, := strconv.ParseUint(string(), 10, 64)
if != nil {
return
}
* = uint64()
return nil
}
type scanPlanTextAnyToInt struct{}
func (scanPlanTextAnyToInt) ( []byte, any) error {
if == nil {
return fmt.Errorf("cannot scan NULL into %T", )
}
, := ().(*int)
if ! {
return ErrScanTargetTypeChanged
}
, := strconv.ParseInt(string(), 10, 0)
if != nil {
return
}
* = int()
return nil
}
type scanPlanTextAnyToUint struct{}
func (scanPlanTextAnyToUint) ( []byte, any) error {
if == nil {
return fmt.Errorf("cannot scan NULL into %T", )
}
, := ().(*uint)
if ! {
return ErrScanTargetTypeChanged
}
, := strconv.ParseUint(string(), 10, 0)
if != nil {
return
}
* = uint()
return nil
}
type scanPlanTextAnyToInt64Scanner struct{}
func (scanPlanTextAnyToInt64Scanner) ( []byte, any) error {
, := ().(Int64Scanner)
if ! {
return ErrScanTargetTypeChanged
}
if == nil {
return .ScanInt64(Int8{})
}
, := strconv.ParseInt(string(), 10, 64)
if != nil {
return
}
= .ScanInt64(Int8{Int64: , Valid: true})
if != nil {
return
}
return nil
}