Skip to content

Adding Snappy to API server flow#171

Merged
avalerio-tkd merged 4 commits into
mainfrom
av_snappy_09
Dec 1, 2025
Merged

Adding Snappy to API server flow#171
avalerio-tkd merged 4 commits into
mainfrom
av_snappy_09

Conversation

@avalerio-tkd

Copy link
Copy Markdown
Collaborator
  • Added Snappy compression/decompression support
  • Added tests for compression/decompression library

- Added tests for compression/decompression library

@argmarco-tkd argmarco-tkd left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this. Overall LGTM. Left a few comments.

throw DBPSUnsupportedException(
"Unsupported compression codec: " + std::string(to_string(compression)));
}
std::vector<uint8_t> Compress(const std::vector<uint8_t>& bytes, CompressionCodec::type compression);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no namespace? (I'm OK either way.)

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. Added a namespace, thanks for the suggestion.

if (bytes.empty()) {
return bytes;
}
std::string decompressed;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wait, string? why is this? It seems odd - specially given that just below (before returning) we're convering it to a byte array.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah! This is because string has native support for resizing so Snappy uses it while compressing/decompressing. Otherwise it would need to calculate a sized buffer beforehand. So used for simplicity.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

got it, makes sense - string being used as an auto-resize buffer. let's add a quick note to the code. Have we checked is there risk for side effects for using strings? (e.g. UTF-8 encoding doing something 'magic' but undesired with the bytes ?) If this is not an issue, using string makes sense.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added an inline comment for this. Also added (then removed) a unittest to Compress/Decompress special utf-8 chars. It feels still wrong to merge code with special chars, so won't merge that specific test, but it works.

TEST(CompressionUtils, CompressDecompress_Snappy_RoundTrip) {
std::vector<uint8_t> original = {0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08};
std::vector<uint8_t> compressed = Compress(original, CompressionCodec::SNAPPY);
std::vector<uint8_t> decompressed = Decompress(compressed, CompressionCodec::SNAPPY);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this test should also validate than compressed != original (at least). Else, if the impl of 'snappy' was switched with the one from Uncompressed, the test would succeed.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. Added the verification.

TEST(CompressionUtils, CompressDecompress_Snappy_SingleByte) {
std::vector<uint8_t> original = {0x42};
std::vector<uint8_t> compressed = Compress(original, CompressionCodec::SNAPPY);
std::vector<uint8_t> decompressed = Decompress(compressed, CompressionCodec::SNAPPY);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

similar to above. let's at least verify that 'original' was transformed (and that 'original' != 'compressed')

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

Comment thread CMakeLists.txt
set(BUILD_TESTING ON CACHE BOOL "" FORCE)

# Disable Snappy tests to avoid conflicts with our GoogleTest
# Snappy includes its own GoogleTest which conflicts with our FetchContent GoogleTest

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this seems familiar :)

Comment thread CMakeLists.txt
# Suppress warnings from Snappy's source code
if(TARGET snappy)
target_compile_options(snappy PRIVATE
-Wno-sign-compare

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do we need this?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are a bunch of compilation warnings that make the compilation output too noisy, so added this to suppress the warnings.

Comment thread CMakeLists.txt
target_include_directories(decoding_utils_test PRIVATE src/server)

# Compression utils tests
add_executable(compression_utils_test src/server/compression_utils_test.cpp)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we need this now that we have GTEST?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the same as the other test make targets, no? Following the same pattern.

@avalerio-tkd avalerio-tkd left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the review @argmarco-tkd . Could you PTAL?

@argmarco-tkd argmarco-tkd left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall LGTM. Left an additional question on the usage of string as a buffer. I don't need a new PR if addressed.

@avalerio-tkd

Copy link
Copy Markdown
Collaborator Author

Overall LGTM. Left an additional question on the usage of string as a buffer. I don't need a new PR if addressed.

Thanks for the pickiness. Comment addressed. Merging.

@avalerio-tkd
avalerio-tkd merged commit 182f4bd into main Dec 1, 2025
2 checks passed
@avalerio-tkd
avalerio-tkd deleted the av_snappy_09 branch December 1, 2025 04:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants