public MQTTFrame encode() { try { DataByteArrayOutputStream os = new DataByteArrayOutputStream(2); os.writeByte(0); os.writeByte(code.ordinal()); MQTTFrame frame = new MQTTFrame(); frame.commandType(TYPE); return frame.buffer(os.toBuffer()); } catch (IOException e) { throw new RuntimeException("The impossible happened"); } }
if(version==3) { MessageSupport.writeUTF(os, V3_PROTOCOL_NAME); os.writeByte(version); } else if(version >= 4) { MessageSupport.writeUTF(os, V4_PROTOCOL_NAME); os.writeByte(version); } else { throw new IllegalArgumentException("Invalid version: "+version); flags |= 0x02; os.writeByte(flags); os.writeShort(keepAlive); MessageSupport.writeUTF(os, clientId);
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"); } }
@Override protected void writeByte(int value) throws IOException { DataByteArrayOutputStream.this.writeByte(value); } };
@Override protected void writeByte(int value) throws IOException { DataByteArrayOutputStream.this.writeByte(value); } };
@Override protected void writeByte(int value) throws IOException { DataByteArrayOutputStream.this.writeByte(value); } };
public static void marshalString(DataByteArrayOutputStream out, String s) throws IOException { // If it's too big, out.writeUTF may not able able to write it out. if (s.length() < Short.MAX_VALUE / 4) { out.writeByte(STRING_TYPE); out.writeUTF(s); } else { out.writeByte(BIG_STRING_TYPE); out.writeUTF(s); } }
public static void marshalString(DataByteArrayOutputStream out, String s) throws IOException { // If it's too big, out.writeUTF may not able able to write it out. if (s.length() < Short.MAX_VALUE / 4) { out.writeByte(STRING_TYPE); out.writeUTF(s); } else { out.writeByte(BIG_STRING_TYPE); out.writeUTF(s); } }
public static void marshalShort(DataByteArrayOutputStream out, short value) throws IOException { out.writeByte(SHORT_TYPE); out.writeShort(value); }
public static void marshalLong(DataByteArrayOutputStream out, long value) throws IOException { out.writeByte(LONG_TYPE); out.writeLong(value); }
public static void marshalFloat(DataByteArrayOutputStream out, float value) throws IOException { out.writeByte(FLOAT_TYPE); out.writeFloat(value); }
public static void marshalBoolean(DataByteArrayOutputStream dataOut, boolean value) throws IOException { dataOut.writeByte(BOOLEAN_TYPE); dataOut.writeBoolean(value); }
public static void marshalChar(DataByteArrayOutputStream out, char value) throws IOException { out.writeByte(CHAR_TYPE); out.writeChar(value); }
public static void marshalFloat(DataByteArrayOutputStream out, float value) throws IOException { out.writeByte(FLOAT_TYPE); out.writeFloat(value); }
public static void marshalChar(DataByteArrayOutputStream out, char value) throws IOException { out.writeByte(CHAR_TYPE); out.writeChar(value); }
public static void marshalByteArray(DataByteArrayOutputStream out, byte[] value, int offset, int length) throws IOException { out.writeByte(BYTE_ARRAY_TYPE); out.writeInt(length); out.write(value, offset, length); }
public static void marshalByteArray(DataByteArrayOutputStream out, byte[] value, int offset, int length) throws IOException { out.writeByte(BYTE_ARRAY_TYPE); out.writeInt(length); out.write(value, offset, length); }
public MQTTFrame encode() { try { DataByteArrayOutputStream os = new DataByteArrayOutputStream(2); os.writeByte(0); os.writeByte(code.ordinal()); MQTTFrame frame = new MQTTFrame(); frame.commandType(TYPE); return frame.buffer(os.toBuffer()); } catch (IOException e) { throw new RuntimeException("The impossible happened"); } }
/** * Write the booleans that this object uses to a BooleanStream */ public void looseMarshal(OpenWireFormat wireFormat, Object o, DataByteArrayOutputStream dataOut) throws IOException { TransactionInfo info = (TransactionInfo)o; super.looseMarshal(wireFormat, o, dataOut); looseMarshalCachedObject(wireFormat, (DataStructure)info.getConnectionId(), dataOut); looseMarshalCachedObject(wireFormat, (DataStructure)info.getTransactionId(), dataOut); dataOut.writeByte(info.getType()); } }
/** * Write the booleans that this object uses to a BooleanStream */ public void looseMarshal(OpenWireFormat wireFormat, Object o, DataByteArrayOutputStream dataOut) throws IOException { TransactionInfo info = (TransactionInfo)o; super.looseMarshal(wireFormat, o, dataOut); looseMarshalCachedObject(wireFormat, (DataStructure)info.getConnectionId(), dataOut); looseMarshalCachedObject(wireFormat, (DataStructure)info.getTransactionId(), dataOut); dataOut.writeByte(info.getType()); } }