public SUBACK decode(MQTTFrame frame) throws ProtocolException { assert(frame.buffers.length == 1); DataByteArrayInputStream is = new DataByteArrayInputStream(frame.buffers[0]); messageId = is.readShort(); grantedQos = is.readBuffer(is.available()).toByteArray(); return this; }
protected AckBase decode(MQTTFrame frame) throws ProtocolException { assert(frame.buffers.length == 1); DataByteArrayInputStream is = new DataByteArrayInputStream(frame.buffers[0]); messageId = is.readShort(); return this; }
static protected void writeUTF(DataByteArrayOutputStream os, Buffer buffer) throws IOException { os.writeShort(buffer.length); os.write(buffer); }
public void onPublish(UTF8Buffer topic, Buffer payload, Runnable ack) { LOG.debug("Received message: topic={}, payload={}", topic.toString(), new String(payload.toByteArray())); try { this.incoming.put(new AckableMessage(topic.toString(), payload.toByteArray(), ack)); } catch (InterruptedException e) { LOG.warn("Interrupted while queueing an MQTT message."); } }
static private String hex(SocketAddress address) { if( address instanceof InetSocketAddress ) { InetSocketAddress isa = (InetSocketAddress)address; return HexSupport.toHexFromBuffer(new Buffer(isa.getAddress().getAddress()))+Integer.toHexString(isa.getPort()); } return ""; }
public Topic(String name, QoS qos) { this(new UTF8Buffer(name), qos); }
public byte[] getPayload() { return payload.toByteArray(); }
public String getTopic() { return topic.toString(); }
static protected UTF8Buffer readUTF(DataByteArrayInputStream is) throws ProtocolException { int size = is.readUnsignedShort(); Buffer buffer = is.readBuffer(size); if (buffer == null || buffer.length != size) { throw new ProtocolException("Invalid message encoding"); } return buffer.utf8(); }
public void setPassword(String password) { this.setPassword(utf8(password)); } public void setPassword(UTF8Buffer password) {
@Override public boolean equals(Object o) { if (o == null) return false; if (o.getClass() != this.getClass()) return false; if (this == o) return true; Topic topic = (Topic) o; if (name != null ? !name.equals(topic.name) : topic.name != null) return false; if (qos != topic.qos) return false; return true; }
@Override public int hashCode() { int result = name != null ? name.hashCode() : 0; result = 31 * result + (qos != null ? qos.hashCode() : 0); return result; }
public static UTF8Buffer readUTF(DataInputStream in, int length) throws IOException { byte data[] = new byte[length]; in.readFully(data); return new UTF8Buffer(data); }
public String getHost() throws IOException { UTF8Buffer buff = (UTF8Buffer) getProperty("Host"); if( buff == null ) { return null; } return buff.toString(); }
public void setUserName(String userName) { this.setUserName(utf8(userName)); } public void setUserName(UTF8Buffer userName) {
public Future<Void> unsubscribe(final String[] topics) { UTF8Buffer[] buffers = new UTF8Buffer[topics.length]; for (int i = 0; i < buffers.length; i++) { buffers[i] = new UTF8Buffer(topics[i]); } return unsubscribe(buffers); }
public void setClientId(String clientId) { this.setClientId(utf8(clientId)); } public void setClientId(UTF8Buffer clientId) {
public void setWillMessage(String willMessage) { connect.willMessage(utf8(willMessage)); } public void setWillMessage(UTF8Buffer willMessage) {
public void setWillTopic(String willTopic) { this.setWillTopic(utf8(willTopic)); } public void setWillTopic(UTF8Buffer willTopic) {