public void encodeAsBinary()

in src/main/protocol-impl/java/com/mysql/cj/protocol/a/NumberValueEncoder.java [89:146]


    public void encodeAsBinary(Message msg, BindValue binding) {
        Number x = binding.getValue() instanceof BigDecimal ? getScaled((BigDecimal) binding.getValue(), binding.getScaleOrLength())
                : (Number) binding.getValue();

        NativePacketPayload intoPacket = (NativePacketPayload) msg;
        switch (binding.getMysqlType()) {
            case BIT:
            case BOOLEAN:
            case TINYINT:
            case TINYINT_UNSIGNED:
                intoPacket.writeInteger(IntegerDataType.INT1, x.longValue());
                return;
            case SMALLINT:
            case SMALLINT_UNSIGNED:
            case MEDIUMINT:
            case MEDIUMINT_UNSIGNED:
                intoPacket.writeInteger(IntegerDataType.INT2, x.longValue());
                return;
            case INT:
            case INT_UNSIGNED:
            case YEAR:
                intoPacket.writeInteger(IntegerDataType.INT4, x.longValue());
                return;
            case BIGINT:
            case BIGINT_UNSIGNED:
                intoPacket.writeInteger(IntegerDataType.INT8, x.longValue());
                return;
            case FLOAT:
            case FLOAT_UNSIGNED:
                intoPacket.writeInteger(IntegerDataType.INT4, Float.floatToIntBits(x.floatValue()));
                return;
            case DOUBLE:
            case DOUBLE_UNSIGNED:
                intoPacket.writeInteger(IntegerDataType.INT8, Double.doubleToLongBits(x.doubleValue()));
                return;
            case DECIMAL:
            case DECIMAL_UNSIGNED:
            case CHAR:
            case VARCHAR:
            case TINYTEXT:
            case TEXT:
            case MEDIUMTEXT:
            case LONGTEXT:
            case BINARY:
            case VARBINARY:
            case TINYBLOB:
            case BLOB:
            case MEDIUMBLOB:
            case LONGBLOB:
                intoPacket.writeBytes(StringSelfDataType.STRING_LENENC,
                        StringUtils.getBytes(x instanceof BigDecimal ? ((BigDecimal) x).toPlainString() : x.toString(), this.charEncoding.getValue()));
                return;
            default:
                throw ExceptionFactory.createException(WrongArgumentException.class,
                        Messages.getString("PreparedStatement.67", new Object[] { binding.getValue().getClass().getName(), binding.getMysqlType().toString() }),
                        this.exceptionInterceptor);
        }
    }