public SUBSCRIBE() { qos(QoS.AT_LEAST_ONCE); }
@Override public String toString() { return "SUBSCRIBE{" + "dup=" + dup() + ", qos=" + qos() + ", messageId=" + messageId + ", topics=" + (topics == null ? null : Arrays.asList(topics)) + '}'; } }
public SUBSCRIBE decode(MQTTFrame frame) throws ProtocolException { assert(frame.buffers.length == 1); header(frame.header()); DataByteArrayInputStream is = new DataByteArrayInputStream(frame.buffers[0]); QoS qos = qos(); if(qos != QoS.AT_MOST_ONCE) { messageId = is.readShort(); } ArrayList<Topic> list = new ArrayList<Topic>(); while(is.available() > 0) { Topic topic = new Topic(MessageSupport.readUTF(is), QoS.values()[is.readByte()]); list.add(topic); } topics = list.toArray(new Topic[list.size()]); return this; }
public MQTTFrame encode() { try { DataByteArrayOutputStream os = new DataByteArrayOutputStream(); QoS qos = qos(); if(qos != QoS.AT_MOST_ONCE) { os.writeShort(messageId); } for(Topic topic: topics) { MessageSupport.writeUTF(os, topic.name()); os.writeByte(topic.qos().ordinal()); } MQTTFrame frame = new MQTTFrame(); frame.header(header()); frame.commandType(TYPE); return frame.buffer(os.toBuffer()); } catch (IOException e) { throw new RuntimeException("The impossible happened"); } }
public SUBSCRIBE() { qos(QoS.AT_LEAST_ONCE); }
@Override public String toString() { return "SUBSCRIBE{" + "dup=" + dup() + ", qos=" + qos() + ", messageId=" + messageId + ", topics=" + (topics == null ? null : Arrays.asList(topics)) + '}'; } }
public SUBSCRIBE decode(MQTTFrame frame) throws ProtocolException { assert(frame.buffers.length == 1); header(frame.header()); DataByteArrayInputStream is = new DataByteArrayInputStream(frame.buffers[0]); QoS qos = qos(); if(qos != QoS.AT_MOST_ONCE) { messageId = is.readShort(); } ArrayList<Topic> list = new ArrayList<Topic>(); while(is.available() > 0) { Topic topic = new Topic(MessageSupport.readUTF(is), QoS.values()[is.readByte()]); list.add(topic); } topics = list.toArray(new Topic[list.size()]); return this; }
public MQTTFrame encode() { try { DataByteArrayOutputStream os = new DataByteArrayOutputStream(); QoS qos = qos(); if(qos != QoS.AT_MOST_ONCE) { os.writeShort(messageId); } for(Topic topic: topics) { MessageSupport.writeUTF(os, topic.name()); os.writeByte(topic.qos().ordinal()); } MQTTFrame frame = new MQTTFrame(); frame.header(header()); frame.commandType(TYPE); return frame.buffer(os.toBuffer()); } catch (IOException e) { throw new RuntimeException("The impossible happened"); } }