LZ4 compression
This commit is contained in:
@@ -16,6 +16,8 @@ import io.anuke.mindustry.net.Packets.Disconnect;
|
||||
import io.anuke.ucore.function.Consumer;
|
||||
import io.anuke.ucore.util.Pooling;
|
||||
import io.anuke.ucore.util.Strings;
|
||||
import net.jpountz.lz4.LZ4Factory;
|
||||
import net.jpountz.lz4.LZ4FastDecompressor;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.DatagramPacket;
|
||||
@@ -32,6 +34,7 @@ public class KryoClient implements ClientProvider{
|
||||
Client client;
|
||||
ObjectMap<InetAddress, Host> addresses = new ObjectMap<>();
|
||||
ClientDiscoveryHandler handler;
|
||||
LZ4FastDecompressor decompressor = LZ4Factory.fastestInstance().fastDecompressor();
|
||||
|
||||
public KryoClient(){
|
||||
KryoCore.init();
|
||||
@@ -105,6 +108,13 @@ public class KryoClient implements ClientProvider{
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] decompressSnapshot(byte[] input, int size){
|
||||
byte[] result = new byte[size];
|
||||
decompressor.decompress(input, result);
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void connect(String ip, int port) throws IOException {
|
||||
//just in case
|
||||
|
||||
@@ -20,6 +20,8 @@ import io.anuke.mindustry.net.Packets.StreamChunk;
|
||||
import io.anuke.ucore.UCore;
|
||||
import io.anuke.ucore.core.Timers;
|
||||
import io.anuke.ucore.util.Log;
|
||||
import net.jpountz.lz4.LZ4Compressor;
|
||||
import net.jpountz.lz4.LZ4Factory;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.ByteBuffer;
|
||||
@@ -33,6 +35,7 @@ public class KryoServer implements ServerProvider {
|
||||
final CopyOnWriteArrayList<KryoConnection> connections = new CopyOnWriteArrayList<>();
|
||||
final CopyOnWriteArraySet<Integer> missing = new CopyOnWriteArraySet<>();
|
||||
final Array<KryoConnection> array = new Array<>();
|
||||
final LZ4Compressor compressor = LZ4Factory.fastestInstance().fastCompressor();
|
||||
Thread serverThread;
|
||||
|
||||
int lastconnection = 0;
|
||||
@@ -105,6 +108,11 @@ public class KryoServer implements ServerProvider {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] compressSnapshot(byte[] input){
|
||||
return compressor.compress(input);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Array<KryoConnection> getConnections() {
|
||||
array.clear();
|
||||
|
||||
Reference in New Issue
Block a user