Commit cee89a52 authored by Sven Robertz's avatar Sven Robertz
Browse files

added a small comment on the packing + added untested code to the csharp lib +...

added a small comment on the packing + added untested code to the csharp lib + changed BASE_UID to 0x60
parent 9e27c274
......@@ -30,7 +30,7 @@
/*
* Start index for user defined types
*/
#define LABCOMM_USER 0x80
#define LABCOMM_USER 0x60
/*
* Semi private decoder declarations
......@@ -269,6 +269,13 @@ LABCOMM_ENCODE(long, long long)
LABCOMM_ENCODE(float, float)
LABCOMM_ENCODE(double, double)
/*
* Pack the 32 bit number data as a sequence of 7 bit chunks, represented in bytes
* with the high bit meaning that more data is to come.
*
* The chunks are sent "little endian": each 7 bit chunk is more significant than
* the previous.
*/
static inline void labcomm_pack32(labcomm_writer_t *w, unsigned int data)
{
unsigned int tmp, i;
......
......@@ -25,7 +25,7 @@ namespace se.lth.control.labcomm {
/*
* start of user defined types
*/
public const int FIRST_USER_INDEX = 0x80;
public const int FIRST_USER_INDEX = 0x60;
}
......
......@@ -18,11 +18,11 @@ namespace se.lth.control.labcomm {
public void runOne() {
bool done = false;
while (!done) {
int tag = decodeInt();
int tag = decodePacked32();
switch (tag) {
case LabComm.TYPEDEF:
case LabComm.SAMPLE: {
int index = decodeInt();
int index = decodePacked32();
String name = decodeString();
MemoryStream signature = new MemoryStream();
collectFlatSignature(new LabCommEncoderChannel(signature));
......@@ -55,19 +55,19 @@ namespace se.lth.control.labcomm {
}
private void collectFlatSignature(LabCommEncoder e) {
int type = decodeInt();
int type = decodePacked32();
e.encodeInt(type);
switch (type) {
case LabComm.ARRAY: {
int dimensions = decodeInt();
e.encodeInt(dimensions);
int dimensions = decodePacked32();
e.encodePacked32(dimensions);
for (int i = 0 ; i < dimensions ; i++) {
e.encodeInt(decodeInt());
e.encodePacked32(decodePacked32());
}
collectFlatSignature(e);
} break;
case LabComm.STRUCT: {
int fields = decodeInt();
int fields = decodePacked32();
e.encodeInt(fields);
for (int i = 0 ; i < fields ; i++) {
e.encodeString(decodeString());
......@@ -155,12 +155,26 @@ namespace se.lth.control.labcomm {
}
public String decodeString() {
int length = (int)ReadInt(4);
//int length = (int)ReadInt(4);
int length = decodePacked32();
byte[] buf = new byte[length];
ReadBytes(buf, length);
return Encoding.UTF8.GetString(buf);
}
}
public int decodePacked32() {
Int64 res = 0;
byte i = 0;
bool cont = true;
do {
byte c = decodeByte();
res |= (c & 0x7f) << 7*i;
cont = (c & 0x80) != 0;
i++;
} while(cont);
return (int) (res & 0xffffffff);
}
}
}
......@@ -18,8 +18,8 @@ namespace se.lth.control.labcomm {
public void register(LabCommDispatcher dispatcher) {
int index = registry.add(dispatcher);
encodeInt(LabComm.SAMPLE);
encodeInt(index);
encodePacked32(LabComm.SAMPLE);
encodePacked32(index);
encodeString(dispatcher.getName());
byte[] signature = dispatcher.getSignature();
for (int i = 0 ; i < signature.Length ; i++) {
......@@ -29,7 +29,7 @@ namespace se.lth.control.labcomm {
}
public void begin(Type c) {
encodeInt(registry.getTag(c));
encodePacked32(registry.getTag(c));
}
public void end(Type c) {
......@@ -84,9 +84,18 @@ namespace se.lth.control.labcomm {
public void encodeString(String value) {
byte[] buf = Encoding.UTF8.GetBytes(value);
WriteInt(buf.Length, 4);
EncodePacked32(buf.Length, 4);
bytes.Write(buf, 0, buf.Length);
}
public void encodePacked32(Int64 value) {
Int64 tmp = value;
while(tmp >= 0x80) {
encodeByte( (byte) ((tmp & 0x7f) | 0x80 ) );
tmp >>= 7;
}
encodeByte( (byte) (tmp & 0x7f) );
}
}
}
......@@ -25,6 +25,6 @@ public class LabComm {
/*
* Start of
*/
public static final int FIRST_USER_INDEX = 0x80;
public static final int FIRST_USER_INDEX = 0x60;
}
......@@ -44,7 +44,7 @@
# User data:
#
# +----+----+----+----+
# | id >= 0x00000080 |
# | id >= 0x00000060 |
# +----+----+----+----+
# | user data
# | ...
......@@ -107,7 +107,7 @@ i_FLOAT = 0x25
i_DOUBLE = 0x26
i_STRING = 0x27
i_USER = 0x80
i_USER = 0x60
def indent(i, s):
return ("\n%s" % (" " * i)).join(s.split("\n"))
......
Supports Markdown
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