Networking #2
@ -20,21 +20,19 @@
|
||||
package de.steamwar.network.packets;
|
||||
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.SneakyThrows;
|
||||
|
||||
import java.io.*;
|
||||
|
||||
Lixfel markierte diese Unterhaltung als gelöst
Veraltet
|
||||
@EqualsAndHashCode
|
||||
public abstract class NetworkPacket implements Serializable {
|
||||
|
||||
@SneakyThrows
|
||||
public byte[] serialize() {
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
try {
|
||||
ObjectOutputStream oos = new ObjectOutputStream(baos);
|
||||
oos.writeObject(this);
|
||||
oos.flush();
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
ObjectOutputStream oos = new ObjectOutputStream(baos);
|
||||
oos.writeObject(this);
|
||||
oos.flush();
|
||||
Chaoscaot markierte diese Unterhaltung als gelöst
Veraltet
Lixfel
hat
Wären das nicht nur IOExceptions? Ansonsten gäbe es ja auch die ExceptionA | ExceptionB -Syntax. Wären das nicht nur IOExceptions? Ansonsten gäbe es ja auch die ExceptionA | ExceptionB -Syntax.
|
||||
return baos.toByteArray();
|
||||
}
|
||||
|
||||
@ -42,13 +40,10 @@ public abstract class NetworkPacket implements Serializable {
|
||||
PacketHandler.handlePacket(deserialize(data));
|
||||
}
|
||||
|
||||
@SneakyThrows
|
||||
public static NetworkPacket deserialize(byte[] data) {
|
||||
ByteArrayInputStream bais = new ByteArrayInputStream(data);
|
||||
try {
|
||||
ObjectInputStream ois = new ObjectInputStream(bais);
|
||||
return (NetworkPacket) ois.readObject();
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
ObjectInputStream ois = new ObjectInputStream(bais);
|
||||
return (NetworkPacket) ois.readObject();
|
||||
}
|
||||
}
|
||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren
Brauchts das ganze EqualsAndHashCode-Zeug tatsächlich?
wegen den Tests