Commit 37dd79a6 authored by Michael Lee's avatar Michael Lee Committed by Alecs King

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
parent 59e4f0d0
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
#define FOLLY_VARINT_H_ #define FOLLY_VARINT_H_
#include <type_traits> #include <type_traits>
#include <folly/Conv.h>
#include <folly/Range.h> #include <folly/Range.h>
namespace folly { namespace folly {
...@@ -126,7 +127,8 @@ inline uint64_t decodeVarint(Range<T*>& data) { ...@@ -126,7 +127,8 @@ inline uint64_t decodeVarint(Range<T*>& data) {
} }
if (p == end) { if (p == end) {
throw std::invalid_argument("Invalid varint value. Too small: " + throw std::invalid_argument("Invalid varint value. Too small: " +
std::to_string(end - begin) + " bytes"); folly::to<std::string>(end - begin) +
" bytes");
} }
val |= static_cast<uint64_t>(*p++) << shift; val |= static_cast<uint64_t>(*p++) << shift;
} }
......
...@@ -915,9 +915,12 @@ std::unique_ptr<IOBuf> LZMA2Codec::doUncompress(const IOBuf* data, ...@@ -915,9 +915,12 @@ std::unique_ptr<IOBuf> LZMA2Codec::doUncompress(const IOBuf* data,
#endif // FOLLY_HAVE_LIBLZMA #endif // FOLLY_HAVE_LIBLZMA
typedef std::unique_ptr<Codec> (*CodecFactory)(int, CodecType); } // namespace
std::unique_ptr<Codec> getCodec(CodecType type, int level) {
typedef std::unique_ptr<Codec> (*CodecFactory)(int, CodecType);
CodecFactory gCodecFactories[ static CodecFactory codecFactories[
static_cast<size_t>(CodecType::NUM_CODEC_TYPES)] = { static_cast<size_t>(CodecType::NUM_CODEC_TYPES)] = {
nullptr, // USER_DEFINED nullptr, // USER_DEFINED
NoCompressionCodec::create, NoCompressionCodec::create,
...@@ -953,17 +956,14 @@ CodecFactory gCodecFactories[ ...@@ -953,17 +956,14 @@ CodecFactory gCodecFactories[
nullptr, nullptr,
nullptr, nullptr,
#endif #endif
}; };
} // namespace
std::unique_ptr<Codec> getCodec(CodecType type, int level) {
size_t idx = static_cast<size_t>(type); size_t idx = static_cast<size_t>(type);
if (idx >= static_cast<size_t>(CodecType::NUM_CODEC_TYPES)) { if (idx >= static_cast<size_t>(CodecType::NUM_CODEC_TYPES)) {
throw std::invalid_argument(to<std::string>( throw std::invalid_argument(to<std::string>(
"Compression type ", idx, " not supported")); "Compression type ", idx, " not supported"));
} }
auto factory = gCodecFactories[idx]; auto factory = codecFactories[idx];
if (!factory) { if (!factory) {
throw std::invalid_argument(to<std::string>( throw std::invalid_argument(to<std::string>(
"Compression type ", idx, " not supported")); "Compression type ", idx, " not supported"));
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment