Example usage for io.netty.buffer ByteBuf readMedium

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

Introduction

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

Prototype

public abstract int readMedium();

Source Link

Document

Gets a 24-bit medium integer at the current readerIndex and increases the readerIndex by 3 in this buffer.

Usage

From source file:com.digitalpetri.opcua.stack.core.channel.headers.SecureMessageHeader.java

License:Apache License

public static SecureMessageHeader decode(ByteBuf buffer) throws UaException {
    return new SecureMessageHeader(MessageType.fromMediumInt(buffer.readMedium()), (char) buffer.readByte(),
            buffer.readUnsignedInt(), buffer.readUnsignedInt());
}

From source file:com.digitalpetri.opcua.stack.core.channel.messages.TcpMessageDecoder.java

License:Apache License

public static HelloMessage decodeHello(ByteBuf buffer) throws UaException {
    MessageType messageType = MessageType.fromMediumInt(buffer.readMedium());
    char chunkType = (char) buffer.readByte();
    buffer.skipBytes(4); // length

    assert (messageType == MessageType.Hello && chunkType == 'F');

    return HelloMessage.decode(buffer);
}

From source file:com.digitalpetri.opcua.stack.core.channel.messages.TcpMessageDecoder.java

License:Apache License

public static AcknowledgeMessage decodeAcknowledge(ByteBuf buffer) throws UaException {
    MessageType messageType = MessageType.fromMediumInt(buffer.readMedium());
    char chunkType = (char) buffer.readByte();
    buffer.skipBytes(4); // length

    assert (messageType == MessageType.Acknowledge && chunkType == 'F');

    return AcknowledgeMessage.decode(buffer);
}

From source file:com.digitalpetri.opcua.stack.core.channel.messages.TcpMessageDecoder.java

License:Apache License

public static ErrorMessage decodeError(ByteBuf buffer) throws UaException {
    MessageType messageType = MessageType.fromMediumInt(buffer.readMedium());
    char chunkType = (char) buffer.readByte();
    buffer.skipBytes(4); // length

    assert (messageType == MessageType.Error && chunkType == 'F');

    return ErrorMessage.decode(buffer);
}

From source file:com.friz.lobby.network.codec.SocialDecoder.java

License:Open Source License

