11package com .xxdb .streaming .client .cep ;
22
3+ import com .xxdb .data .AbstractVector ;
34import com .xxdb .data .Entity ;
45import com .xxdb .io .ExtendedDataOutput ;
56import 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