io.vertx.mqtt.messages.codes.ReasonCodeUtils Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of vertx-mqtt Show documentation
Show all versions of vertx-mqtt Show documentation
Vert.x MQTT reactive client and server
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;
}
}