Updated SUBSCRIBE to be 3.1.1 compliant

This commit is contained in:
selva.andre
2014-08-02 12:30:28 +02:00
parent 53f87a6e4f
commit d1b54eb8cf
2 changed files with 53 additions and 1 deletions
@@ -38,6 +38,7 @@ class SubscribeDecoder extends DemuxDecoder {
in.resetReaderIndex();
return;
}
//TODO check reserved fixed flags = b0010
//check qos level
if (message.getQos() != QOSType.LEAST_ONE) {
@@ -53,6 +54,10 @@ class SubscribeDecoder extends DemuxDecoder {
readed = in.readerIndex()- start;
}
if (message.subscriptions().isEmpty()) {
throw new CorruptedFrameException("subscribe MUST have got at least 1 couple topic/QoS");
}
out.add(message);
}
@@ -61,7 +66,12 @@ class SubscribeDecoder extends DemuxDecoder {
*/
private void decodeSubscription(ByteBuf in, SubscribeMessage message) throws UnsupportedEncodingException {
String topic = Utils.decodeString(in);
byte qos = (byte)(in.readByte() & 0x03);
byte qosByte = in.readByte();
if ((qosByte & 0xFC) > 0) { //the first 6 bits is reserved => has to be 0
throw new CorruptedFrameException("subscribe MUST have QoS byte with reserved buts to 0, found " + Integer.toHexString(qosByte));
}
byte qos = (byte)(qosByte & 0x03);
//TODO check qos id 000000xx
message.addSubscription(new SubscribeMessage.Couple(qos, topic));
}