Начало трансляции сервероного кода к новому протоколу
This commit is contained in:
52
src/main/java/im/rosetta/network/enums/ResultCode.java
Normal file
52
src/main/java/im/rosetta/network/enums/ResultCode.java
Normal file
@@ -0,0 +1,52 @@
|
||||
package im.rosetta.network.enums;
|
||||
|
||||
// Auto-generated by RCC (Rosetta Code Compiler). Do not edit manually.
|
||||
public enum ResultCode {
|
||||
SUCCESS(0),
|
||||
ERROR(1),
|
||||
INVALID(2),
|
||||
USERNAME_TAKEN(3);
|
||||
|
||||
private final Integer code;
|
||||
|
||||
ResultCode(Integer code) {
|
||||
this.code = code;
|
||||
}
|
||||
|
||||
public Integer getCode() {
|
||||
return code;
|
||||
}
|
||||
|
||||
public static ResultCode fromCode(int code) {
|
||||
return switch (code) {
|
||||
case 0 -> SUCCESS;
|
||||
case 1 -> ERROR;
|
||||
case 2 -> INVALID;
|
||||
case 3 -> USERNAME_TAKEN;
|
||||
default -> throw new IllegalArgumentException("Unknown ResultCode code: " + code);
|
||||
};
|
||||
}
|
||||
|
||||
public static ResultCode fromCode(int code, int version) {
|
||||
ResultCode value = fromCode(code);
|
||||
if (!value.isSupportedInVersion(version)) {
|
||||
throw new IllegalArgumentException("Unsupported ResultCode code " + code + " for version " + version);
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
public boolean isSupportedInVersion(int version) {
|
||||
return switch (this) {
|
||||
case SUCCESS -> true;
|
||||
case ERROR -> true;
|
||||
case INVALID -> true;
|
||||
case USERNAME_TAKEN -> true;
|
||||
};
|
||||
}
|
||||
|
||||
public void requireSupportedInVersion(int version) {
|
||||
if (!isSupportedInVersion(version)) {
|
||||
throw new IllegalArgumentException("Unsupported ResultCode value " + this + " for version " + version);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user