All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.vertx.mqtt.messages.codes.ReasonCodeUtils Maven / Gradle / Ivy

The newest version!
package io.vertx.mqtt.messages.codes;

/**
 * Utilities for MQTT message codes enums
 */
public class ReasonCodeUtils {
    static  void fillValuesByCode(C[] valuesByCode, C[] values) {
        for (C code : values) {
            final int unsignedByte = code.value() & 0xFF;
            valuesByCode[unsignedByte] = code;
        }
    }

    static  C codeLookup(C[] valuesByCode, byte b, String codeType) {
        final int unsignedByte = b & 0xFF;
        C reasonCode = null;
        try {
            reasonCode = valuesByCode[unsignedByte];
        } catch (ArrayIndexOutOfBoundsException ignored) {
            // no op
        }
        if (reasonCode == null) {
            throw new IllegalArgumentException("unknown " + codeType + " reason code: " + unsignedByte);
        }
        return reasonCode;
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy