Example usage for io.netty.buffer ByteBuf readUnsignedShort

List of usage examples for io.netty.buffer ByteBuf readUnsignedShort

Introduction

In this page you can find the example usage for io.netty.buffer ByteBuf readUnsignedShort.

Prototype

public abstract int readUnsignedShort();

Source Link

Document

Gets an unsigned 16-bit short integer at the current readerIndex and increases the readerIndex by 2 in this buffer.

Usage

From source file:com.tesora.dve.db.mysql.libmy.MyHandshakeV10.java

License:Open Source License

@Override
public void unmarshallMessage(ByteBuf cb) {
    protocolVersion = cb.readByte();//from w ww  .j  a va2s. c  o  m
    serverVersion = cb.readSlice(cb.bytesBefore((byte) 0)).toString(CharsetUtil.UTF_8);
    cb.skipBytes(1); // skip the NULL terminator
    threadID = cb.readInt();
    scrambleBuffer1st = MysqlAPIUtils.readBytesAsString(cb, 8, CharsetUtil.ISO_8859_1);
    cb.skipBytes(1);
    long sc1 = cb.readUnsignedShort();
    serverCharset = cb.readByte();
    serverStatus = cb.readShort();
    long sc2 = Long.rotateLeft(cb.readUnsignedShort(), 16);
    setServerCapabilities(sc1 + sc2);
    scrambleBufferSize = new Integer(cb.readByte());
    cb.skipBytes(10); //unused bytes
    scrambleBuffer2nd = cb.readSlice(cb.bytesBefore((byte) 0)).toString(CharsetUtil.ISO_8859_1);
    cb.skipBytes(1);
    if ((serverCapabilitiesasLong
            & ClientCapabilities.CLIENT_PLUGIN_AUTH) == ClientCapabilities.CLIENT_PLUGIN_AUTH) {
        plugInProvidedData = cb.readSlice(cb.bytesBefore((byte) 0)).toString(CharsetUtil.UTF_8);
    }
}

From source file:com.tesora.dve.db.mysql.libmy.MyOKResponse.java

License:Open Source License

@Override
public void unmarshallMessage(ByteBuf cb) {
    cb.readByte(); // field count - always 0
    affectedRows = MysqlAPIUtils.getLengthCodedLong(cb);
    insertId = MysqlAPIUtils.getLengthCodedLong(cb);
    serverStatus = cb.readUnsignedShort();
    warningCount = cb.readUnsignedShort();
    if (cb.isReadable())
        message = MysqlAPIUtils.readBytesAsString(cb, CharsetUtil.UTF_8);
}

From source file:com.tesora.dve.db.mysql.libmy.MyPrepareOKResponse.java

License:Open Source License

@Override
public void unmarshallMessage(ByteBuf cb) {
    cb.skipBytes(1);/*  w w w. j  a v  a2 s  .c  om*/
    stmtId = cb.readInt();
    numColumns = cb.readUnsignedShort();
    numParams = cb.readUnsignedShort();
    cb.skipBytes(1);
    warningCount = cb.readShort();
}

From source file:com.tesora.dve.mysqlapi.repl.messages.MyQueryLogEvent.java

License:Open Source License

@Override
public void unmarshallMessage(ByteBuf cb) throws PEException {

    // read event header
    slaveProxyId = cb.readUnsignedInt();
    execTime = cb.readUnsignedInt();/*from w  w w .  java2 s . co  m*/
    dbNameLen = cb.readByte();
    errorCode = cb.readUnsignedShort();
    statusVarsLen = cb.readUnsignedShort();

    statusVars.parseStatusVariables(cb, statusVarsLen);

    dbName = MysqlAPIUtils.readBytesAsString(cb, dbNameLen, CharsetUtil.UTF_8);
    cb.skipBytes(1); //for trailing 0
    query = Unpooled.buffer(cb.readableBytes());
    query.writeBytes(cb);
    origQuery = query.toString(CharsetUtil.UTF_8);
}

From source file:com.tesora.dve.mysqlapi.repl.messages.MyStatusVariables.java

License:Open Source License

public void parseStatusVariables(ByteBuf cb, int svLen) throws PEException {
    if (svLen > 0) {
        ByteBuf statsVarsBuf = cb.readBytes(svLen);
        while (statsVarsBuf.isReadable()) {
            byte code = statsVarsBuf.readByte();
            MyQueryEventCode mqec = MyQueryEventCode.fromByte(code);
            if (mqec == null) {
                throw new PEException("Replication could not decode query event code: '" + code + "' (0x"
                        + Integer.toHexString(code) + ")");
            }//from  www .ja v a  2 s.  c  o  m

            switch (mqec) {
            case Q_FLAGS2_CODE:
                int flags = statsVarsBuf.readInt();
                suppliedEventCodes.add(new QueryFlags2Event(flags));
                break;

            case Q_SQL_MODE_CODE:
                long sqlMode = statsVarsBuf.readLong();
                suppliedEventCodes.add(new QuerySQLModeEvent(sqlMode));
                break;

            case Q_CATALOG_CODE: {
                byte len = statsVarsBuf.readByte();
                String catalog = MysqlAPIUtils.readBytesAsString(statsVarsBuf, len, CharsetUtil.UTF_8);
                statsVarsBuf.readByte(); // null terminated byte

                suppliedEventCodes.add(new QueryCatalogEvent(catalog));
                break;
            }
            case Q_AUTO_INCREMENT:
                int autoIncrementIncrement = statsVarsBuf.readUnsignedShort();
                int autoIncrementOffset = statsVarsBuf.readUnsignedShort();

                suppliedEventCodes
                        .add(new QueryAutoIncrementEvent(autoIncrementIncrement, autoIncrementOffset));
                break;

            case Q_CHARSET_CODE:
                int charSetClient = statsVarsBuf.readUnsignedShort();
                int collationConnection = statsVarsBuf.readUnsignedShort();
                int collationServer = statsVarsBuf.readUnsignedShort();

                suppliedEventCodes
                        .add(new QueryCharSetCodeEvent(charSetClient, collationConnection, collationServer));
                break;

            case Q_TIME_ZONE_CODE: {
                byte len = statsVarsBuf.readByte();
                String timeZone = MysqlAPIUtils.readBytesAsString(statsVarsBuf, len, CharsetUtil.UTF_8);

                suppliedEventCodes.add(new QueryTimeZoneCodeEvent(timeZone));
                break;
            }
            case Q_CATALOG_NZ_CODE: {
                byte catalogLen = statsVarsBuf.readByte();
                String catalog = MysqlAPIUtils.readBytesAsString(statsVarsBuf, catalogLen, CharsetUtil.UTF_8);

                suppliedEventCodes.add(new QueryCatalogNZEvent(catalog));
                break;
            }
            case Q_LC_TIME_NAMES_CODE:
                short monthDayNames = statsVarsBuf.readShort();

                suppliedEventCodes.add(new QueryTimeNamesEvent(monthDayNames));
                break;

            case Q_CHARSET_DATABASE_CODE:
                short collationDatabase = statsVarsBuf.readShort();

                suppliedEventCodes.add(new QueryCollationDatabaseEvent(collationDatabase));
                break;

            case Q_TABLE_MAP_FOR_UPDATE_CODE:
                long tableMapForUpdate = statsVarsBuf.readLong();

                suppliedEventCodes.add(new QueryTableMapEvent(tableMapForUpdate));
                break;

            case Q_MASTER_DATA_WRITTEN_CODE:
                int originalLength = statsVarsBuf.readInt();

                suppliedEventCodes.add(new QueryMasterDataWrittenEvent(originalLength));
                break;

            case Q_INVOKER:
                int userLen = statsVarsBuf.readByte();
                String user = MysqlAPIUtils.readBytesAsString(statsVarsBuf, userLen, CharsetUtil.UTF_8);
                int hostLen = statsVarsBuf.readByte();
                String host = MysqlAPIUtils.readBytesAsString(statsVarsBuf, hostLen, CharsetUtil.UTF_8);

                suppliedEventCodes.add(new QueryInvokerEvent(user, host));
                break;

            case Q_UPDATED_DB_NAMES:
                List<String> dbNames = new ArrayList<String>();
                int numDbs = statsVarsBuf.readByte();
                if (numDbs > 0) {
                    for (int i = 0; i < numDbs; i++) {
                        dbNames.add(statsVarsBuf.readSlice(statsVarsBuf.bytesBefore((byte) 0))
                                .toString(CharsetUtil.UTF_8));
                        statsVarsBuf.readByte(); //read null byte
                    }
                }
                suppliedEventCodes.add(new QueryUpdatedDBNamesEvent(dbNames));
                break;

            case Q_MICROSECONDS:
                int microseconds = statsVarsBuf.readMedium();

                suppliedEventCodes.add(new QueryMicrosecondsEvent(microseconds));
                break;

            case Q_HRNOW:
                //TODO: this was apparently added for MariaDB, but I can't find a lot of info on it. skip for now.
                suppliedEventCodes.add(new QueryMicrosecondsEvent(statsVarsBuf.readUnsignedMedium()));
                break;

            default:
                throw new PEException("Replication encountered an unknown query event code: '" + code + "' (0x"
                        + Integer.toHexString(code) + ")");
            }
        }
    }
}

