Search in sources :

Example 1 with MessageType

use of org.eclipse.milo.opcua.stack.core.channel.messages.MessageType in project milo by eclipse.

the class UascServerAsymmetricHandler method decode.

@Override
protected void decode(ChannelHandlerContext ctx, ByteBuf buffer, List<Object> out) throws Exception {
    if (buffer.readableBytes() >= HEADER_LENGTH) {
        int messageLength = getMessageLength(buffer, maxChunkSize);
        if (buffer.readableBytes() >= messageLength) {
            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);
            }
        }
    }
}
Also used : UaException(org.eclipse.milo.opcua.stack.core.UaException) Unsigned.uint(org.eclipse.milo.opcua.stack.core.types.builtin.unsigned.Unsigned.uint) MessageType(org.eclipse.milo.opcua.stack.core.channel.messages.MessageType)

Aggregations

UaException (org.eclipse.milo.opcua.stack.core.UaException)1 MessageType (org.eclipse.milo.opcua.stack.core.channel.messages.MessageType)1 Unsigned.uint (org.eclipse.milo.opcua.stack.core.types.builtin.unsigned.Unsigned.uint)1