@Override
protected void decode(ChannelHandlerContext ctx, ByteBuf buf, List<Object> out) throws Exception {
    if (!buf.isReadable())
        return;/*w  w  w  .  j a  va 2 s. c om*/

    int type = buf.readUnsignedByte();
    int size = buf.readUnsignedShort();

    if (!buf.isReadable(size))
        return;

    byte[] xtea = new byte[size];
    buf.readBytes(xtea);
    ByteBuf xteaBuf = Unpooled.wrappedBuffer(new XTEA(xtea).decrypt(key).toByteArray());

    int game = xteaBuf.readUnsignedByte();
    int lang = xteaBuf.readUnsignedByte();
    int display = xteaBuf.readUnsignedByte();
    int width = xteaBuf.readUnsignedShort();
    int height = xteaBuf.readUnsignedShort();

    int multisample = xteaBuf.readByte();

    byte[] uid = new byte[24];
    for (int i = 0; i < uid.length; i++)
        uid[i] = xteaBuf.readByte();

    String gameToken = BufferUtils.getString(xteaBuf);

    int prefSize = xteaBuf.readUnsignedByte();
    int prefVersion = xteaBuf.readUnsignedByte();
    int aPref = xteaBuf.readUnsignedByte();
    int antiAliasing = xteaBuf.readUnsignedByte();
    int aPref1 = xteaBuf.readUnsignedByte();
    int bloom = xteaBuf.readUnsignedByte();
    int brightness = xteaBuf.readUnsignedByte();
    int buildArea = xteaBuf.readUnsignedByte();
    int aPref2 = xteaBuf.readUnsignedByte();
    int flickeringEffects = xteaBuf.readUnsignedByte();
    int fog = xteaBuf.readUnsignedByte();
    int groundBlending = xteaBuf.readUnsignedByte();
    int groundDecoration = xteaBuf.readUnsignedByte();
    int idleAnimations = xteaBuf.readUnsignedByte();
    int lighting = xteaBuf.readUnsignedByte();
    int sceneryShadows = xteaBuf.readUnsignedByte();
    int aPref3 = xteaBuf.readUnsignedByte();
    int nullPref = xteaBuf.readUnsignedByte();
    int orthoMode = xteaBuf.readUnsignedByte();
    int particles = xteaBuf.readUnsignedByte();
    int removeRoofs = xteaBuf.readUnsignedByte();
    int maxScreenSize = xteaBuf.readUnsignedByte();
    int skyboxes = xteaBuf.readUnsignedByte();
    int mobShadows = xteaBuf.readUnsignedByte();
    int textures = xteaBuf.readUnsignedByte();
    int desiredToolkit = xteaBuf.readUnsignedByte();
    int nullPref1 = xteaBuf.readUnsignedByte();
    int water = xteaBuf.readUnsignedByte();
    int screenSize = xteaBuf.readUnsignedByte();
    int customCursors = xteaBuf.readUnsignedByte();
    int graphics = xteaBuf.readUnsignedByte();
    int cpu = xteaBuf.readUnsignedByte();
    int aPref4 = xteaBuf.readUnsignedByte();
    int safeMode = xteaBuf.readUnsignedByte();
    int aPref5 = xteaBuf.readUnsignedByte();
    int aPref6 = xteaBuf.readUnsignedByte();
    int aPref7 = xteaBuf.readUnsignedByte();
    int soundEffectsVolume = xteaBuf.readUnsignedByte();
    int areaSoundsVolume = xteaBuf.readUnsignedByte();
    int voiceOverVolume = xteaBuf.readUnsignedByte();
    int musicVolume = xteaBuf.readUnsignedByte();
    int themeMusicVolume = xteaBuf.readUnsignedByte();
    int steroSound = xteaBuf.readUnsignedByte();
    xteaBuf.readMedium();
    xteaBuf.readMedium();

    int infoVersion = xteaBuf.readUnsignedByte();
    int osType = xteaBuf.readUnsignedByte();
    boolean arch64 = xteaBuf.readBoolean();
    int versionType = xteaBuf.readUnsignedByte();
    int vendorType = xteaBuf.readUnsignedByte();
    int jMajor = xteaBuf.readUnsignedByte();
    int jMinor = xteaBuf.readUnsignedByte();
    int jPatch = xteaBuf.readUnsignedByte();
    boolean falseBool = xteaBuf.readBoolean();
    int heapSize = xteaBuf.readUnsignedShort();
    int pocessorCount = xteaBuf.readUnsignedByte();
    int cpuPhyscialMemory = xteaBuf.readUnsignedMedium();
    int cpuClock = xteaBuf.readUnsignedShort();
    String gpuName = BufferUtils.getJagString(xteaBuf);
    String aString = BufferUtils.getJagString(xteaBuf);
    String dxVersion = BufferUtils.getJagString(xteaBuf);
    String aString1 = BufferUtils.getJagString(xteaBuf);
    int gpuDriverMonth = xteaBuf.readUnsignedByte();
    int gpuDriverYear = xteaBuf.readUnsignedShort();
    String cpuType = BufferUtils.getJagString(xteaBuf);
    String cpuName = BufferUtils.getJagString(xteaBuf);
    int cpuThreads = xteaBuf.readUnsignedByte();
    int anInt = xteaBuf.readUnsignedByte();
    int anInt1 = xteaBuf.readInt();
    int anInt2 = xteaBuf.readInt();
    int anInt3 = xteaBuf.readInt();
    int anInt4 = xteaBuf.readInt();
    String aString2 = BufferUtils.getJagString(xteaBuf);

    int anInt5 = xteaBuf.readInt();
    String seed = BufferUtils.getString(xteaBuf);
    int affiliate = xteaBuf.readInt();
    int anInt6 = xteaBuf.readInt();
    String updateToken = BufferUtils.getString(xteaBuf);
    int anInt7 = xteaBuf.readUnsignedByte();

    int[] checksums = new int[(xteaBuf.readableBytes() / 4) + 1];
    for (int i = 0; i < checksums.length; i++) {
        if (i == 32)
            checksums[i] = -1;
        else
            checksums[i] = xteaBuf.readInt();
    }

    System.out.println(seed);
}

From source file:com.quavo.osrs.game.model.entity.actor.player.info.LoginClearance.java

License:Open Source License

/**
 * Reads the data from a {@link ByteBuf} for a login clearance.
 * /*from w  w  w . j ava2s  .  c om*/
 * @param buffer The {@link ByteBuf}.
 */
