Better IO
This commit is contained in:
@@ -2,10 +2,12 @@ package mindustry.net;
|
||||
|
||||
import arc.*;
|
||||
import arc.struct.*;
|
||||
import arc.util.io.*;
|
||||
import arc.util.serialization.*;
|
||||
import mindustry.core.*;
|
||||
import mindustry.io.*;
|
||||
|
||||
import java.io.*;
|
||||
import java.nio.*;
|
||||
|
||||
/**
|
||||
@@ -65,31 +67,29 @@ public class Packets{
|
||||
}
|
||||
|
||||
public static class InvokePacket implements Packet{
|
||||
private static ReusableByteInStream bin;
|
||||
private static Reads read = new Reads(new DataInputStream(bin = new ReusableByteInStream()));
|
||||
|
||||
public byte type, priority;
|
||||
|
||||
public ByteBuffer writeBuffer;
|
||||
public int writeLength;
|
||||
public byte[] bytes;
|
||||
public int length;
|
||||
|
||||
@Override
|
||||
public void read(ByteBuffer buffer){
|
||||
type = buffer.get();
|
||||
priority = buffer.get();
|
||||
writeLength = buffer.getShort();
|
||||
short writeLength = buffer.getShort();
|
||||
byte[] bytes = new byte[writeLength];
|
||||
buffer.get(bytes);
|
||||
writeBuffer = ByteBuffer.wrap(bytes);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(ByteBuffer buffer){
|
||||
buffer.put(type);
|
||||
buffer.put(priority);
|
||||
buffer.putShort((short)writeLength);
|
||||
|
||||
writeBuffer.position(0);
|
||||
for(int i = 0; i < writeLength; i++){
|
||||
buffer.put(writeBuffer.get());
|
||||
}
|
||||
buffer.putShort((short)length);
|
||||
buffer.put(bytes, 0, length);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -106,6 +106,11 @@ public class Packets{
|
||||
public boolean isUnimportant(){
|
||||
return priority == 2;
|
||||
}
|
||||
|
||||
public Reads reader(){
|
||||
bin.setBytes(bytes);
|
||||
return read;
|
||||
}
|
||||
}
|
||||
|
||||
/** Marks the beginning of a stream. */
|
||||
|
||||
Reference in New Issue
Block a user