Search in sources :

Example 1 with IntegerProperty

use of io.netty.handler.codec.mqtt.MqttProperties.IntegerProperty in project netty by netty.

the class MqttDecoder method decodeProperties.

private static Result<MqttProperties> decodeProperties(ByteBuf buffer) {
    final long propertiesLength = decodeVariableByteInteger(buffer);
    int totalPropertiesLength = unpackA(propertiesLength);
    int numberOfBytesConsumed = unpackB(propertiesLength);
    MqttProperties decodedProperties = new MqttProperties();
    while (numberOfBytesConsumed < totalPropertiesLength) {
        long propertyId = decodeVariableByteInteger(buffer);
        final int propertyIdValue = unpackA(propertyId);
        numberOfBytesConsumed += unpackB(propertyId);
        MqttProperties.MqttPropertyType propertyType = MqttProperties.MqttPropertyType.valueOf(propertyIdValue);
        switch(propertyType) {
            case PAYLOAD_FORMAT_INDICATOR:
            case REQUEST_PROBLEM_INFORMATION:
            case REQUEST_RESPONSE_INFORMATION:
            case MAXIMUM_QOS:
            case RETAIN_AVAILABLE:
            case WILDCARD_SUBSCRIPTION_AVAILABLE:
            case SUBSCRIPTION_IDENTIFIER_AVAILABLE:
            case SHARED_SUBSCRIPTION_AVAILABLE:
                final int b1 = buffer.readUnsignedByte();
                numberOfBytesConsumed++;
                decodedProperties.add(new IntegerProperty(propertyIdValue, b1));
                break;
            case SERVER_KEEP_ALIVE:
            case RECEIVE_MAXIMUM:
            case TOPIC_ALIAS_MAXIMUM:
            case TOPIC_ALIAS:
                final int int2BytesResult = decodeMsbLsb(buffer);
                numberOfBytesConsumed += 2;
                decodedProperties.add(new IntegerProperty(propertyIdValue, int2BytesResult));
                break;
            case PUBLICATION_EXPIRY_INTERVAL:
            case SESSION_EXPIRY_INTERVAL:
            case WILL_DELAY_INTERVAL:
            case MAXIMUM_PACKET_SIZE:
                final int maxPacketSize = buffer.readInt();
                numberOfBytesConsumed += 4;
                decodedProperties.add(new IntegerProperty(propertyIdValue, maxPacketSize));
                break;
            case SUBSCRIPTION_IDENTIFIER:
                long vbIntegerResult = decodeVariableByteInteger(buffer);
                numberOfBytesConsumed += unpackB(vbIntegerResult);
                decodedProperties.add(new IntegerProperty(propertyIdValue, unpackA(vbIntegerResult)));
                break;
            case CONTENT_TYPE:
            case RESPONSE_TOPIC:
            case ASSIGNED_CLIENT_IDENTIFIER:
            case AUTHENTICATION_METHOD:
            case RESPONSE_INFORMATION:
            case SERVER_REFERENCE:
            case REASON_STRING:
                final Result<String> stringResult = decodeString(buffer);
                numberOfBytesConsumed += stringResult.numberOfBytesConsumed;
                decodedProperties.add(new MqttProperties.StringProperty(propertyIdValue, stringResult.value));
                break;
            case USER_PROPERTY:
                final Result<String> keyResult = decodeString(buffer);
                final Result<String> valueResult = decodeString(buffer);
                numberOfBytesConsumed += keyResult.numberOfBytesConsumed;
                numberOfBytesConsumed += valueResult.numberOfBytesConsumed;
                decodedProperties.add(new MqttProperties.UserProperty(keyResult.value, valueResult.value));
                break;
            case CORRELATION_DATA:
            case AUTHENTICATION_DATA:
                final byte[] binaryDataResult = decodeByteArray(buffer);
                numberOfBytesConsumed += binaryDataResult.length + 2;
                decodedProperties.add(new MqttProperties.BinaryProperty(propertyIdValue, binaryDataResult));
                break;
            default:
                // shouldn't reach here
                throw new DecoderException("Unknown property type: " + propertyType);
        }
    }
    return new Result<MqttProperties>(decodedProperties, numberOfBytesConsumed);
}
Also used : IntegerProperty(io.netty.handler.codec.mqtt.MqttProperties.IntegerProperty) DecoderException(io.netty.handler.codec.DecoderException)

Aggregations

DecoderException (io.netty.handler.codec.DecoderException)1 IntegerProperty (io.netty.handler.codec.mqtt.MqttProperties.IntegerProperty)1