def _SerializeNativeArray(value, data_offset, data, length): data_size = len(data) data.extend(bytearray(serialization.HEADER_STRUCT.size)) data.extend(buffer(value)) data_length = len(data) - data_size data.extend(bytearray(serialization.NeededPaddingForAlignment(data_length))) serialization.HEADER_STRUCT.pack_into(data, data_size, data_length, length) return (data_offset, [])
def SerializeArray(self, value, data_offset, data, handle_offset): size = (serialization.HEADER_STRUCT.size + self.sub_type.GetByteSize() * len(value)) data_end = len(data) position = len(data) + serialization.HEADER_STRUCT.size data.extend( bytearray(size + serialization.NeededPaddingForAlignment(size))) returned_handles = [] to_pack = [] for item in value: (new_data, new_handles) = self.sub_type.Serialize( item, len(data) - position, data, handle_offset + len(returned_handles)) to_pack.extend(serialization.Flatten(new_data)) returned_handles.extend(new_handles) position = position + self.sub_type.GetByteSize() serialization.HEADER_STRUCT.pack_into(data, data_end, size, len(value)) struct.pack_into('%d%s' % (len(value), self.sub_type.GetTypeCode()), data, data_end + serialization.HEADER_STRUCT.size, *to_pack) return (data_offset, returned_handles)