Created
December 8, 2018 06:35
-
-
Save fuzz-ai/a4a2c06116a90a3d793df87701dc5f8c to your computer and use it in GitHub Desktop.
snappy compression round-trip test harness
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <snappy.h> | |
| #include <iostream> | |
| #include <string> | |
| #include <cstring> | |
| #include <stdlib.h> | |
| const size_t maxInputSize = 10 * 1024 * 1024; | |
| char inputBuf[maxInputSize]; | |
| int main( int argc, char *argv[] ) { | |
| std::cin.read( inputBuf, maxInputSize ); | |
| size_t inputLength = std::cin.gcount(); | |
| std::string compressed; | |
| snappy::Compress( inputBuf, inputLength, &compressed ); | |
| std::string uncompressed; | |
| snappy::Uncompress( compressed.data(), compressed.size(), | |
| &uncompressed ); | |
| if ( uncompressed.size() != inputLength ) { | |
| std::cout << "Size mismatch."; | |
| abort(); | |
| } | |
| if ( memcmp( uncompressed.data(), inputBuf, inputLength ) != 0 ) { | |
| std::cout << "Content mismatch."; | |
| abort(); | |
| } | |
| return 0; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment