List of usage examples for io.netty.buffer ByteBuf readUnsignedByte
public abstract short readUnsignedByte();
From source file:org.legacy.network.protocol.ondemand.OnDemandEncoder.java
License:Open Source License
@Override protected void encode(ChannelHandlerContext ctx, OnDemandResponseMessage msg, ByteBuf out) throws Exception { OnDemandResponseMessage response = (OnDemandResponseMessage) msg; ByteBuf container = response.getContainer(); int index = response.getType(); int file = response.getFile(); ByteBuf buffer = Unpooled.buffer();/* ww w .ja va 2 s . c o m*/ int compression = container.readUnsignedByte(); int size = ((container.readByte() & 0xff) << 24) + ((container.readByte() & 0xff) << 16) + ((container.readByte() & 0xff) << 8) + (container.readByte() & 0xff); if (!response.isPriority()) { file |= 0x80000000; } buffer.writeByte(index); buffer.writeInt(file); buffer.writeByte(compression); buffer.writeInt(size); int bytes = container.readableBytes(); if (bytes > 502) { bytes = 502; } buffer.writeBytes(container.readBytes(bytes)); for (;;) { bytes = container.readableBytes(); if (bytes == 0) { break; } else if (bytes > 507) { bytes = 507; } buffer.writeByte(index); buffer.writeInt(file); buffer.writeBytes(container.readBytes(bytes)); } }
From source file:org.legacy.network.protocol.ondemand.XorEncoder.java
License:Open Source License
@Override protected void encode(ChannelHandlerContext ctx, ByteBuf in, ByteBuf out) throws Exception { while (out.isWritable()) { out.writeByte(in.readUnsignedByte() ^ key); }//from w w w . j a v a 2 s .co m }
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; }/* ww w . jav a 2s. 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;/* w w w.j a va 2s .c o 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.neo4j.bolt.v1.transport.BoltV1Dechunker.java
License:Open Source License
public void handle(ByteBuf data) throws IOException { while (data.readableBytes() > 0) { switch (state) { case AWAITING_CHUNK: { if (data.readableBytes() >= 2) { // Whole header available, read that chunkSize = data.readUnsignedShort(); handleHeader();/*from ww w . j a v a 2s . c om*/ } else { // Only one byte available, read that and wait for the second byte chunkSize = data.readUnsignedByte() << 8; state = State.IN_HEADER; } break; } case IN_HEADER: { // First header byte read, now we read the next one chunkSize = chunkSize | data.readUnsignedByte(); handleHeader(); break; } case IN_CHUNK: { if (chunkSize < data.readableBytes()) { // Current packet is larger than current chunk, slice of the chunk input.append(data.readSlice(chunkSize)); state = State.AWAITING_CHUNK; } else if (chunkSize == data.readableBytes()) { // Current packet perfectly maps to current chunk input.append(data); state = State.AWAITING_CHUNK; return; } else { // Current packet is smaller than the chunk we're reading, split the current chunk itself up chunkSize -= data.readableBytes(); input.append(data); return; } break; } case CLOSED: { // No-op return; } } } }
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.co 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); }
From source file:org.onosproject.lisp.msg.protocols.DefaultLispInfo.java
License:Apache License
public static LispInfo deserialize(ByteBuf byteBuf) throws LispParseError, LispReaderException { if (byteBuf.readerIndex() != 0) { return null; }// w w w . ja v a 2s .com // infoReply -> 1 bit boolean infoReplyFlag = ByteOperator.getBit(byteBuf.readByte(), INFO_REPLY_INDEX); // let's skip the reserved field byteBuf.skipBytes(RESERVED_SKIP_LENGTH_1); // nonce -> 64 bits long nonce = byteBuf.readLong(); // keyId -> 16 bits short keyId = byteBuf.readShort(); // authenticationDataLength -> 16 bits short authLength = byteBuf.readShort(); // authData -> depends on the authenticationDataLength byte[] authData = new byte[authLength]; byteBuf.readBytes(authData); // ttl -> 32 bits int ttl = byteBuf.readInt(); // let's skip the reserved field byteBuf.skipBytes(RESERVED_SKIP_LENGTH_2); // mask length -> 8 bits short maskLength = byteBuf.readUnsignedByte(); LispAfiAddress prefix = new LispAfiAddress.AfiAddressReader().readFrom(byteBuf); return new DefaultLispInfo(infoReplyFlag, nonce, keyId, authLength, authData, ttl, (byte) maskLength, prefix); }
From source file:org.onosproject.lisp.msg.types.lcaf.LispLcafAddress.java
License:Apache License
/** * Deserializes common fields from byte buffer. * * @param byteBuf byte buffer/* w w w . j a v a2 s. c om*/ * @return LispLcafAddress with filled common data fields */ public static LispLcafAddress deserializeCommon(ByteBuf byteBuf) { // let's skip first and second two bytes, // because it represents LCAF AFI code byteBuf.skipBytes(LCAF_AFI_CODE_BYTE_LENGTH); // reserved1 -> 8 bits byte reserved1 = (byte) byteBuf.readUnsignedByte(); // flags -> 8 bits byte flag = (byte) byteBuf.readUnsignedByte(); // LCAF type -> 8 bits byte lcafType = (byte) byteBuf.readUnsignedByte(); // reserved2 -> 8bits byte reserved2 = (byte) byteBuf.readUnsignedByte(); // length -> 16 bits short length = (short) byteBuf.readUnsignedShort(); return new LispLcafAddress(LispCanonicalAddressFormatEnum.valueOf(lcafType), reserved1, reserved2, flag, length); }
From source file:org.onosproject.lisp.msg.types.LispLcafAddress.java
License:Apache License
/** * Deserializes common fields from byte buffer. * * @param byteBuf byte buffer//from w w w . j a v a2 s . c o m * @return LispLcafAddress with filled common data fields */ public static LispLcafAddress deserializeCommon(ByteBuf byteBuf) { // reserved1 -> 8 bits byte reserved1 = (byte) byteBuf.readUnsignedByte(); // flags -> 8 bits byte flag = (byte) byteBuf.readUnsignedByte(); // LCAF type -> 8 bits byte lcafType = (byte) byteBuf.readUnsignedByte(); // reserved2 -> 8bits byte reserved2 = (byte) byteBuf.readUnsignedByte(); // length -> 16 bits short length = (short) byteBuf.readUnsignedShort(); return new LispLcafAddress(LispCanonicalAddressFormatEnum.valueOf(lcafType), reserved1, reserved2, flag, length); }
From source file:org.opendaylight.capwap.ODLCapwapControlMessage.java
License:Open Source License
int decode(ByteBuf buf) { //ByteBuf bbuf = Unpooled.wrappedBuffer(buf); //ByteBuf tmpbuf = bbuf.readerIndex(pos); this.msgType = buf.readUnsignedInt(); this.seqNo = buf.readUnsignedByte(); this.msgLen = buf.readUnsignedShort(); this.flags = buf.readUnsignedByte(); return 0;//from w ww . j a v a 2 s .co m }