Commit 45b8e760 authored by Sven Gestegård Robertz's avatar Sven Gestegård Robertz
Browse files

java version2006 written, not tested

parent 7e0a91ce
......@@ -13,18 +13,26 @@ MODULES=LabCommDispatcher \
LabCommReader \
WriterWrapper
all: labcomm.jar
all: labcomm.jar labcomm2006.jar
labcomm.jar: gen/JAVAC
echo $@
cd gen ; jar cf ../$@ se/lth/control/labcomm/*.class
labcomm2006.jar: gen/JAVAC
echo $@
cd gen ; jar cf ../$@ se/lth/control/labcomm2006/*.class
gen:
mkdir gen
gen/JAVAC: $(MODULES:%=se/lth/control/labcomm/%.java) Makefile | gen
gen/JAVAC: $(MODULES:%=se/lth/control/labcomm/%.java) $(MODULES:%=se/lth/control/labcomm2006/%.java) Makefile | gen
javac -d gen $(filter %.java, $^)
touch $@
.PHONY: clean
clean:
rm -rf labcomm.jar gen
rm -rf labcomm.jar gen labcomm2006.jar
......@@ -27,6 +27,6 @@ public class LabComm {
/*
* Start of user declared types
*/
public static final int FIRST_USER_INDEX = 0x40;
public static final int FIRST_USER_INDEX = 0x80;
}
......@@ -134,19 +134,12 @@ public class LabCommDecoderChannel implements LabCommDecoder {
return new String(chars);
}
/**
method for API harmonization with labcomm2013.
Labcomm2006 encodes lengths etc as 32 bit ints.
*/
public int decodePacked32() throws IOException {
long res=0;
byte i=0;
boolean cont=true;
do {
byte c = in.readByte();
res = (res << 7) | (c & 0x7f);
cont = (c & 0x80) != 0;
i++;
} while(cont);
return (int) (res & 0xffffffff);
return in.readInt();
}
}
......@@ -19,7 +19,7 @@ public class LabCommEncoderChannel implements LabCommEncoder {
data = new DataOutputStream(bytes);
registry = new LabCommEncoderRegistry();
if (emitVersion) {
throw new RuntimeError("Labcomm 2006 does not support emitVersion");
throw new IllegalArgumentException("Labcomm 2006 does not support emitVersion");
}
}
......@@ -91,27 +91,17 @@ public class LabCommEncoderChannel implements LabCommEncoder {
public void encodeString(String value) throws IOException {
data.writeShort(0); // HACK...
data.writeUTF(value);
//kludge, to replace above hack with packed length
ByteArrayOutputStream tmpb = new ByteArrayOutputStream();
DataOutputStream tmps = new DataOutputStream(tmpb);
tmps.writeUTF(value);
tmps.flush();
byte[] tmp = tmpb.toByteArray();
encodePacked32(tmp.length-2);
for (int i = 2 ; i < tmp.length ; i++) {
encodeByte(tmp[i]);
}
}
/**
method for API harmonization with labcomm2013.
Labcomm2006 encodes lengths etc as 32 bit ints.
*/
public inline void encodePacked32(long value) throws IOException {
encodeInt(value);
public void encodePacked32(long value) throws IOException {
if(value > Integer.MAX_VALUE) {
throw new IllegalArgumentException("Value too large, must fit in 32 bits");
}
encodeInt((int) value);
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment