String protocol = msg.getProtocol();
String conversationId = msg.getConversationId();
String inReplyTo = msg.getInReplyTo();
String replyWith = msg.getReplyWith();
Date replyBy = msg.getReplyByDate();
Properties props = msg.getAllUserDefinedParameters();
if (props.size() > 63) {
throw new IOException("Cannot serialize more than 63 params");
}
if (sender != null) { presence1 |= 0x80; }
if (language != null) { presence1 |= 0x40; }
if (ontology != null) { presence1 |= 0x20; }
if (encoding != null) { presence1 |= 0x10; }
if (protocol != null) { presence1 |= 0x08; }
if (conversationId != null) { presence1 |= 0x04; }
if (inReplyTo != null) { presence1 |= 0x02; }
if (replyWith != null) { presence1 |= 0x01; }
if (replyBy != null) { presence2 |= 0x80; }
presence2 |= (props.size() & 0x3F);
dos.writeByte(presence1);
dos.writeByte(presence2);
if (sender != null) { serializeAID(sender, dos); }
if (language != null) { dos.writeUTF(language); }