Skip to content

Commit

Permalink
fix decoder always return null
Browse files Browse the repository at this point in the history
  • Loading branch information
topi-banana committed Dec 3, 2024
1 parent c3cb719 commit 191efdf
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/main/java/com/vulpeus/kyoyu/net/KyoyuPacketManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public class KyoyuPacketManager {
}

private static IKyoyuPacket decode(byte[] raw) {
IKyoyuPacket res = null;
try (ByteArrayInputStream bais = new ByteArrayInputStream(raw); DataInputStream dis = new DataInputStream(bais)) {
String key = dis.readUTF();
int len = dis.readInt();
Expand All @@ -25,7 +26,7 @@ private static IKyoyuPacket decode(byte[] raw) {
Class<? extends IKyoyuPacket> packetClass = packetRegistry.get(key);
if (packetClass != null) {
try {
IKyoyuPacket packet = packetClass.getDeclaredConstructor(byte[].class).newInstance((Object) data);
res = packetClass.getDeclaredConstructor(byte[].class).newInstance((Object) data);
} catch (Exception e) {
e.printStackTrace();
}
Expand All @@ -36,7 +37,7 @@ private static IKyoyuPacket decode(byte[] raw) {
throw new RuntimeException(e);
}

return null;
return res;
}

private static byte[] encode(IKyoyuPacket packet) {
Expand Down

0 comments on commit 191efdf

Please sign in to comment.