Skip to content

Commit

Permalink
Merge two enums
Browse files Browse the repository at this point in the history
  • Loading branch information
ustc-zzzz committed Dec 6, 2023
1 parent bbb486f commit f54b423
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,6 @@ public final class ProjectorURLSummaryPacket implements Function<ProjectorURL, P
private final HashFunction hmacNonceFunction;
private final Object2BooleanMap<Bits256> hmacUrlToBlockStatus;

private enum Status {
END, BLOCKED, UNBLOCKED
}

public ProjectorURLSummaryPacket(BiMap<UUID, ProjectorURL> idToUrl, Set<UUID> blockedIdSet) {
var hmacNonce = Bits256.random();
var hmacNonceFunction = Hashing.hmacSha256(hmacNonce.toBytes());
Expand All @@ -61,15 +57,15 @@ public ProjectorURLSummaryPacket(FriendlyByteBuf buf) {
var nonce = Bits256.read(buf);
var hmacUrlToBlockStatus = new Object2BooleanArrayMap<Bits256>(defaultCapacity);
while (true) {
switch (buf.readEnum(Status.class)) {
case END -> {
switch (buf.readEnum(ProjectorURL.Status.class)) {
case UNKNOWN -> {
this.hmacNonce = nonce;
this.hmacNonceFunction = Hashing.hmacSha256(nonce.toBytes());
this.hmacUrlToBlockStatus = Object2BooleanMaps.unmodifiable(hmacUrlToBlockStatus);
return;
}
case BLOCKED -> hmacUrlToBlockStatus.put(Bits256.read(buf), true);
case UNBLOCKED -> hmacUrlToBlockStatus.put(Bits256.read(buf), false);
case ALLOWED -> hmacUrlToBlockStatus.put(Bits256.read(buf), false);
}
}
}
Expand All @@ -85,10 +81,10 @@ public void sendToClient(ServerPlayer player) {
public void write(FriendlyByteBuf buf) {
this.hmacNonce.write(buf);
for (var entry : this.hmacUrlToBlockStatus.object2BooleanEntrySet()) {
buf.writeEnum(entry.getBooleanValue() ? ProjectorURLSummaryPacket.Status.BLOCKED : ProjectorURLSummaryPacket.Status.UNBLOCKED);
buf.writeEnum(entry.getBooleanValue() ? ProjectorURL.Status.BLOCKED : ProjectorURL.Status.ALLOWED);
entry.getKey().write(buf);
}
buf.writeEnum(ProjectorURLSummaryPacket.Status.END);
buf.writeEnum(ProjectorURL.Status.UNKNOWN);
}

@Override
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/teacon/slides/url/ProjectorURL.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public boolean equals(Object o) {
}

public enum Status {
BLOCKED, ALLOWED, UNKNOWN;
UNKNOWN, BLOCKED, ALLOWED;

public boolean isBlocked() {
return this == BLOCKED;
Expand Down

0 comments on commit f54b423

Please sign in to comment.