From 37dd79a6f610efbb8932b2d2ed52339ed4fe7baf Mon Sep 17 00:00:00 2001 From: Michael Lee Date: Thu, 19 Feb 2015 10:44:16 -0800 Subject: [PATCH] Remove @/folly dependency from folly/io:compression Summary: This diff should let us include folly/io:compression into iOS and Android projects without pulling in a lot of dependencies and should allow the use of zlib. Test Plan: fbconfig -r folly/io/tests && fbmake runtests Reviewed By: seanc@fb.com Subscribers: trunkagent, bmatheny, folly-diffs@, yfeldblum, seanc, benyluo FB internal diff: D1853058 Tasks: 6245912 Signature: t1:1853058:1424370881:2ea243d93e6041502e5e356fa430c2483f652b40 --- folly/Varint.h | 4 +++- folly/io/Compression.cpp | 42 ++++++++++++++++++++-------------------- 2 files changed, 24 insertions(+), 22 deletions(-) diff --git a/folly/Varint.h b/folly/Varint.h index 5642f691..438cd1b5 100644 --- a/folly/Varint.h +++ b/folly/Varint.h @@ -18,6 +18,7 @@ #define FOLLY_VARINT_H_ #include +#include #include namespace folly { @@ -126,7 +127,8 @@ inline uint64_t decodeVarint(Range& data) { } if (p == end) { throw std::invalid_argument("Invalid varint value. Too small: " + - std::to_string(end - begin) + " bytes"); + folly::to(end - begin) + + " bytes"); } val |= static_cast(*p++) << shift; } diff --git a/folly/io/Compression.cpp b/folly/io/Compression.cpp index ef8ed9ef..ab0ee5a0 100644 --- a/folly/io/Compression.cpp +++ b/folly/io/Compression.cpp @@ -915,55 +915,55 @@ std::unique_ptr LZMA2Codec::doUncompress(const IOBuf* data, #endif // FOLLY_HAVE_LIBLZMA -typedef std::unique_ptr (*CodecFactory)(int, CodecType); +} // namespace + +std::unique_ptr getCodec(CodecType type, int level) { + typedef std::unique_ptr (*CodecFactory)(int, CodecType); -CodecFactory gCodecFactories[ + static CodecFactory codecFactories[ static_cast(CodecType::NUM_CODEC_TYPES)] = { - nullptr, // USER_DEFINED - NoCompressionCodec::create, + nullptr, // USER_DEFINED + NoCompressionCodec::create, #if FOLLY_HAVE_LIBLZ4 - LZ4Codec::create, + LZ4Codec::create, #else - nullptr, + nullptr, #endif #if FOLLY_HAVE_LIBSNAPPY - SnappyCodec::create, + SnappyCodec::create, #else - nullptr, + nullptr, #endif #if FOLLY_HAVE_LIBZ - ZlibCodec::create, + ZlibCodec::create, #else - nullptr, + nullptr, #endif #if FOLLY_HAVE_LIBLZ4 - LZ4Codec::create, + LZ4Codec::create, #else - nullptr, + nullptr, #endif #if FOLLY_HAVE_LIBLZMA - LZMA2Codec::create, - LZMA2Codec::create, + LZMA2Codec::create, + LZMA2Codec::create, #else - nullptr, - nullptr, + nullptr, + nullptr, #endif -}; - -} // namespace + }; -std::unique_ptr getCodec(CodecType type, int level) { size_t idx = static_cast(type); if (idx >= static_cast(CodecType::NUM_CODEC_TYPES)) { throw std::invalid_argument(to( "Compression type ", idx, " not supported")); } - auto factory = gCodecFactories[idx]; + auto factory = codecFactories[idx]; if (!factory) { throw std::invalid_argument(to( "Compression type ", idx, " not supported")); -- 2.34.1