Search in sources :

Example 1 with MySQLRowImpl

use of io.vertx.mysqlclient.impl.MySQLRowImpl in project vertx-sql-client by eclipse-vertx.

the class RowResultDecoder method decodeRow.

@Override
protected Row decodeRow(int len, ByteBuf in) {
    Row row = new MySQLRowImpl(rowDesc);
    if (rowDesc.dataFormat() == DataFormat.BINARY) {
        // BINARY row decoding
        // 0x00 packet header
        // null_bitmap
        int nullBitmapLength = (len + 7 + 2) >> 3;
        int nullBitmapIdx = 1 + in.readerIndex();
        in.skipBytes(1 + nullBitmapLength);
        // values
        for (int c = 0; c < len; c++) {
            int val = c + 2;
            int bytePos = val >> 3;
            int bitPos = val & 7;
            byte mask = (byte) (1 << bitPos);
            byte nullByte = (byte) (in.getByte(nullBitmapIdx + bytePos) & mask);
            Object decoded = null;
            if (nullByte == 0) {
                // non-null
                ColumnDefinition columnDef = rowDesc.columnDefinitions()[c];
                DataType dataType = columnDef.type();
                int collationId = rowDesc.columnDefinitions()[c].characterSet();
                int columnDefinitionFlags = columnDef.flags();
                decoded = DataTypeCodec.decodeBinary(dataType, collationId, columnDefinitionFlags, in);
            }
            row.addValue(decoded);
        }
    } else {
        // TEXT row decoding
        for (int c = 0; c < len; c++) {
            Object decoded = null;
            if (in.getUnsignedByte(in.readerIndex()) == NULL) {
                in.skipBytes(1);
            } else {
                DataType dataType = rowDesc.columnDefinitions()[c].type();
                int columnDefinitionFlags = rowDesc.columnDefinitions()[c].flags();
                int collationId = rowDesc.columnDefinitions()[c].characterSet();
                decoded = DataTypeCodec.decodeText(dataType, collationId, columnDefinitionFlags, in);
            }
            row.addValue(decoded);
        }
    }
    return row;
}
Also used : MySQLRowImpl(io.vertx.mysqlclient.impl.MySQLRowImpl) DataType(io.vertx.mysqlclient.impl.datatype.DataType) Row(io.vertx.sqlclient.Row) ColumnDefinition(io.vertx.mysqlclient.impl.protocol.ColumnDefinition)

Example 2 with MySQLRowImpl

use of io.vertx.mysqlclient.impl.MySQLRowImpl in project Mycat2 by MyCATApache.

the class MycatVertxRowResultDecoder method decodeRow.

@Override
protected Row decodeRow(int len, ByteBuf in) {
    Row row = new MySQLRowImpl(rowDesc);
    if (rowDesc.dataFormat() == DataFormat.BINARY) {
        // BINARY row decoding
        // 0x00 packet header
        // null_bitmap
        int nullBitmapLength = (len + 7 + 2) >> 3;
        int nullBitmapIdx = 1 + in.readerIndex();
        in.skipBytes(1 + nullBitmapLength);
        // values
        for (int c = 0; c < len; c++) {
            int val = c + 2;
            int bytePos = val >> 3;
            int bitPos = val & 7;
            byte mask = (byte) (1 << bitPos);
            byte nullByte = (byte) (in.getByte(nullBitmapIdx + bytePos) & mask);
            Object decoded = null;
            if (nullByte == 0) {
                // non-null
                ColumnDefinition columnDef = rowDesc.columnDefinitions()[c];
                DataType dataType = columnDef.type();
                int collationId = rowDesc.columnDefinitions()[c].characterSet();
                int columnDefinitionFlags = columnDef.flags();
                decoded = DataTypeCodec.decodeBinary(dataType, collationId, columnDefinitionFlags, in);
            }
            row.addValue(decoded);
        }
    } else {
        // TEXT row decoding
        for (int c = 0; c < len; c++) {
            Object decoded = null;
            if (in.getUnsignedByte(in.readerIndex()) == NULL) {
                in.skipBytes(1);
            } else {
                DataType dataType = rowDesc.columnDefinitions()[c].type();
                int columnDefinitionFlags = rowDesc.columnDefinitions()[c].flags();
                int collationId = rowDesc.columnDefinitions()[c].characterSet();
                decoded = DataTypeCodec.decodeText(dataType, collationId, columnDefinitionFlags, in);
            }
            row.addValue(decoded);
        }
    }
    return row;
}
Also used : MySQLRowImpl(io.vertx.mysqlclient.impl.MySQLRowImpl) DataType(io.vertx.mysqlclient.impl.datatype.DataType) Row(io.vertx.sqlclient.Row) ColumnDefinition(io.vertx.mysqlclient.impl.protocol.ColumnDefinition)

Aggregations

MySQLRowImpl (io.vertx.mysqlclient.impl.MySQLRowImpl)2 DataType (io.vertx.mysqlclient.impl.datatype.DataType)2 ColumnDefinition (io.vertx.mysqlclient.impl.protocol.ColumnDefinition)2 Row (io.vertx.sqlclient.Row)2