### Uncompress Data in C++ Source: https://github.com/google/snappy/blob/main/README.md Basic C++ example demonstrating how to uncompress data using Snappy. Input and output are expected to be std::string objects. ```c++ snappy::Uncompress(input.data(), input.size(), &output); ``` -------------------------------- ### Compress Data in C++ Source: https://github.com/google/snappy/blob/main/README.md Basic C++ example demonstrating how to compress data using Snappy. Input and output are expected to be std::string objects. ```c++ snappy::Compress(input.data(), input.size(), &output); ``` -------------------------------- ### Configure Snappy Test Support Library Source: https://github.com/google/snappy/blob/main/CMakeLists.txt Sets up a library for test support, including test-specific sources and linking against the main Snappy library and optional compression libraries. ```cmake if(SNAPPY_BUILD_TESTS OR SNAPPY_BUILD_BENCHMARKS) add_library(snappy_test_support "") target_sources(snappy_test_support PRIVATE "snappy-test.cc" "snappy-test.h" "snappy_test_data.cc" "snappy_test_data.h" "${PROJECT_BINARY_DIR}/config.h" ) # Test files include snappy-test.h, HAVE_CONFIG_H must be defined. target_compile_definitions(snappy_test_support PUBLIC -DHAVE_CONFIG_H) if(BUILD_SHARED_LIBS) set_target_properties(snappy_test_support PROPERTIES WINDOWS_EXPORT_ALL_SYMBOLS ON) endif(BUILD_SHARED_LIBS) target_link_libraries(snappy_test_support snappy) if(HAVE_LIBZ) target_link_libraries(snappy_test_support z) endif(HAVE_LIBZ) if(HAVE_LIBLZO2) target_link_libraries(snappy_test_support lzo2) endif(HAVE_LIBLZO2) if(HAVE_LIBLZ4) target_link_libraries(snappy_test_support lz4) endif(HAVE_LIBLZ4) target_include_directories(snappy_test_support BEFORE PUBLIC "${PROJECT_SOURCE_DIR}" ) endif(SNAPPY_BUILD_TESTS OR SNAPPY_BUILD_BENCHMARKS) ``` -------------------------------- ### Build Snappy Library Source: https://github.com/google/snappy/blob/main/README.md Instructions to clone the repository, update submodules, create a build directory, and compile the Snappy library using CMake. ```bash git submodule update --init mkdir build cd build && cmake ../ && make ``` -------------------------------- ### Configure Snappy Benchmark Executable Source: https://github.com/google/snappy/blob/main/CMakeLists.txt Builds the Snappy benchmark executable using Google Benchmark. Links against the test support library and benchmark main. Includes the Google Benchmark subdirectory. ```cmake if(SNAPPY_BUILD_BENCHMARKS) add_executable(snappy_benchmark "") target_sources(snappy_benchmark PRIVATE "snappy_benchmark.cc" ) target_link_libraries(snappy_benchmark snappy_test_support benchmark_main) # This project uses Google benchmark for benchmarking. set(BENCHMARK_ENABLE_TESTING OFF CACHE BOOL "" FORCE) set(BENCHMARK_ENABLE_EXCEPTIONS OFF CACHE BOOL "" FORCE) add_subdirectory("third_party/benchmark") endif(SNAPPY_BUILD_BENCHMARKS) ``` -------------------------------- ### Benchmark Snappy Against Other Libraries Source: https://github.com/google/snappy/blob/main/README.md Command-line usage for the `snappy_test_tool` to benchmark Snappy against other compression libraries like zlib. Requires specifying the library to test against and one or more input files. ```bash snappy_test_tool --zlib file1.txt file2.txt ``` -------------------------------- ### Configure Snappy Unit Tests Source: https://github.com/google/snappy/blob/main/CMakeLists.txt Builds the Snappy unit test executable using GoogleTest. Links against the test support library and Google Mock/Google Test. Sets up CMake test definitions. ```cmake if(SNAPPY_BUILD_TESTS) enable_testing() # Prevent overriding the parent project's compiler/linker settings on Windows. set(gtest_force_shared_crt ON CACHE BOOL "" FORCE) set(install_gtest OFF) set(install_gmock OFF) set(build_gmock ON) # This project is tested using GoogleTest. add_subdirectory("third_party/googletest") # GoogleTest triggers a missing field initializers warning. if(SNAPPY_HAVE_NO_MISSING_FIELD_INITIALIZERS) set_property(TARGET gtest APPEND PROPERTY COMPILE_OPTIONS -Wno-missing-field-initializers) set_property(TARGET gmock APPEND PROPERTY COMPILE_OPTIONS -Wno-missing-field-initializers) endif(SNAPPY_HAVE_NO_MISSING_FIELD_INITIALIZERS) if(SNAPPY_HAVE_NO_IMPLICIT_INT_FLOAT_CONVERSION) set_property(TARGET gtest APPEND PROPERTY COMPILE_OPTIONS -Wno-implicit-int-float-conversion) endif(SNAPPY_HAVE_NO_IMPLICIT_INT_FLOAT_CONVERSION) add_executable(snappy_unittest "") target_sources(snappy_unittest PRIVATE "snappy_unittest.cc" ) target_link_libraries(snappy_unittest snappy_test_support gmock_main gtest add_test( NAME snappy_unittest WORKING_DIRECTORY "${PROJECT_SOURCE_DIR}" COMMAND "${PROJECT_BINARY_DIR}/snappy_unittest") add_executable(snappy_test_tool "") target_sources(snappy_test_tool PRIVATE "snappy_test_tool.cc" ) target_link_libraries(snappy_test_tool snappy_test_support) endif(SNAPPY_BUILD_TESTS) ```