List of usage examples for io.netty.buffer ByteBuf skipBytes
public abstract ByteBuf skipBytes(int length);
From source file:org.jfxvnc.net.rfb.codec.handshaker.RfbClient33Decoder.java
License:Apache License
protected PixelFormat parsePixelFormat(ByteBuf m) { PixelFormat pf = new PixelFormat(); pf.setBitPerPixel(m.readUnsignedByte()); pf.setDepth(m.readUnsignedByte());/*from ww w. j a v a2 s . c o m*/ pf.setBigEndian(m.readUnsignedByte() == 1); pf.setTrueColor(m.readUnsignedByte() == 1); pf.setRedMax(m.readUnsignedShort()); pf.setGreenMax(m.readUnsignedShort()); pf.setBlueMax(m.readUnsignedShort()); pf.setRedShift(m.readUnsignedByte()); pf.setGreenShift(m.readUnsignedByte()); pf.setBlueShift(m.readUnsignedByte()); m.skipBytes(3); return pf; }
From source file:org.jfxvnc.net.rfb.codec.handshaker.RfbClient38Decoder.java
License:Apache License
private PixelFormat parsePixelFormat(ByteBuf m) { PixelFormat pf = new PixelFormat(); pf.setBitPerPixel(m.readUnsignedByte()); pf.setDepth(m.readUnsignedByte());//w w w . j a va 2s. c o m pf.setBigEndian(m.readUnsignedByte() == 1); pf.setTrueColor(m.readUnsignedByte() == 1); pf.setRedMax(m.readUnsignedShort()); pf.setGreenMax(m.readUnsignedShort()); pf.setBlueMax(m.readUnsignedShort()); pf.setRedShift(m.readUnsignedByte()); pf.setGreenShift(m.readUnsignedByte()); pf.setBlueShift(m.readUnsignedByte()); m.skipBytes(3); return pf; }
From source file:org.jmqtt.core.util.MqttUtils.java
License:Open Source License
public static boolean checkHeaderAvailability(ByteBuf in) { if (in.readableBytes() < 1) { return false; }//from w ww. j a v a 2s . c o m //byte h1 = in.get(); //byte messageType = (byte) ((h1 & 0x00F0) >> 4); in.skipBytes(1); //skip the messageType byte int remainingLength = decodeRemainingLenght(in); if (remainingLength == -1) { return false; } //check remaining length if (in.readableBytes() < remainingLength) { return false; } //return messageType == type ? MessageDecoderResult.OK : MessageDecoderResult.NOT_OK; return true; }
From source file:org.l2junity.loginserver.network.client.crypt.Crypt.java
License:Open Source License
@Override public void encrypt(ByteBuf buf) { // Ensure that byte order is little endian because we set new packet size in first 2 bytes if (buf.order() != ByteOrder.LITTLE_ENDIAN) { buf = buf.order(ByteOrder.LITTLE_ENDIAN); }//from w w w . j ava2 s . c om // Checksum & XOR Key or Checksum only buf.writeZero(_static ? 8 : 4); // Padding buf.writeZero(8 - (buf.readableBytes() % 8)); if (_static) { _static = false; int key = Rnd.nextInt(); buf.skipBytes(4); // The first 4 bytes are ignored while (buf.readerIndex() < (buf.writerIndex() - 8)) { int data = buf.readInt(); key += data; data ^= key; buf.setInt(buf.readerIndex() - 4, data); } buf.setInt(buf.readerIndex(), key); buf.resetReaderIndex(); final byte[] block = new byte[8]; while (buf.isReadable(8)) { buf.readBytes(block); STATIC_BLOWFISH_ENGINE.encryptBlock(block, 0); buf.setBytes(buf.readerIndex() - block.length, block); } } else { int checksum = 0; while (buf.isReadable(8)) { checksum ^= buf.readInt(); } buf.setInt(buf.readerIndex(), checksum); buf.resetReaderIndex(); final byte[] block = new byte[8]; while (buf.isReadable(8)) { buf.readBytes(block); _blowfishEngine.encryptBlock(block, 0); buf.setBytes(buf.readerIndex() - block.length, block); } } }
From source file:org.mobicents.protocols.ss7.m3ua.impl.message.M3UAMessageImpl.java
License:Open Source License
protected void decode(ByteBuf data) { while (data.readableBytes() >= 4) { short tag = (short) ((data.readUnsignedByte() << 8) | (data.readUnsignedByte())); short len = (short) ((data.readUnsignedByte() << 8) | (data.readUnsignedByte())); if (data.readableBytes() < len - 4) { return; }/*from w w w .j ava2s .co m*/ byte[] value = new byte[len - 4]; data.readBytes(value); parameters.put(tag, factory.createParameter(tag, value)); // The Parameter Length does not include any padding octets. We have // to consider padding here int padding = 4 - (len % 4); if (padding < 4) { if (data.readableBytes() < padding) return; else data.skipBytes(padding); } } }
From source file:org.mobicents.protocols.ss7.m3ua.impl.message.MessageFactoryImpl.java
License:Open Source License
public M3UAMessageImpl createMessage(ByteBuf message) { int dataLen;/*from www.j ava 2 s . co m*/ if (message.readableBytes() < 8) { return null; } // obtain message class and type from header message.markReaderIndex(); message.skipBytes(2); int messageClass = message.readUnsignedByte(); int messageType = message.readUnsignedByte(); // obtain remaining length of the message and prepare buffer dataLen = message.readInt() - 8; if (message.readableBytes() < dataLen) { message.resetReaderIndex(); return null; } // construct new message instance M3UAMessageImpl messageTemp = this.createMessage(messageClass, messageType); // parsing params of this message message.markWriterIndex(); message.writerIndex(message.readerIndex() + dataLen); messageTemp.decode(message); message.resetWriterIndex(); return messageTemp; }
From source file:org.msgpack.rpc.loop.netty.MessagePackStreamDecoder.java
License:Apache License
@Override protected void decode(ChannelHandlerContext ctx, ByteBuf msg, List<Object> paramList) throws Exception { if (msg.isReadable()) { ByteBuffer buffer = msg.nioBuffer(); Unpacker unpacker = msgpack.createBufferUnpacker(buffer); int lastPos = 0; try {/* w w w . j a v a2 s .c om*/ while (buffer.position() < buffer.limit()) { Value v = unpacker.readValue(); paramList.add(v); lastPos = buffer.position(); } msg.skipBytes(lastPos); } catch (EOFException e) { msg.skipBytes(lastPos); } } }
From source file:org.neo4j.tools.boltalyzer.AnalyzedSession.java
License:Open Source License
public String describeServerPayload(ByteBuffer payload) throws IOException { ByteBuf data = Unpooled.wrappedBuffer(payload); String out = " <EMPTY>"; // TODO: Something more sophisticated than this if (serverHandshakeRemaining > 0 && data.readableBytes() > 0) { int toRead = Math.min(data.readableBytes(), serverHandshakeRemaining); serverHandshakeRemaining -= toRead; data.skipBytes(toRead); out = " <HANDSHAKE RESPONSE>"; }/*from ww w .j a v a 2s. c o m*/ if (data.readableBytes() == 0) { return out; } serverStream.handle(data); return serverStreamDescriber.flushDescription(); }
From source file:org.neo4j.tools.boltalyzer.AnalyzedSession.java
License:Open Source License
public String describeClientPayload(ByteBuffer payload) throws IOException { ByteBuf data = Unpooled.wrappedBuffer(payload); String out = " <EMPTY>"; if (clientHandshakeRemaining > 0 && data.readableBytes() > 0) { int toRead = Math.min(data.readableBytes(), clientHandshakeRemaining); clientHandshakeRemaining -= toRead; data.skipBytes(toRead); out = " <HANDSHAKE>"; }//w w w. ja v a 2 s .com if (data.readableBytes() == 0) { return out; } clientStream.handle(data); return clientStreamDescriber.flushDescription(); }
From source file:org.onosproject.lisp.msg.protocols.DefaultLispGenericLocator.java
License:Apache License
/** * Deserializes LispGenericLocator message portion. * * @param byteBuf byte buffer/*from w w w . j a v a 2 s . c o m*/ * @return LispGenericLocator * @throws LispParseError LISP message parse error * @throws LispReaderException LISP message reader exception */ public static LispGenericLocator deserialize(ByteBuf byteBuf) throws LispParseError, LispReaderException { // priority -> 8 bits byte priority = (byte) byteBuf.readUnsignedByte(); // weight -> 8 bits byte weight = (byte) byteBuf.readUnsignedByte(); // multi-cast priority -> 8 bits byte multicastPriority = (byte) byteBuf.readUnsignedByte(); // multi-cast weight -> 8 bits byte multicastWeight = (byte) byteBuf.readUnsignedByte(); // let's skip unused flags byteBuf.skipBytes(SKIP_UNUSED_FLAG_LENGTH); byte flags = byteBuf.readByte(); // local locator flag -> 1 bit boolean localLocator = ByteOperator.getBit(flags, LOCAL_LOCATOR_INDEX); // rloc probe flag -> 1 bit boolean rlocProbed = ByteOperator.getBit(flags, RLOC_PROBED_INDEX); // routed flag -> 1 bit boolean routed = ByteOperator.getBit(flags, ROUTED_INDEX); LispAfiAddress address = new LispAfiAddress.AfiAddressReader().readFrom(byteBuf); return new DefaultLispGenericLocator(priority, weight, multicastPriority, multicastWeight, localLocator, rlocProbed, routed, address); }