1- import typing
2-
31from hazelcast .serialization .api import *
42from hazelcast .serialization .bits import *
53
@@ -157,28 +155,28 @@ def write_byte_array(self, val):
157155 self ._pos += _len
158156
159157 def write_signed_byte_array (self , val : typing .List [int ]) -> None :
160- self ._write_array_fnc (val , self . write_signed_byte )
158+ self ._bulk_write (val , BYTE_SIZE_IN_BYTES , "b" )
161159
162160 def write_boolean_array (self , val ):
163- self ._write_array_fnc (val , self . write_boolean )
161+ self ._bulk_write (val , BOOLEAN_SIZE_IN_BYTES , "?" )
164162
165163 def write_char_array (self , val ):
166164 self ._write_array_fnc (val , self .write_char )
167165
168166 def write_int_array (self , val ):
169- self ._write_array_fnc (val , self . write_int )
167+ self ._bulk_write (val , INT_SIZE_IN_BYTES , "i" )
170168
171169 def write_long_array (self , val ):
172- self ._write_array_fnc (val , self . write_long )
170+ self ._bulk_write (val , LONG_SIZE_IN_BYTES , "q" )
173171
174172 def write_double_array (self , val ):
175- self ._write_array_fnc (val , self . write_double )
173+ self ._bulk_write (val , DOUBLE_SIZE_IN_BYTES , "d" )
176174
177175 def write_float_array (self , val ):
178- self ._write_array_fnc (val , self . write_float )
176+ self ._bulk_write (val , FLOAT_SIZE_IN_BYTES , "f" )
179177
180178 def write_short_array (self , val ):
181- self ._write_array_fnc (val , self . write_short )
179+ self ._bulk_write (val , SHORT_SIZE_IN_BYTES , "h" )
182180
183181 def write_string_array (self , val ):
184182 self ._write_array_fnc (val , self .write_string )
@@ -204,16 +202,26 @@ def set_position(self, position):
204202 self ._pos = position
205203
206204 def write_zero_bytes (self , count ):
207- for _ in range (0 , count ):
208- self ._write (0 )
205+ self ._ensure_available (count )
206+ self ._buffer [self ._pos : self ._pos + count ] = bytes (count )
207+ self ._pos += count
209208
210209 def write_utf (self , val ):
211210 self .write_string (val )
212211
213212 def write_utf_array (self , val ):
214213 self .write_string_array (val )
215214
216- # HELPERS
215+ def _bulk_write (self , val , item_size , fmt_char ):
216+ length = len (val ) if val is not None else NULL_ARRAY_LENGTH
217+ self .write_int (length )
218+ if length > 0 :
219+ nbytes = length * item_size
220+ self ._ensure_available (nbytes )
221+ endian = ">" if self ._is_big_endian else "<"
222+ struct .pack_into (f"{ endian } { length } { fmt_char } " , self ._buffer , self ._pos , * val )
223+ self ._pos += nbytes
224+
217225 def _write_array_fnc (self , val , item_write_fnc ):
218226 _len = len (val ) if val is not None else NULL_ARRAY_LENGTH
219227 self .write_int (_len )
0 commit comments