use of com.swiftmq.impl.mqtt.v311.netty.handler.codec.mqtt.MqttFixedHeader in project swiftmq-ce by iitsoftware.
the class MqttEncoder method encodeMessageWithOnlySingleByteFixedHeaderAndMessageId.
private static com.swiftmq.impl.mqtt.v311.netty.buffer.ByteBuf encodeMessageWithOnlySingleByteFixedHeaderAndMessageId(MqttMessage message) {
MqttFixedHeader mqttFixedHeader = message.fixedHeader();
MqttMessageIdVariableHeader variableHeader = (MqttMessageIdVariableHeader) message.variableHeader();
int msgId = variableHeader.messageId();
// variable part only has a message id
int variableHeaderBufferSize = 2;
int fixedHeaderBufferSize = 1 + getVariableLengthInt(variableHeaderBufferSize);
com.swiftmq.impl.mqtt.v311.netty.buffer.ByteBuf buf = new com.swiftmq.impl.mqtt.v311.netty.buffer.ByteBuf(fixedHeaderBufferSize + variableHeaderBufferSize);
buf.writeByte(getFixedHeaderByte1(mqttFixedHeader));
writeVariableLengthInt(buf, variableHeaderBufferSize);
buf.writeShort(msgId);
return buf;
}
use of com.swiftmq.impl.mqtt.v311.netty.handler.codec.mqtt.MqttFixedHeader in project swiftmq-ce by iitsoftware.
the class MqttEncoder method encodePublishMessage.
private static com.swiftmq.impl.mqtt.v311.netty.buffer.ByteBuf encodePublishMessage(MqttPublishMessage message) {
MqttFixedHeader mqttFixedHeader = message.fixedHeader();
MqttPublishVariableHeader variableHeader = message.variableHeader();
com.swiftmq.impl.mqtt.v311.netty.buffer.ByteBuf payload = message.payload().duplicate();
String topicName = variableHeader.topicName();
byte[] topicNameBytes = encodeStringUtf8(topicName);
int variableHeaderBufferSize = 2 + topicNameBytes.length + (mqttFixedHeader.qosLevel().value() > 0 ? 2 : 0);
int payloadBufferSize = payload.readableBytes();
int variablePartSize = variableHeaderBufferSize + payloadBufferSize;
int fixedHeaderBufferSize = 1 + getVariableLengthInt(variablePartSize);
com.swiftmq.impl.mqtt.v311.netty.buffer.ByteBuf buf = new com.swiftmq.impl.mqtt.v311.netty.buffer.ByteBuf(fixedHeaderBufferSize + variablePartSize);
buf.writeByte(getFixedHeaderByte1(mqttFixedHeader));
writeVariableLengthInt(buf, variablePartSize);
buf.writeShort(topicNameBytes.length);
buf.writeBytes(topicNameBytes);
if (mqttFixedHeader.qosLevel().value() > 0) {
buf.writeShort(variableHeader.messageId());
}
buf.writeBytes(payload);
return buf;
}
use of com.swiftmq.impl.mqtt.v311.netty.handler.codec.mqtt.MqttFixedHeader in project swiftmq-ce by iitsoftware.
the class MqttEncoder method encodeMessageWithOnlySingleByteFixedHeader.
private static com.swiftmq.impl.mqtt.v311.netty.buffer.ByteBuf encodeMessageWithOnlySingleByteFixedHeader(MqttMessage message) {
MqttFixedHeader mqttFixedHeader = message.fixedHeader();
com.swiftmq.impl.mqtt.v311.netty.buffer.ByteBuf buf = new com.swiftmq.impl.mqtt.v311.netty.buffer.ByteBuf(2);
buf.writeByte(getFixedHeaderByte1(mqttFixedHeader));
buf.writeByte(0);
return buf;
}
use of com.swiftmq.impl.mqtt.v311.netty.handler.codec.mqtt.MqttFixedHeader in project swiftmq-ce by iitsoftware.
the class Producer method send.
public void send(MqttPublishMessage mqttPublishMessage) throws Exception {
MqttFixedHeader fixedHeader = mqttPublishMessage.fixedHeader();
ByteBuf payload = mqttPublishMessage.payload();
BytesMessageImpl bytesMessage = new BytesMessageImpl();
bytesMessage.setJMSDestination(topic);
bytesMessage.setJMSTimestamp(System.currentTimeMillis());
bytesMessage.setJMSMessageID(session.getMqttConnection().nextId());
bytesMessage.setJMSDeliveryMode(DeliveryMode.PERSISTENT);
bytesMessage.setStringProperty(MessageImpl.PROP_USER_ID, session.getMqttConnection().getActiveLogin().getUserName());
bytesMessage.setStringProperty(MessageImpl.PROP_CLIENT_ID, session.getClientId());
if (fixedHeader.isDup())
bytesMessage.setBooleanProperty(MessageImpl.PROP_DOUBT_DUPLICATE, true);
bytesMessage.setIntProperty(PROP_QOS, fixedHeader.qosLevel().value());
payload.reset();
byte[] b = new byte[payload.size()];
payload.readBytes(b);
bytesMessage.writeBytes(b);
transaction = sender.createTransaction();
transaction.putMessage(bytesMessage);
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(ctx.mqttSwiftlet.getName(), toString() + ", sent: " + bytesMessage);
}
Aggregations