Require a buffer to be passed along.

This commit is contained in:
md_5 2013-02-01 21:33:31 +11:00
parent 684600a423
commit 6bb9a14cd1
11 changed files with 30 additions and 32 deletions

View File

@ -6,10 +6,10 @@ import java.io.IOException;
public class BulkChunk extends Instruction { public class BulkChunk extends Instruction {
@Override @Override
void read(DataInput in) throws IOException { void read(DataInput in, byte[] buffer) throws IOException {
short count = in.readShort(); short count = in.readShort();
int size = in.readInt(); int size = in.readInt();
in.readBoolean(); in.readBoolean();
skip(in, size + count * 12); skip(in, buffer, size + count * 12);
} }
} }

View File

@ -12,10 +12,10 @@ class ByteHeader extends Instruction {
} }
@Override @Override
void read(DataInput in) throws IOException { void read(DataInput in, byte[] buffer) throws IOException {
byte size = in.readByte(); byte size = in.readByte();
for (byte b = 0; b < size; b++) { for (byte b = 0; b < size; b++) {
child.read(in); child.read(in, buffer);
} }
} }
} }

View File

@ -47,7 +47,7 @@ public class DataInputPacketReader {
} }
} }
public static void readPacket(DataInput in) throws IOException { public static void readPacket(DataInput in, byte[] buffer) throws IOException {
int packetId = in.readUnsignedByte(); int packetId = in.readUnsignedByte();
Instruction[] packetDef = instructions[packetId]; Instruction[] packetDef = instructions[packetId];
@ -56,7 +56,7 @@ public class DataInputPacketReader {
} }
for (Instruction instruction : packetDef) { for (Instruction instruction : packetDef) {
instruction.read(in); instruction.read(in, buffer);
} }
} }
} }

View File

@ -25,12 +25,10 @@ abstract class Instruction {
static final Instruction USHORT_BYTE = new UnsignedShortByte(); static final Instruction USHORT_BYTE = new UnsignedShortByte();
// Illegal forward references below this line // Illegal forward references below this line
static final Instruction BYTE_INT = new ByteHeader(INT); static final Instruction BYTE_INT = new ByteHeader(INT);
// Buffer used to read all skips, make sure it is sufficiently large (1mb packet at the moment)
static final byte[] buf = new byte[1 << 20];
abstract void read(DataInput in) throws IOException; abstract void read(DataInput in, byte[] buffer) throws IOException;
final void skip(DataInput in, int len) throws IOException { final void skip(DataInput in, byte[] buffer, int len) throws IOException {
in.readFully(buf, 0, len); in.readFully(buffer, 0, len);
} }
} }

View File

@ -12,10 +12,10 @@ class IntHeader extends Instruction {
} }
@Override @Override
void read(DataInput in) throws IOException { void read(DataInput in, byte[] buffer) throws IOException {
int size = in.readInt(); int size = in.readInt();
for (int i = 0; i < size; i++) { for (int i = 0; i < size; i++) {
child.read(in); child.read(in, buffer);
} }
} }
} }

View File

@ -6,11 +6,11 @@ import java.io.IOException;
class Item extends Instruction { class Item extends Instruction {
@Override @Override
void read(DataInput in) throws IOException { void read(DataInput in, byte[] buffer) throws IOException {
short type = in.readShort(); short type = in.readShort();
if (type >= 0) { if (type >= 0) {
skip(in, 3); skip(in, buffer, 3);
SHORT_BYTE.read(in); SHORT_BYTE.read(in, buffer);
} }
} }
} }

View File

@ -15,7 +15,7 @@ class Jump extends Instruction {
} }
@Override @Override
void read(DataInput in) throws IOException { void read(DataInput in, byte[] buffer) throws IOException {
skip(in, len); skip(in, buffer, len);
} }
} }

View File

@ -6,31 +6,31 @@ import java.io.IOException;
class MetaData extends Instruction { class MetaData extends Instruction {
@Override @Override
void read(DataInput in) throws IOException { void read(DataInput in, byte[] buffer) throws IOException {
int x = in.readUnsignedByte(); int x = in.readUnsignedByte();
while (x != 127) { while (x != 127) {
int type = x >> 5; int type = x >> 5;
switch (type) { switch (type) {
case 0: case 0:
BYTE.read(in); BYTE.read(in, buffer);
break; break;
case 1: case 1:
SHORT.read(in); SHORT.read(in, buffer);
break; break;
case 2: case 2:
INT.read(in); INT.read(in, buffer);
break; break;
case 3: case 3:
FLOAT.read(in); FLOAT.read(in, buffer);
break; break;
case 4: case 4:
STRING.read(in); STRING.read(in, buffer);
break; break;
case 5: case 5:
ITEM.read(in); ITEM.read(in, buffer);
break; break;
case 6: case 6:
skip(in, 12); // int, int, int skip(in, buffer, 12); // int, int, int
break; break;
default: default:
throw new IllegalArgumentException("Unknown metadata type " + type); throw new IllegalArgumentException("Unknown metadata type " + type);

View File

@ -6,10 +6,10 @@ import java.io.IOException;
public class OptionalMotion extends Instruction { public class OptionalMotion extends Instruction {
@Override @Override
void read(DataInput in) throws IOException { void read(DataInput in, byte[] buffer) throws IOException {
int data = in.readInt(); int data = in.readInt();
if (data > 0) { if (data > 0) {
skip(in, 6); skip(in, buffer, 6);
} }
} }
} }

View File

@ -12,10 +12,10 @@ class ShortHeader extends Instruction {
} }
@Override @Override
void read(DataInput in) throws IOException { void read(DataInput in, byte[] buffer) throws IOException {
short size = in.readShort(); short size = in.readShort();
for (short s = 0; s < size; s++) { for (short s = 0; s < size; s++) {
child.read(in); child.read(in, buffer);
} }
} }
} }

View File

@ -6,8 +6,8 @@ import java.io.IOException;
public class UnsignedShortByte extends Instruction { public class UnsignedShortByte extends Instruction {
@Override @Override
void read(DataInput in) throws IOException { void read(DataInput in, byte[] buffer) throws IOException {
int size = in.readUnsignedShort(); int size = in.readUnsignedShort();
skip(in, size); skip(in, buffer, size);
} }
} }