1616from typing import Any , NamedTuple
1717
1818import numpy as np
19- from msgpack import packb , unpackb
2019
2120import blosc2
2221from blosc2 import SpecialValue , blosc2_ext
22+ from blosc2 ._msgpack_utils import msgpack_packb , msgpack_unpackb
2323from blosc2 .info import InfoReporter
2424
2525
@@ -46,12 +46,7 @@ def __setitem__(self, name, content):
4646 return
4747 raise NotImplementedError ("Slicing is not supported, unless [:]" )
4848 cparams = {"typesize" : 1 }
49- content = packb (
50- content ,
51- default = blosc2_ext .encode_tuple ,
52- strict_types = True ,
53- use_bin_type = True ,
54- )
49+ content = msgpack_packb (content )
5550 super ().set_vlmeta (name , content , ** cparams )
5651
5752 def __getitem__ (self , name ):
@@ -60,7 +55,7 @@ def __getitem__(self, name):
6055 # Return all the vlmetalayers
6156 return self .getall ()
6257 raise NotImplementedError ("Slicing is not supported, unless [:]" )
63- return unpackb (super ().get_vlmeta (name ), list_hook = blosc2_ext . decode_tuple )
58+ return msgpack_unpackb (super ().get_vlmeta (name ))
6459
6560 def __delitem__ (self , name ):
6661 blosc2_ext .check_access_mode (self .urlpath , self .mode )
@@ -120,7 +115,7 @@ def __setitem__(self, key: str, value: bytes) -> None:
120115 ..warning: Note that the *length* of the metalayer cannot change,
121116 otherwise an exception will be raised.
122117 """
123- value = packb (value , default = blosc2_ext . encode_tuple , strict_types = True , use_bin_type = True )
118+ value = msgpack_packb (value )
124119 blosc2_ext .meta__setitem__ (self .schunk , key , value )
125120
126121 def __getitem__ (self , item : str | slice ) -> bytes | dict [str , bytes ]:
@@ -144,10 +139,7 @@ def __getitem__(self, item: str | slice) -> bytes | dict[str, bytes]:
144139 return self .getall ()
145140 raise NotImplementedError ("Slicing is not supported, unless [:]" )
146141 if self .__contains__ (item ):
147- return unpackb (
148- blosc2_ext .meta__getitem__ (self .schunk , item ),
149- list_hook = blosc2_ext .decode_tuple ,
150- )
142+ return msgpack_unpackb (blosc2_ext .meta__getitem__ (self .schunk , item ))
151143 else :
152144 raise KeyError (f"{ item } not found" )
153145
0 commit comments