From source file:com.tesora.dve.mysqlapi.repl.messages.MyUserVarLogEvent.java

License:Open Source License

long readValue(ByteBuf decimalPortionBuf, int valueLen) throws PEException {
    if (valueLen < 1 || valueLen > 4)
        throw new PEException("Cannot decode decimal buffer.  Invalid read length of " + valueLen);

    long value = 0;
    if (valueLen == 4) {
        value = decimalPortionBuf.readUnsignedInt();
    } else if (valueLen == 3) {
        value = decimalPortionBuf.readUnsignedMedium();
    } else if (valueLen == 2) {
        value = decimalPortionBuf.readUnsignedShort();
    } else if (valueLen == 1) {
        value = decimalPortionBuf.readUnsignedByte();
    }//ww w  .ja va  2  s . co  m
    return value;
}

From source file:com.trinity.engine.protocol.detail.ConnectionReplayingDecoder.java

License:Apache License

/**
 * {@inheritDoc}/*from  www.j  av  a 2 s . c o m*/
 */
@Override
protected void decode(ChannelHandlerContext context, ByteBuf input, List<Object> output) throws Exception {
    switch (state()) {
    case READ_ID:
        mMessageId = input.readUnsignedByte();
        checkpoint(DecoderState.READ_LENGTH);
        break;
    case READ_LENGTH:
        mMessageLength = input.readUnsignedShort();
        checkpoint(DecoderState.READ_CONTENT);
        break;
    case READ_CONTENT:
        output.add(mLookupService.decode(mMessageId, input.readBytes(mMessageLength)));
        checkpoint(DecoderState.READ_ID);
    }
}

From source file:com.twitter.http2.HttpFrameEncoderTest.java

License:Apache License

private static void assertSettingsFrame(ByteBuf frame, boolean ack, int id, int value) {
    byte type = 0x04;
    byte flags = ack ? (byte) 0x01 : 0x00;
    int length = assertFrameHeader(frame, type, flags, 0);
    if (ack) {/*from w w  w .j a  v  a  2s .co  m*/
        assertEquals(0, length);
    } else {
        assertEquals(6, length);
        assertEquals(id, frame.readUnsignedShort());
        assertEquals(value, frame.readInt());
    }
    assertFalse(frame.isReadable());
}

From source file:com.uber.tchannel.codecs.CodecUtils.java

License:Open Source License

public static String decodeString(ByteBuf buffer) {
    int valueLength = buffer.readUnsignedShort();
    byte[] valueBytes = new byte[valueLength];
    buffer.readBytes(valueBytes);//  w  w  w  . j  a  v a2s. com
    return new String(valueBytes);
}

From source file:com.uber.tchannel.codecs.CodecUtils.java

License:Open Source License

public static Map<String, String> decodeHeaders(ByteBuf buffer) {

    int numHeaders = buffer.readUnsignedShort();
    Map<String, String> headers = new HashMap<String, String>(numHeaders);

    for (int i = 0; i < numHeaders; i++) {
        String key = CodecUtils.decodeString(buffer);
        String value = CodecUtils.decodeString(buffer);
        headers.put(key, value);/* ww  w  .j  a  va2 s. c om*/

    }

    return headers;

}