@Test public void testCompleteHeaderWIthUser_password() throws Exception { ConnectMessage msg = new ConnectMessage(); msg.setUserFlag(true); msg.setPasswordFlag(true); msg.setWillRetain(true); msg.setWillQos((byte)2); msg.setWillFlag(true); msg.setCleanSession(true); msg.setKeepAlive(512); msg.setClientID("ABCDEF"); msg.setWillTopic("Topic"); msg.setWillMessage("Message"); msg.setUsername("Pablo"); msg.setPassword("PBL"); ByteBuf out = Unpooled.buffer(); m_encoder.encode(m_mockedContext, msg, out); assertEquals(0x10, out.readByte()); assertEquals(48, out.readByte()); verifyString("MQIsdp", out); assertEquals(0x03, out.readByte()); assertEquals((byte)0xF6, (byte)out.readByte()); assertEquals(2, out.readByte()); assertEquals(0, out.readByte()); verifyString("ABCDEF", out); verifyString("Topic", out); verifyString("Message", out); verifyString("Pablo", out); verifyString("PBL", out); }
@Override protected void encode(ChannelHandlerContext chc, ConnectMessage message, ByteBuf out) { ByteBuf staticHeaderBuff = chc.alloc().buffer(12); staticHeaderBuff.writeBytes(Utils.encodeString("MQIsdp")); staticHeaderBuff.writeByte(0x03); byte connectionFlags = 0; if (message.isCleanSession()) { connectionFlags |= 0x02; } if (message.isWillFlag()) { connectionFlags |= 0x04; } connectionFlags |= ((message.getWillQos() & 0x03) << 3); if (message.isWillRetain()) { connectionFlags |= 0x020; } if (message.isPasswordFlag()) { connectionFlags |= 0x040; } if (message.isUserFlag()) { connectionFlags |= 0x080; } staticHeaderBuff.writeByte(connectionFlags); staticHeaderBuff.writeShort(message.getKeepAlive()); ByteBuf variableHeaderBuff = chc.alloc().buffer(12); if (message.getClientID() != null) { variableHeaderBuff.writeBytes(Utils.encodeString(message.getClientID())); if (message.isWillFlag()) { variableHeaderBuff.writeBytes(Utils.encodeString(message.getWillTopic())); variableHeaderBuff.writeBytes(Utils.encodeString(message.getWillMessage())); } if (message.isUserFlag() && message.getUsername() != null) { variableHeaderBuff.writeBytes(Utils.encodeString(message.getUsername())); if (message.isPasswordFlag() && message.getPassword() != null) { variableHeaderBuff.writeBytes(Utils.encodeString(message.getPassword())); } } } int variableHeaderSize = variableHeaderBuff.readableBytes(); ByteBuf buff = chc.alloc().buffer(); buff.writeByte(AbstractMessage.CONNECT << 4); buff.writeBytes(Utils.encodeRemainingLength(12 + variableHeaderSize)); buff.writeBytes(staticHeaderBuff).writeBytes(variableHeaderBuff); out.writeBytes(buff); }
ConnectEncoder extends DemuxEncoder<ConnectMessage> { @Override protected void encode(ChannelHandlerContext chc, ConnectMessage message, ByteBuf out) { ByteBuf staticHeaderBuff = chc.alloc().buffer(12); staticHeaderBuff.writeBytes(Utils.encodeString("MQIsdp")); staticHeaderBuff.writeByte(0x03); byte connectionFlags = 0; if (message.isCleanSession()) { connectionFlags |= 0x02; } if (message.isWillFlag()) { connectionFlags |= 0x04; } connectionFlags |= ((message.getWillQos() & 0x03) << 3); if (message.isWillRetain()) { connectionFlags |= 0x020; } if (message.isPasswordFlag()) { connectionFlags |= 0x040; } if (message.isUserFlag()) { connectionFlags |= 0x080; } staticHeaderBuff.writeByte(connectionFlags); staticHeaderBuff.writeShort(message.getKeepAlive()); ByteBuf variableHeaderBuff = chc.alloc().buffer(12); if (message.getClientID() != null) { variableHeaderBuff.writeBytes(Utils.encodeString(message.getClientID())); if (message.isWillFlag()) { variableHeaderBuff.writeBytes(Utils.encodeString(message.getWillTopic())); variableHeaderBuff.writeBytes(Utils.encodeString(message.getWillMessage())); } if (message.isUserFlag() && message.getUsername() != null) { variableHeaderBuff.writeBytes(Utils.encodeString(message.getUsername())); if (message.isPasswordFlag() && message.getPassword() != null) { variableHeaderBuff.writeBytes(Utils.encodeString(message.getPassword())); } } } int variableHeaderSize = variableHeaderBuff.readableBytes(); ByteBuf buff = chc.alloc().buffer(); buff.writeByte(AbstractMessage.CONNECT << 4); buff.writeBytes(Utils.encodeRemainingLength(12 + variableHeaderSize)); buff.writeBytes(staticHeaderBuff).writeBytes(variableHeaderBuff); out.writeBytes(buff); } }
ConnectEncoder extends DemuxEncoder<ConnectMessage> { @Override protected void encode(ChannelHandlerContext chc, ConnectMessage message, ByteBuf out) { ByteBuf staticHeaderBuff = chc.alloc().buffer(12); staticHeaderBuff.writeBytes(Utils.encodeString("MQIsdp")); staticHeaderBuff.writeByte(0x03); byte connectionFlags = 0; if (message.isCleanSession()) { connectionFlags |= 0x02; } if (message.isWillFlag()) { connectionFlags |= 0x04; } connectionFlags |= ((message.getWillQos() & 0x03) << 3); if (message.isWillRetain()) { connectionFlags |= 0x020; } if (message.isPasswordFlag()) { connectionFlags |= 0x040; } if (message.isUserFlag()) { connectionFlags |= 0x080; } staticHeaderBuff.writeByte(connectionFlags); staticHeaderBuff.writeShort(message.getKeepAlive()); ByteBuf variableHeaderBuff = chc.alloc().buffer(12); if (message.getClientID() != null) { variableHeaderBuff.writeBytes(Utils.encodeString(message.getClientID())); if (message.isWillFlag()) { variableHeaderBuff.writeBytes(Utils.encodeString(message.getWillTopic())); variableHeaderBuff.writeBytes(Utils.encodeString(message.getWillMessage())); } if (message.isUserFlag() && message.getUsername() != null) { variableHeaderBuff.writeBytes(Utils.encodeString(message.getUsername())); if (message.isPasswordFlag() && message.getPassword() != null) { variableHeaderBuff.writeBytes(Utils.encodeString(message.getPassword())); } } } int variableHeaderSize = variableHeaderBuff.readableBytes(); ByteBuf buff = chc.alloc().buffer(); buff.writeByte(AbstractMessage.CONNECT << 4); buff.writeBytes(Utils.encodeRemainingLength(12 + variableHeaderSize)); buff.writeBytes(staticHeaderBuff).writeBytes(variableHeaderBuff); out.writeBytes(buff); }  }
ConnectEncoder extends DemuxEncoder<ConnectMessage> { @Override protected void encode(ChannelHandlerContext chc, ConnectMessage message, ByteBuf out) { ByteBuf staticHeaderBuff = chc.alloc().buffer(12); staticHeaderBuff.writeBytes(Utils.encodeString("MQIsdp")); staticHeaderBuff.writeByte(0x03); byte connectionFlags = 0; if (message.isCleanSession()) { connectionFlags |= 0x02; } if (message.isWillFlag()) { connectionFlags |= 0x04; } connectionFlags |= ((message.getWillQos() & 0x03) << 3); if (message.isWillRetain()) { connectionFlags |= 0x020; } if (message.isPasswordFlag()) { connectionFlags |= 0x040; } if (message.isUserFlag()) { connectionFlags |= 0x080; } staticHeaderBuff.writeByte(connectionFlags); staticHeaderBuff.writeShort(message.getKeepAlive()); ByteBuf variableHeaderBuff = chc.alloc().buffer(12); if (message.getClientID() != null) { variableHeaderBuff.writeBytes(Utils.encodeString(message.getClientID())); if (message.isWillFlag()) { variableHeaderBuff.writeBytes(Utils.encodeString(message.getWillTopic())); variableHeaderBuff.writeBytes(Utils.encodeString(message.getWillMessage())); } if (message.isUserFlag() && message.getUsername() != null) { variableHeaderBuff.writeBytes(Utils.encodeString(message.getUsername())); if (message.isPasswordFlag() && message.getPassword() != null) { variableHeaderBuff.writeBytes(Utils.encodeString(message.getPassword())); } } } int variableHeaderSize = variableHeaderBuff.readableBytes(); ByteBuf buff = chc.alloc().buffer(); buff.writeByte(AbstractMessage.CONNECT << 4); buff.writeBytes(Utils.encodeRemainingLength(12 + variableHeaderSize)); buff.writeBytes(staticHeaderBuff).writeBytes(variableHeaderBuff); out.writeBytes(buff); }   }
ConnectEncoder extends DemuxEncoder<ConnectMessage> { @Override protected void encode(ChannelHandlerContext chc, ConnectMessage message, ByteBuf out) { ByteBuf staticHeaderBuff = chc.alloc().buffer(12); staticHeaderBuff.writeBytes(Utils.encodeString("MQIsdp")); staticHeaderBuff.writeByte(0x03); byte connectionFlags = 0; if (message.isCleanSession()) { connectionFlags |= 0x02; } if (message.isWillFlag()) { connectionFlags |= 0x04; } connectionFlags |= ((message.getWillQos() & 0x03) << 3); if (message.isWillRetain()) { connectionFlags |= 0x020; } if (message.isPasswordFlag()) { connectionFlags |= 0x040; } if (message.isUserFlag()) { connectionFlags |= 0x080; } staticHeaderBuff.writeByte(connectionFlags); staticHeaderBuff.writeShort(message.getKeepAlive()); ByteBuf variableHeaderBuff = chc.alloc().buffer(12); if (message.getClientID() != null) { variableHeaderBuff.writeBytes(Utils.encodeString(message.getClientID())); if (message.isWillFlag()) { variableHeaderBuff.writeBytes(Utils.encodeString(message.getWillTopic())); variableHeaderBuff.writeBytes(Utils.encodeString(message.getWillMessage())); } if (message.isUserFlag() && message.getUsername() != null) { variableHeaderBuff.writeBytes(Utils.encodeString(message.getUsername())); if (message.isPasswordFlag() && message.getPassword() != null) { variableHeaderBuff.writeBytes(Utils.encodeString(message.getPassword())); } } } int variableHeaderSize = variableHeaderBuff.readableBytes(); ByteBuf buff = chc.alloc().buffer(); buff.writeByte(AbstractMessage.CONNECT << 4); buff.writeBytes(Utils.encodeRemainingLength(12 + variableHeaderSize)); buff.writeBytes(staticHeaderBuff).writeBytes(variableHeaderBuff); out.writeBytes(buff); }    }