diff --git a/src/serialization/SerializerBinary.cpp b/src/serialization/SerializerBinary.cpp index 5162a50..a01181d 100644 --- a/src/serialization/SerializerBinary.cpp +++ b/src/serialization/SerializerBinary.cpp @@ -44,12 +44,13 @@ namespace serialization const auto size_bytes = (end_pos - start_pos).as_bytes(); // Make a copy of the uncompressed data - auto *uncompressed = new uint8_t[size_bytes]{0}; + auto *uncompressed = new uint8_t[size_bytes] {0}; + stream.seek(start_pos); stream.read_copy(uncompressed, size_bits); // Setup compression static const std::size_t bufsize = 1024; - auto *temp_buffer = new uint8_t[bufsize]{0}; + uint8_t temp_buffer[bufsize] {0}; std::vector compressed; z_stream z; z.zalloc = nullptr; @@ -96,7 +97,6 @@ namespace serialization // Cleanup temporary buffers delete[] uncompressed; - delete[] temp_buffer; // Write the compression header const auto use_compression = compressed.size() < size_bytes; @@ -264,7 +264,7 @@ namespace serialization { // Create a buffer for the compressed data and read it in BitBuffer compressed(data_available_bytes); - segment_stream.read_copy(compressed.data(), data_available_bytes); + segment_stream.read_copy(compressed.data(), data_available_bytes * 8); // Uncompress the compressed buffer auto *uncompressed = new BitBuffer(uncompressed_size); diff --git a/test/samples/serialization_binary_file_compressed.bin b/test/samples/serialization_binary_file_compressed.bin new file mode 100644 index 0000000..2280edc Binary files /dev/null and b/test/samples/serialization_binary_file_compressed.bin differ diff --git a/test/samples/serialization_binary_regular_compressed.bin b/test/samples/serialization_binary_regular_compressed.bin new file mode 100644 index 0000000..b2d8ba9 Binary files /dev/null and b/test/samples/serialization_binary_regular_compressed.bin differ diff --git a/test/src/unit-serialization.cpp b/test/src/unit-serialization.cpp index 24c4995..738a409 100644 --- a/test/src/unit-serialization.cpp +++ b/test/src/unit-serialization.cpp @@ -488,8 +488,6 @@ TEST_CASE("Serialization tests", "[serialization]") ); test_serializer(test_object, serializer, "_file"); } - /* - TODO: Test compression SECTION("Regular format with compression") { serialization::SerializerBinary serializer( @@ -507,7 +505,6 @@ TEST_CASE("Serialization tests", "[serialization]") ); test_serializer(test_object, serializer, "_file_compressed"); } - */ } // If one of the above sections leaves test_object set, then