List of usage examples for io.netty.buffer ByteBuf getUnsignedIntLE
public abstract long getUnsignedIntLE(int index);
From source file:org.eclipse.milo.opcua.stack.client.transport.uasc.UascClientMessageHandler.java
License:Open Source License
private void validateChunkHeaders(List<ByteBuf> chunkBuffers) throws UaException { ChannelSecurity channelSecurity = secureChannel.getChannelSecurity(); long currentTokenId = channelSecurity.getCurrentToken().getTokenId().longValue(); long previousTokenId = channelSecurity.getPreviousToken().map(t -> t.getTokenId().longValue()).orElse(-1L); for (ByteBuf chunkBuffer : chunkBuffers) { // tokenId starts after messageType + chunkType + messageSize + secureChannelId long tokenId = chunkBuffer.getUnsignedIntLE(3 + 1 + 4 + 4); if (tokenId != currentTokenId && tokenId != previousTokenId) { String message = String.format( "received unknown secure channel token: " + "tokenId=%s currentTokenId=%s previousTokenId=%s", tokenId, currentTokenId, previousTokenId); throw new UaException(StatusCodes.Bad_SecureChannelTokenUnknown, message); }//from ww w .j a va2s.co m } }
From source file:org.traccar.protocol.NavigilFrameDecoder.java
License:Apache License
@Override protected Object decode(ChannelHandlerContext ctx, Channel channel, ByteBuf buf) throws Exception { // Check minimum length if (buf.readableBytes() < MESSAGE_HEADER) { return null; }//ww w .j a v a 2 s .c o m // Check for preamble boolean hasPreamble = false; if (buf.getUnsignedIntLE(buf.readerIndex()) == PREAMBLE) { hasPreamble = true; } // Check length and return buffer int length = buf.getUnsignedShortLE(buf.readerIndex() + 6); if (buf.readableBytes() >= length) { if (hasPreamble) { buf.readUnsignedIntLE(); length -= 4; } return buf.readRetainedSlice(length); } return null; }
From source file:org.traccar.protocol.TelicFrameDecoder.java
License:Apache License
@Override protected Object decode(ChannelHandlerContext ctx, Channel channel, ByteBuf buf) throws Exception { if (buf.readableBytes() < 4) { return null; }//from w w w.j a va2 s . c om long length = buf.getUnsignedIntLE(buf.readerIndex()); if (length < 1024) { if (buf.readableBytes() >= length + 4) { buf.readUnsignedIntLE(); return buf.readRetainedSlice((int) length); } } else { int endIndex = buf.indexOf(buf.readerIndex(), buf.writerIndex(), (byte) 0); if (endIndex >= 0) { ByteBuf frame = buf.readRetainedSlice(endIndex - buf.readerIndex()); buf.readByte(); if (frame.readableBytes() > 0) { return frame; } } } return null; }