List of usage examples for io.netty.buffer ByteBuf clear
public abstract ByteBuf clear();
From source file:io.moquette.parser.netty.PubAckDecoderTest.java
License:Open Source License
private void initHeader(ByteBuf buff, int messageID) { buff.clear().writeByte(AbstractMessage.PUBACK << 4).writeByte(2); //return code buff.writeShort(messageID);/* w ww . jav a 2 s . c o m*/ }
From source file:io.moquette.parser.netty.PublishDecoderTest.java
License:Open Source License
private void initHeader(ByteBuf buff) throws IllegalAccessException { ByteBuf tmp = Unpooled.buffer(4).writeBytes(Utils.encodeString("Fake Topic")); buff.clear().writeByte(AbstractMessage.PUBLISH << 4) .writeBytes(Utils.encodeRemainingLength(tmp.readableBytes())); //topic name// w w w .j av a 2 s . c om buff.writeBytes(tmp); }
From source file:io.moquette.parser.netty.PublishDecoderTest.java
License:Open Source License
private ByteBuf packetWithTopic(String topicName) throws IllegalAccessException { ByteBuf buff = Unpooled.buffer(14); ByteBuf topicBuff = Unpooled.buffer(4).writeBytes(Utils.encodeString(topicName)); buff.clear().writeByte(AbstractMessage.PUBLISH << 4) .writeBytes(Utils.encodeRemainingLength(topicBuff.readableBytes())); //topic name/*from w w w. j a v a 2s. c o m*/ buff.writeBytes(topicBuff); return buff; }
From source file:io.moquette.parser.netty.PublishDecoderTest.java
License:Open Source License
private void initHeaderWithMessageID(ByteBuf buff, int messageID) throws IllegalAccessException { ByteBuf tmp = Unpooled.buffer(4).writeBytes(Utils.encodeString("Fake Topic")); tmp.writeShort(messageID);/*from w w w . java 2s.c om*/ buff.clear().writeByte(AbstractMessage.PUBLISH << 4 | 0x02) //set Qos to 1 .writeBytes(Utils.encodeRemainingLength(tmp.readableBytes())); //topic name buff.writeBytes(tmp); }
From source file:io.moquette.parser.netty.PublishDecoderTest.java
License:Open Source License
private void initHeaderWithMessageID_Payload(ByteBuf buff, int messageID, byte[] payload) throws IllegalAccessException { ByteBuf tmp = Unpooled.buffer(4).writeBytes(Utils.encodeString("Fake Topic")); tmp.writeShort(messageID);//w w w . j a va 2 s . c o m tmp.writeBytes(payload); buff.clear().writeByte(AbstractMessage.PUBLISH << 4 | 0x02) //set Qos to 1 .writeBytes(Utils.encodeRemainingLength(tmp.readableBytes())); //topic name buff.writeBytes(tmp); }
From source file:io.moquette.parser.netty.PublishDecoderTest.java
License:Open Source License
private void initHeaderWithMessageID_Payload(ByteBuf buff, int messageID, ByteBuffer payload) throws IllegalAccessException { ByteBuf tmp = Unpooled.buffer(4).writeBytes(Utils.encodeString("Fake Topic")); tmp.writeShort(messageID);/*www .j a va2s . c om*/ tmp.writeBytes(payload); buff.clear().writeByte(AbstractMessage.PUBLISH << 4 | 0x02) //set Qos to 1 .writeBytes(Utils.encodeRemainingLength(tmp.readableBytes())); //topic name buff.writeBytes(tmp); }
From source file:io.moquette.parser.netty.PublishDecoderTest.java
License:Open Source License
private ByteBuf generatePublishQoS0(ByteBuf payload) throws IllegalAccessException { int size = payload.capacity(); ByteBuf messageBody = Unpooled.buffer(size); messageBody.writeBytes(Utils.encodeString("/topic")); //ONLY for QoS > 1 Utils.writeWord(messageBody, messageID); messageBody.writeBytes(payload);/*w ww.ja v a2 s . co m*/ ByteBuf completeMsg = Unpooled.buffer(size); completeMsg.clear().writeByte(AbstractMessage.PUBLISH << 4 | 0x00) //set Qos to 0 .writeBytes(Utils.encodeRemainingLength(messageBody.readableBytes())); completeMsg.writeBytes(messageBody); return completeMsg; }
From source file:io.moquette.parser.netty.PublishDecoderTest.java
License:Open Source License
private ByteBuf preparePubclishWithQosFlags(byte flags) { ByteBuf buff = Unpooled.buffer(14); ByteBuffer payload = ByteBuffer.allocate(3).put(new byte[] { 0x0A, 0x0B, 0x0C }); ByteBuf tmp = Unpooled.buffer(4).writeBytes(Utils.encodeString("Fake Topic")); tmp.writeShort(MESSAGE_ID);/* w w w . j av a2 s.co m*/ tmp.writeBytes(payload); buff.clear().writeByte(AbstractMessage.PUBLISH << 4 | flags) //set DUP=1 Qos to 11 => b1110 .writeBytes(Utils.encodeRemainingLength(tmp.readableBytes())); //topic name buff.writeBytes(tmp); return buff; }
From source file:io.moquette.parser.netty.SubAckDecoderTest.java
License:Open Source License
private void initHeaderQos(ByteBuf buff, int messageID, AbstractMessage.QOSType... qoss) throws IllegalAccessException { buff.clear().writeByte(AbstractMessage.SUBACK << 4) .writeBytes(Utils.encodeRemainingLength(2 + qoss.length)); buff.writeShort(messageID);//from w w w . j a v a 2 s . co m for (AbstractMessage.QOSType qos : qoss) { buff.writeByte(qos.byteValue()); } }
From source file:io.moquette.parser.netty.SubscribeDecoderTest.java
License:Open Source License
private void initHeaderBadQos(ByteBuf buff) { buff.clear().writeByte(AbstractMessage.SUBSCRIBE << 4).writeByte(0); }