33import com .fasterxml .jackson .annotation .JsonValue ;
44import dev .zarr .zarrjava .core .codec .ArrayBytesCodec ;
55import ucar .ma2 .Array ;
6+ import ucar .ma2 .DataType ;
7+ import ucar .ma2 .Index ;
68
79import java .nio .ByteBuffer ;
810import java .nio .ByteOrder ;
@@ -11,12 +13,25 @@ public abstract class BytesCodec extends ArrayBytesCodec {
1113 protected abstract ByteOrder getByteOrder ();
1214
1315 @ Override
14- public Array decode (ByteBuffer chunkBytes ) {
15- chunkBytes .order (getByteOrder ());
16- return Array .factory (arrayMetadata .dataType .getMA2DataType (), arrayMetadata .chunkShape ,
17- chunkBytes );
16+ public Array decode (ByteBuffer chunkBytes ) {
17+ chunkBytes .order (getByteOrder ());
18+ DataType dtype = arrayMetadata .dataType .getMA2DataType ();
19+ int [] shape = arrayMetadata .chunkShape ;
20+
21+ // Array.factory does not support boolean arrays directly from ByteBuffer
22+ if (dtype == DataType .BOOLEAN ) {
23+ int size = chunkBytes .remaining ();
24+ boolean [] bools = new boolean [size ];
25+ for (int i = 0 ; i < size ; i ++) {
26+ bools [i ] = chunkBytes .get (i ) != 0 ;
27+ }
28+
29+ Index index = Index .factory (shape );
30+ return Array .factory (DataType .BOOLEAN , index , bools );
1831 }
1932
33+ return Array .factory (dtype , shape , chunkBytes );
34+ }
2035 @ Override
2136 public ByteBuffer encode (Array chunkArray ) {
2237 return chunkArray .getDataAsByteBuffer (getByteOrder ());
0 commit comments