@@ -21,13 +21,13 @@ namespace sparrow_ipc
2121{
2222 // TODO split serialize/deserialize fcts in two different files or just rename the current one?
2323 template <typename T>
24- std::vector<uint8_t > serialize_primitive_array (const sparrow::primitive_array<T>& arr);
24+ std::vector<uint8_t > serialize_primitive_array (sparrow::primitive_array<T>& arr);
2525
2626 template <typename T>
2727 sparrow::primitive_array<T> deserialize_primitive_array (const std::vector<uint8_t >& buffer);
2828
2929 template <typename T>
30- std::vector<uint8_t > serialize_primitive_array (const sparrow::primitive_array<T>& arr)
30+ std::vector<uint8_t > serialize_primitive_array (sparrow::primitive_array<T>& arr)
3131 {
3232 // This function serializes a sparrow::primitive_array into a byte vector that is compliant
3333 // with the Apache Arrow IPC Streaming Format. It constructs a stream containing two messages:
@@ -40,9 +40,10 @@ namespace sparrow_ipc
4040 // - 8-byte padding and alignment for the message body.
4141 // - Correctly populating the Flatbuffer-defined metadata for both messages.
4242
43- // Create a mutable copy of the input array to allow moving its internal structures
44- sparrow::primitive_array<T> mutable_arr = arr;
45- auto [arrow_arr, arrow_schema] = sparrow::extract_arrow_structures (std::move (mutable_arr));
43+ // Get arrow structures
44+ auto [arrow_arr_ptr, arrow_schema_ptr] = sparrow::get_arrow_structures (arr);
45+ auto & arrow_arr = *arrow_arr_ptr;
46+ auto & arrow_schema = *arrow_schema_ptr;
4647
4748 // This will be the final buffer holding the complete IPC stream.
4849 std::vector<uint8_t > final_buffer;
@@ -194,10 +195,6 @@ namespace sparrow_ipc
194195 }
195196 }
196197
197- // Release the memory managed by the C structures
198- arrow_arr.release (&arrow_arr);
199- arrow_schema.release (&arrow_schema);
200-
201198 // Return the final buffer containing the complete IPC stream
202199 return final_buffer;
203200 }
@@ -278,4 +275,4 @@ namespace sparrow_ipc
278275
279276 return sparrow::primitive_array<T>(std::move (data), node_meta->length (), std::move (bitmap), name, metadata);
280277 }
281- }
278+ }
0 commit comments