Skip to content

Commit 182ea49

Browse files
author
chengyitian
committed
AJ-884: fix issue about fast vector serialize in cep;
1 parent a733a28 commit 182ea49

File tree

1 file changed

+44
-2
lines changed

1 file changed

+44
-2
lines changed

src/com/xxdb/streaming/client/cep/FastArrayAttributeSerializer.java

Lines changed: 44 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.xxdb.streaming.client.cep;
22

3+
import com.xxdb.data.AbstractVector;
34
import com.xxdb.data.Entity;
45
import com.xxdb.io.ExtendedDataOutput;
56
import java.io.IOException;
@@ -12,7 +13,48 @@ public FastArrayAttributeSerializer(int unitLen) {
1213

1314
@Override
1415
public void serialize(Entity attribute, ExtendedDataOutput out) throws IOException {
15-
attribute.write(out);
16-
}
16+
int curCount = attribute.rows();
17+
if (curCount == 0) {
18+
out.writeShort((short)0);
19+
return;
20+
}
21+
22+
// Using signed types, but ensuring they are processed according to unsigned logic
23+
short arrayRows = 1;
24+
byte curCountBytes = 1;
25+
byte reserved = 0;
26+
int maxCount = 255;
27+
28+
while (curCount > maxCount) {
29+
curCountBytes *= 2;
30+
maxCount = (int)((1L << (8 * curCountBytes)) - 1);
31+
}
1732

33+
out.writeShort(arrayRows);
34+
out.writeByte(curCountBytes);
35+
out.writeByte(reserved);
36+
37+
switch (curCountBytes) {
38+
case 1:
39+
{
40+
// byte range: -128 to 127, but treated as unsigned for range 0 to 255
41+
out.writeByte((byte)(curCount & 0xFF));
42+
break;
43+
}
44+
case 2:
45+
{
46+
// short range: -32768 to 32767, but treated as unsigned for range 0 to 65535
47+
out.writeShort((short)(curCount & 0xFFFF));
48+
break;
49+
}
50+
default:
51+
{
52+
// int range: -2147483648 to 2147483647, sufficient for most cases
53+
out.writeInt(curCount);
54+
break;
55+
}
56+
}
57+
58+
((AbstractVector)attribute).serialize(0, curCount, out);
59+
}
1860
}

0 commit comments

Comments
 (0)