// https://github.com/jackc/pgx/issues/409 Changed JSON and JSONB to surface
// []byte to database/sql instead of string. But that caused problems with the
// simple protocol because the driver.Valuer case got taken before the
// pgtype.TextEncoder case. And driver.Valuer needed to be first in the usual
// case because of https://github.com/jackc/pgx/issues/339. So instead we
// special case JSON and JSONB.
case*pgtype.JSON:
buf,err:=arg.EncodeText(ci,nil)
iferr!=nil{
returnnil,err
}
ifbuf==nil{
returnnil,nil
}
returnstring(buf),nil
case*pgtype.JSONB:
buf,err:=arg.EncodeText(ci,nil)
iferr!=nil{
returnnil,err
}
ifbuf==nil{
returnnil,nil
}
returnstring(buf),nil
casedriver.Valuer:
returncallValuerValue(arg)
casepgtype.TextEncoder:
buf,err:=arg.EncodeText(ci,nil)
iferr!=nil{
returnnil,err
}
ifbuf==nil{
returnnil,nil
}
returnstring(buf),nil
caseint64:
returnarg,nil
casefloat64:
returnarg,nil
casebool:
returnarg,nil
casetime.Time:
returnarg,nil
casestring:
returnarg,nil
case[]byte:
returnarg,nil
caseint8:
returnint64(arg),nil
caseint16:
returnint64(arg),nil
caseint32:
returnint64(arg),nil
caseint:
returnint64(arg),nil
caseuint8:
returnint64(arg),nil
caseuint16:
returnint64(arg),nil
caseuint32:
returnint64(arg),nil
caseuint64:
ifarg>math.MaxInt64{
returnnil,errors.Errorf("arg too big for int64: %v",arg)
}
returnint64(arg),nil
caseuint:
ifuint64(arg)>math.MaxInt64{
returnnil,errors.Errorf("arg too big for int64: %v",arg)
}
returnint64(arg),nil
casefloat32:
returnfloat64(arg),nil
}
refVal:=reflect.ValueOf(arg)
ifrefVal.Kind()==reflect.Ptr{
ifrefVal.IsNil(){
returnnil,nil
}
arg=refVal.Elem().Interface()
returnconvertSimpleArgument(ci,arg)
}
ifstrippedArg,ok:=stripNamedType(&refVal);ok{
returnconvertSimpleArgument(ci,strippedArg)
}
returnnil,SerializationError(fmt.Sprintf("Cannot encode %T in simple protocol - %T must implement driver.Valuer, pgtype.TextEncoder, or be a native type",arg,arg))