diff --git a/G-Earth/src/main/java/gearth/protocol/HPacket.java b/G-Earth/src/main/java/gearth/protocol/HPacket.java index 5e3c757..6d2c711 100644 --- a/G-Earth/src/main/java/gearth/protocol/HPacket.java +++ b/G-Earth/src/main/java/gearth/protocol/HPacket.java @@ -14,7 +14,7 @@ import java.util.Arrays; import java.util.List; public class HPacket implements StringifyAble { - // te komen: toExpressions (+impl. expressies) + private boolean isEdited = false; private byte[] packetInBytes; private int readIndex = 6; @@ -326,6 +326,15 @@ public class HPacket implements StringifyAble { return java.nio.ByteBuffer.wrap(btarray).getInt(); } + public double readDouble(){ + double result = readDouble(readIndex); + readIndex += 8; + return result; + } + public double readDouble(int index) { + return java.nio.ByteBuffer.wrap(packetInBytes).getDouble(index); + } + public int length() { return readInteger(0); } @@ -413,6 +422,14 @@ public class HPacket implements StringifyAble { } return this; } + public HPacket replaceDouble(int index, double d) { + isEdited = true; + ByteBuffer b = ByteBuffer.allocate(8).putDouble(d); + for (int j = 0; j < 8; j++) { + packetInBytes[index + j] = b.array()[j]; + } + return this; + } public HPacket replaceByte(int index, byte b) { isEdited = true; packetInBytes[index] = b; @@ -573,6 +590,16 @@ public class HPacket implements StringifyAble { fixLength(); return this; } + public HPacket appendDouble(double d) { + isEdited = true; + packetInBytes = Arrays.copyOf(packetInBytes, packetInBytes.length + 8); + ByteBuffer byteBuffer = ByteBuffer.allocate(8).putDouble(d); + for (int j = 0; j < 8; j++) { + packetInBytes[packetInBytes.length - 8 + j] = byteBuffer.array()[j]; + } + fixLength(); + return this; + } public HPacket appendByte(byte b) { isEdited = true; packetInBytes = Arrays.copyOf(packetInBytes, packetInBytes.length + 1);