@Test public void testEncodeWithMultiTopic() throws Exception { m_msg.setQos(QOSType.LEAST_ONE); String topic1 = "a/b"; String topic2 = "a/b/c"; m_msg.addTopic(topic1); m_msg.addTopic(topic2); m_encoder.encode(null, m_msg, m_mockProtoEncoder); assertEquals((byte)0xA2, (byte)m_mockProtoEncoder.getBuffer().get()); assertEquals(14, m_mockProtoEncoder.getBuffer().get()); assertEquals((byte)0xAA, m_mockProtoEncoder.getBuffer().get()); assertEquals((byte)0xBB, m_mockProtoEncoder.getBuffer().get()); verifyString(topic1, m_mockProtoEncoder.getBuffer()); verifyString(topic2, m_mockProtoEncoder.getBuffer()); }
public void encode(IoSession session, UnsubscribeMessage message, ProtocolEncoderOutput out) throws Exception { if (message.topics().isEmpty()) { throw new IllegalArgumentException("Found an unsubscribe message with empty topics"); } if (message.getQos() != QOSType.LEAST_ONE) { throw new IllegalArgumentException("Expected a message with QOS 1, found " + message.getQos()); } IoBuffer variableHeaderBuff = IoBuffer.allocate(4).setAutoExpand(true); Utils.writeWord(variableHeaderBuff, message.getMessageID()); for (String topic : message.topics()) { variableHeaderBuff.put(Utils.encodeString(topic)); } variableHeaderBuff.flip(); int variableHeaderSize = variableHeaderBuff.remaining(); byte flags = Utils.encodeFlags(message); IoBuffer buff = IoBuffer.allocate(2 + variableHeaderSize); buff.put((byte) (AbstractMessage.UNSUBSCRIBE << 4 | flags)); buff.put(Utils.encodeRemainingLength(variableHeaderSize)); buff.put(variableHeaderBuff).flip(); out.write(buff); }
UnsubscribeEncoder implements MessageEncoder<UnsubscribeMessage> { public void encode(IoSession session, UnsubscribeMessage message, ProtocolEncoderOutput out) throws Exception { if (message.topics().isEmpty()) { throw new IllegalArgumentException("Found an unsubscribe message with empty topics"); } if (message.getQos() != QOSType.LEAST_ONE) { throw new IllegalArgumentException("Expected a message with QOS 1, found " + message.getQos()); } IoBuffer variableHeaderBuff = IoBuffer.allocate(4).setAutoExpand(true); Utils.writeWord(variableHeaderBuff, message.getMessageID()); for (String topic : message.topics()) { variableHeaderBuff.put(Utils.encodeString(topic)); } variableHeaderBuff.flip(); int variableHeaderSize = variableHeaderBuff.remaining(); byte flags = Utils.encodeFlags(message); IoBuffer buff = IoBuffer.allocate(2 + variableHeaderSize); buff.put((byte) (AbstractMessage.UNSUBSCRIBE << 4 | flags)); buff.put(Utils.encodeRemainingLength(variableHeaderSize)); buff.put(variableHeaderBuff).flip(); out.write(buff); } }
UnsubscribeEncoder implements MessageEncoder<UnsubscribeMessage> { public void encode(IoSession session, UnsubscribeMessage message, ProtocolEncoderOutput out) throws Exception { if (message.topics().isEmpty()) { throw new IllegalArgumentException("Found an unsubscribe message with empty topics"); } if (message.getQos() != QOSType.LEAST_ONE) { throw new IllegalArgumentException("Expected a message with QOS 1, found " + message.getQos()); } IoBuffer variableHeaderBuff = IoBuffer.allocate(4).setAutoExpand(true); Utils.writeWord(variableHeaderBuff, message.getMessageID()); for (String topic : message.topics()) { variableHeaderBuff.put(Utils.encodeString(topic)); } variableHeaderBuff.flip(); int variableHeaderSize = variableHeaderBuff.remaining(); byte flags = Utils.encodeFlags(message); IoBuffer buff = IoBuffer.allocate(2 + variableHeaderSize); buff.put((byte) (AbstractMessage.UNSUBSCRIBE << 4 | flags)); buff.put(Utils.encodeRemainingLength(variableHeaderSize)); buff.put(variableHeaderBuff).flip(); out.write(buff); }  }
UnsubscribeEncoder implements MessageEncoder<UnsubscribeMessage> { public void encode(IoSession session, UnsubscribeMessage message, ProtocolEncoderOutput out) throws Exception { if (message.topics().isEmpty()) { throw new IllegalArgumentException("Found an unsubscribe message with empty topics"); } if (message.getQos() != QOSType.LEAST_ONE) { throw new IllegalArgumentException("Expected a message with QOS 1, found " + message.getQos()); } IoBuffer variableHeaderBuff = IoBuffer.allocate(4).setAutoExpand(true); Utils.writeWord(variableHeaderBuff, message.getMessageID()); for (String topic : message.topics()) { variableHeaderBuff.put(Utils.encodeString(topic)); } variableHeaderBuff.flip(); int variableHeaderSize = variableHeaderBuff.remaining(); byte flags = Utils.encodeFlags(message); IoBuffer buff = IoBuffer.allocate(2 + variableHeaderSize); buff.put((byte) (AbstractMessage.UNSUBSCRIBE << 4 | flags)); buff.put(Utils.encodeRemainingLength(variableHeaderSize)); buff.put(variableHeaderBuff).flip(); out.write(buff); }  void encode(IoSession session, UnsubscribeMessage message, ProtocolEncoderOutput out); }
UnsubscribeEncoder implements MessageEncoder<UnsubscribeMessage> { public void encode(IoSession session, UnsubscribeMessage message, ProtocolEncoderOutput out) throws Exception { if (message.topics().isEmpty()) { throw new IllegalArgumentException("Found an unsubscribe message with empty topics"); } if (message.getQos() != QOSType.LEAST_ONE) { throw new IllegalArgumentException("Expected a message with QOS 1, found " + message.getQos()); } IoBuffer variableHeaderBuff = IoBuffer.allocate(4).setAutoExpand(true); Utils.writeWord(variableHeaderBuff, message.getMessageID()); for (String topic : message.topics()) { variableHeaderBuff.put(Utils.encodeString(topic)); } variableHeaderBuff.flip(); int variableHeaderSize = variableHeaderBuff.remaining(); byte flags = Utils.encodeFlags(message); IoBuffer buff = IoBuffer.allocate(2 + variableHeaderSize); buff.put((byte) (AbstractMessage.UNSUBSCRIBE << 4 | flags)); buff.put(Utils.encodeRemainingLength(variableHeaderSize)); buff.put(variableHeaderBuff).flip(); out.write(buff); }  void encode(IoSession session, UnsubscribeMessage message, ProtocolEncoderOutput out);  }