public void readNoReturn(ByteBuf buffer) {
    switch (this) {
    case NORMAL:
        buffer.readerIndex(buffer.readerIndex() + 8);
        break;
    case TRUSTED_COMPUTER:
        buffer.readInt();
        buffer.readerIndex(buffer.readerIndex() + 4);
        break;
    case AUTHENTICATOR:
    case TRUSTED_AUTHENTICATOR:
        buffer.readMedium();
        buffer.readerIndex(buffer.readerIndex() + 5);
        break;
    }
}

From source file:com.quavo.osrs.game.model.entity.actor.player.info.LoginClearance.java

License:Open Source License

/**
 * Reads the data from a {@link ByteBuf} for a login clearance.
 * /*from  w  w  w.  ja  v  a  2 s . c  om*/
 * @param buffer The {@link ByteBuf}.
 * @return The created login clearance type.
 */
public LoginClearance read(ByteBuf buffer) {
    switch (this) {
    case NORMAL:
        buffer.readerIndex(buffer.readerIndex() + 8);
        break;
    case TRUSTED_COMPUTER:
        buffer.readInt();
        buffer.readerIndex(buffer.readerIndex() + 4);
        break;
    case AUTHENTICATOR:
    case TRUSTED_AUTHENTICATOR:
        buffer.readMedium();
        buffer.readerIndex(buffer.readerIndex() + 5);
        break;
    }
    return this;
}

From source file:com.quavo.osrs.game.model.entity.actor.player.info.MachineInformation.java

License:Open Source License

/**
 * Decodes the machine information of the user during the {@link WorldLoginDecoder}.
 * //  ww  w  .j a va2 s  . c o  m
 * @param buffer The {@link ByteBuf}.
 * @return The created machine information.
 */
public static MachineInformation decode(ByteBuf buffer) {
    buffer.readByte();
    int osArch = buffer.readByte();
    boolean is64Bit = buffer.readByte() == 1;
    int osBuild = buffer.readByte();
    int vendor = buffer.readByte();
    buffer.readByte();
    buffer.readByte();
    buffer.readByte();
    buffer.readByte();
    buffer.readShort();
    buffer.readByte();
    buffer.readMedium();
    buffer.readShort();
    ByteBufUtils.readJagString(buffer);
    ByteBufUtils.readJagString(buffer);
    ByteBufUtils.readJagString(buffer);
    ByteBufUtils.readJagString(buffer);
    buffer.readByte();
    buffer.readShort();
    ByteBufUtils.readJagString(buffer);
    ByteBufUtils.readJagString(buffer);
    buffer.readByte();
    buffer.readByte();
    return new MachineInformation(osArch, is64Bit, osBuild, vendor);
}

From source file:com.tesora.dve.db.mysql.portal.protocol.MysqlClientAuthenticationHandler.java

License:Open Source License

protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out, boolean isLastBytes)
        throws Exception {
    ByteBuf leBuf = in.order(ByteOrder.LITTLE_ENDIAN);

    leBuf.markReaderIndex();/*  ww w .ja  va 2s. c  o m*/
    boolean messageProcessed = false;

    try {
        if (leBuf.readableBytes() > MESSAGE_HEADER_LEN) {
            int payloadLen = leBuf.readMedium();
            leBuf.readByte(); // seq

            if (leBuf.readableBytes() >= payloadLen) {
                ByteBuf payload = leBuf.slice(leBuf.readerIndex(), payloadLen).order(ByteOrder.LITTLE_ENDIAN);
                Byte protocolVersion = leBuf.readByte();
                leBuf.skipBytes(payloadLen - 1);
                messageProcessed = true;

                if (state == AuthenticationState.AWAIT_GREETING)
                    processGreeting(ctx, payload, protocolVersion);
                else
                    processAcknowlegement(ctx, payload);
            }
        }

    } catch (Throwable t) {
        enterState(AuthenticationState.FAILURE);
        log.warn("Unexpected problem on outbound mysql connection.", t);
        throw t;
    } finally {
        if (!messageProcessed)
            leBuf.resetReaderIndex();

        if (isLastBytes && (state == AuthenticationState.AWAIT_ACKNOWLEGEMENT
                || state == AuthenticationState.AWAIT_GREETING)) {
            //we are waiting for handshake packets from mysql, but no more packets will ever arrive.  release blocked callers.
            Channel channel = ctx.channel();
            SocketAddress addr = (channel == null ? null : channel.remoteAddress());
            log.warn("Socket closed in middle of authentication handshake on socket " + addr);
            enterState(AuthenticationState.FAILURE);
        }
    }
}

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) + ")");
            }// w  ww.  j av  a2s.  co  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) + ")");
            }
        }
    }
}