generateCmdID

master
Alex 2022-01-01 17:16:34 +01:00
parent c0dd200e24
commit 83dad1ba08
2 changed files with 10 additions and 10 deletions

View File

@ -3,7 +3,6 @@ package earth.krakatao;
import earth.krakatao.events.KraSocketClientEventInitiater;
import earth.krakatao.events.KraSocketClientEventInterface;
import earth.krakatao.protocol.KraSocketClientProtocol;
import earth.krakatao.protocol.KraSocketClientProtocolMessage;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.logging.Logger;

View File

@ -18,19 +18,20 @@ public class KraSocketClientProtocol {
@Getter
HashMap<Integer, Consumer<KraSocketClientProtocolMessage>> consumerHashMap = new HashMap<>();
public int getCmdID() {
if (cmdIDs.isEmpty()) {
cmdIDs.add(10);
return 10;
private int currentCmdIDIndex = 10;
public int generateCmdID() {
// TODO: check max int value 2^32
if (this.currentCmdIDIndex < 10 || this.currentCmdIDIndex > 15000) {
this.currentCmdIDIndex = 10;
return this.currentCmdIDIndex;
}
int cmdID = cmdIDs.get(cmdIDs.size() - 1) + 1;
this.currentCmdIDIndex++;
cmdIDs.add(cmdID);
KraSocketClient.getLogger().info("currentCmdIDIndex:" + currentCmdIDIndex);
// TODO: check max int value 2^32
return cmdID;
return this.currentCmdIDIndex;
}
public byte[] EncodeMessage(KraSocketClientProtocolMessage kraProtocolMessage) {