Example usage for io.netty.buffer ByteBuf getMediumLE

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

Introduction

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

Prototype

public abstract int getMediumLE(int index);

Source Link

Document

Gets a 24-bit medium integer at the specified absolute index in this buffer in the Little Endian Byte Order.

Usage

From source file:org.eclipse.milo.opcua.stack.client.transport.uasc.UascClientAcknowledgeHandler.java

License:Open Source License

@Override
protected void decode(ChannelHandlerContext ctx, ByteBuf buffer, List<Object> out) throws Exception {
    int maxChunkSize = config.getMessageLimits().getMaxChunkSize();

    while (buffer.readableBytes() >= HEADER_LENGTH) {
        int messageLength = getMessageLength(buffer, maxChunkSize);

        if (buffer.readableBytes() < messageLength) {
            break;
        }/*from  w  w  w .ja  v  a2 s. c o  m*/

        MessageType messageType = MessageType.fromMediumInt(buffer.getMediumLE(buffer.readerIndex()));

        switch (messageType) {
        case Acknowledge:
            onAcknowledge(ctx, buffer.readSlice(messageLength));
            break;

        case Error:
            onError(ctx, buffer.readSlice(messageLength));
            break;

        default:
            out.add(buffer.readSlice(messageLength).retain());
        }
    }
}

From source file:org.eclipse.milo.opcua.stack.client.transport.uasc.UascClientMessageHandler.java

License:Open Source License

private void decodeMessage(ChannelHandlerContext ctx, ByteBuf buffer) throws UaException {
    int messageLength = getMessageLength(buffer, maxChunkSize);
    MessageType messageType = MessageType.fromMediumInt(buffer.getMediumLE(buffer.readerIndex()));

    switch (messageType) {
    case OpenSecureChannel:
        onOpenSecureChannel(ctx, buffer.readSlice(messageLength));
        break;//  w ww  .  j av a 2 s  .c o  m

    case SecureMessage:
        onSecureMessage(ctx, buffer.readSlice(messageLength));
        break;

    case Error:
        onError(ctx, buffer.readSlice(messageLength));
        break;

    default:
        throw new UaException(StatusCodes.Bad_TcpMessageTypeInvalid, "unexpected MessageType: " + messageType);
    }
}

From source file:org.eclipse.milo.opcua.stack.server.transport.uasc.UascServerAsymmetricHandler.java

License:Open Source License

@Override
protected void decode(ChannelHandlerContext ctx, ByteBuf buffer, List<Object> out) throws Exception {
    while (buffer.readableBytes() >= HEADER_LENGTH) {
        int messageLength = getMessageLength(buffer, maxChunkSize);

        if (buffer.readableBytes() < messageLength) {
            break;
        }/* ww w  .  ja  v  a2  s  . c  o  m*/

        MessageType messageType = MessageType.fromMediumInt(buffer.getMediumLE(buffer.readerIndex()));

        switch (messageType) {
        case OpenSecureChannel:
            onOpenSecureChannel(ctx, buffer.readSlice(messageLength));
            break;

        case CloseSecureChannel:
            logger.debug("Received CloseSecureChannelRequest");

            buffer.skipBytes(messageLength);

            if (secureChannelTimeout != null) {
                secureChannelTimeout.cancel();
                secureChannelTimeout = null;
            }

            ctx.close();
            break;

        default:
            throw new UaException(StatusCodes.Bad_TcpMessageTypeInvalid,
                    "unexpected MessageType: " + messageType);
        }
    }
}

From source file:org.eclipse.milo.opcua.stack.server.transport.uasc.UascServerHelloHandler.java

License:Open Source License

@Override
protected void decode(ChannelHandlerContext ctx, ByteBuf buffer, List<Object> out) throws Exception {
    while (buffer.readableBytes() >= HEADER_LENGTH) {
        int messageLength = getMessageLength(buffer, MAX_HELLO_MESSAGE_SIZE);

        if (buffer.readableBytes() < messageLength) {
            break;
        }/*from  w  ww . j  av a 2s .  c  om*/

        MessageType messageType = MessageType.fromMediumInt(buffer.getMediumLE(buffer.readerIndex()));

        switch (messageType) {
        case Hello:
            onHello(ctx, buffer.readSlice(messageLength));
            break;

        default:
            throw new UaException(StatusCodes.Bad_TcpMessageTypeInvalid,
                    "unexpected MessageType: " + messageType);
        }
    }
}

From source file:org.eclipse.milo.opcua.stack.server.transport.uasc.UascServerSymmetricHandler.java

License:Open Source License

@Override
protected void decode(ChannelHandlerContext ctx, ByteBuf buffer, List<Object> out) throws Exception {
    while (buffer.readableBytes() >= HEADER_LENGTH) {
        int messageLength = getMessageLength(buffer, maxChunkSize);

        if (buffer.readableBytes() < messageLength) {
            break;
        }//from  w  ww  .  j  av a2  s  . c o  m

        MessageType messageType = MessageType.fromMediumInt(buffer.getMediumLE(buffer.readerIndex()));

        switch (messageType) {
        case SecureMessage:
            onSecureMessage(ctx, buffer.readSlice(messageLength));
            break;

        default:
            out.add(buffer.readSlice(messageLength).retain());
        }
    }
}