Skip to content

Commit

Permalink
Improve the documentation on the tokens
Browse files Browse the repository at this point in the history
  • Loading branch information
Garanas committed May 5, 2024
1 parent 1cad3f5 commit 74e2196
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,6 @@ public record Token(TokenId tokenId, int tokenSize, byte[] tokenContent) {
public enum TokenId {
CMDST_ADVANCE,
CMDST_SET_COMMAND_SOURCE,

/**
* When a player leaves the game
*/
CMDST_COMMAND_SOURCE_TERMINATED,
CMDST_VERIFY_CHECKSUM,
CMDST_REQUEST_PAUSE,
Expand All @@ -23,15 +19,7 @@ public enum TokenId {
CMDST_ISSUE_FACTORY_COMMAND,
CMDST_INCREASE_COMMAND_COUNT,
CMDST_DECRASE_COMMAND_COUNT,

/**
* When you adjust the target of an order
*/
CMDST_SET_COMMAND_TARGET,

/**
* When you transform a move order into a patrol order
*/
CMDST_SET_COMMAND_TYPE,
CMDST_SET_COMMAND_CELLS,
CMDST_REMOVE_COMMAND_FROM_QUEUE,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,15 @@
@Slf4j
public class Tokenizer {

private static final int TOKEN_HEADER_LENGTH = 3;

public static List<Token> tokenize(LittleEndianDataInputStream dataStream) throws IOException {
ArrayList<Token> tokens = new ArrayList<>();
while (dataStream.available() > 0) {
int tokenId = dataStream.readUnsignedByte();
int tokenLength = dataStream.readUnsignedShort();
byte[] tokenContent = dataStream.readNBytes( tokenLength - 3);

byte[] tokenContent = dataStream.readNBytes(tokenLength - TOKEN_HEADER_LENGTH);

tokens.add(new Token(Token.TokenId.values()[tokenId], tokenLength, tokenContent));
}
Expand Down

0 comments on commit 74e2196

Please sign in to comment.