Commit 5fde48f3 authored by Anders Blomdell's avatar Anders Blomdell
Browse files

lib/csharp/se/lth/control/labcomm/LabCommEncoderChannel.cs:

  corrected encodeBoolean
  changed encodePacked32
  added a flush to end() method

lib/csharp/se/lth/control/labcomm/LabCommDecoderChannel.cs:
  corrected struct handling
  corrected readInt
  changed decodePacked32  
parent 1301ffcd
MODULES=LabCommDispatcher \
LabCommDecoderRegistry \
LabComm \
LabCommSample \
LabCommHandler \
LabCommEncoderRegistry \
LabCommDecoder \
LabCommType \
LabCommEncoderChannel \
LabCommEncoder \
LabCommDecoderChannel \
all: labcomm.dll
labcomm.dll: $(MODULES:%=se/lth/control/labcomm/%.cs) Makefile
mcs -out:$@ -target:library $(filter %.cs, $^)
clean:
rm labcomm.dll
......@@ -6,6 +6,7 @@ namespace se.lth.control.labcomm {
void register(LabCommDispatcher dispatcher,
LabCommHandler handler);
bool decodeBoolean();
byte decodeByte();
short decodeShort();
......@@ -14,6 +15,7 @@ namespace se.lth.control.labcomm {
float decodeFloat();
double decodeDouble();
String decodeString();
int decodePacked32();
}
......
......@@ -68,7 +68,7 @@ namespace se.lth.control.labcomm {
} break;
case LabComm.STRUCT: {
int fields = decodePacked32();
e.encodeInt(fields);
e.encodePacked32(fields);
for (int i = 0 ; i < fields ; i++) {
e.encodeString(decodeString());
collectFlatSignature(e);
......@@ -108,10 +108,11 @@ namespace se.lth.control.labcomm {
}
private Int64 ReadInt(int length) {
int result = 0;
Int64 result = 0;
ReadBytes(buf, length);
for (int i = 0 ; i < length ; i++) {
result = (result << 8) + buf[i];
}
return result;
}
......@@ -163,16 +164,13 @@ namespace se.lth.control.labcomm {
}
public int decodePacked32() {
TODO: Correct byteorder
Int64 res = 0;
byte i = 0;
bool cont = true;
do {
byte c = decodeByte();
res |= (uint) ((c & 0x7f) << 7*i);
Int64 c = decodeByte();
res = (res << 7) | (c & 0x7f);
cont = (c & 0x80) != 0;
i++;
} while(cont);
return (int) (res & 0xffffffff);
......
......@@ -7,6 +7,7 @@ namespace se.lth.control.labcomm {
void register(LabCommDispatcher dispatcher);
void begin(Type c);
void end(Type c);
void encodeBoolean(bool value);
void encodeByte(byte value);
void encodeShort(short value);
......
......@@ -35,6 +35,7 @@ namespace se.lth.control.labcomm {
public void end(Type c) {
bytes.WriteTo(writer);
bytes.SetLength(0);
writer.Flush();
}
private void WriteInt(Int64 value, int length) {
......@@ -46,7 +47,7 @@ namespace se.lth.control.labcomm {
}
public void encodeBoolean(bool value) {
WriteInt(value ? 0 : 1, 1);
WriteInt(value ? 1 : 0, 1);
}
public void encodeByte(byte value) {
......@@ -89,13 +90,16 @@ namespace se.lth.control.labcomm {
}
public void encodePacked32(Int64 value) {
Int64 tmp = value;
TODO: Correct byteorder
while(tmp >= 0x80) {
encodeByte( (byte) ((tmp & 0x7f) | 0x80 ) );
tmp >>= 7;
byte[] tmp = new byte[5];
Int64 v = value & 0xffffffff;
int i;
for (i = 0 ; i == 0 || v != 0 ; i++, v = (v >> 7)) {
tmp[i] = (byte)(v & 0x7f);
}
for (i = i - 1 ; i >= 0 ; i--) {
encodeByte((byte)(tmp[i] | (i!=0?0x80:0x00)));
}
encodeByte( (byte) (tmp & 0x7f) );
}
}
}
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