Remove @/folly dependency from folly/io:compression
authorMichael Lee <mzlee@fb.com>
Thu, 19 Feb 2015 18:44:16 +0000 (10:44 -0800)
committerAlecs King <int@fb.com>
Tue, 3 Mar 2015 03:23:51 +0000 (19:23 -0800)
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
folly/io/Compression.cpp

index 5642f691ccda33a0c8460e2a1ea0920a5d53d081..438cd1b5c3e228c75c06b6aed98d54cf7a6c4491 100644 (file)
@@ -18,6 +18,7 @@
 #define FOLLY_VARINT_H_
 
 #include <type_traits>
 #define FOLLY_VARINT_H_
 
 #include <type_traits>
+#include <folly/Conv.h>
 #include <folly/Range.h>
 
 namespace folly {
 #include <folly/Range.h>
 
 namespace folly {
@@ -126,7 +127,8 @@ inline uint64_t decodeVarint(Range<T*>& data) {
     }
     if (p == end) {
       throw std::invalid_argument("Invalid varint value. Too small: " +
     }
     if (p == end) {
       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;
   }
index ef8ed9ef4267d85cf5bebd5282d494c69bf60cf7..ab0ee5a0719bff6e5aea2bb393be22f2978305e6 100644 (file)
@@ -915,55 +915,55 @@ 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
-  NoCompressionCodec::create,
+    nullptr,  // USER_DEFINED
+    NoCompressionCodec::create,
 
 #if FOLLY_HAVE_LIBLZ4
 
 #if FOLLY_HAVE_LIBLZ4
-  LZ4Codec::create,
+    LZ4Codec::create,
 #else
 #else
-  nullptr,
+    nullptr,
 #endif
 
 #if FOLLY_HAVE_LIBSNAPPY
 #endif
 
 #if FOLLY_HAVE_LIBSNAPPY
-  SnappyCodec::create,
+    SnappyCodec::create,
 #else
 #else
-  nullptr,
+    nullptr,
 #endif
 
 #if FOLLY_HAVE_LIBZ
 #endif
 
 #if FOLLY_HAVE_LIBZ
-  ZlibCodec::create,
+    ZlibCodec::create,
 #else
 #else
-  nullptr,
+    nullptr,
 #endif
 
 #if FOLLY_HAVE_LIBLZ4
 #endif
 
 #if FOLLY_HAVE_LIBLZ4
-  LZ4Codec::create,
+    LZ4Codec::create,
 #else
 #else
-  nullptr,
+    nullptr,
 #endif
 
 #if FOLLY_HAVE_LIBLZMA
 #endif
 
 #if FOLLY_HAVE_LIBLZMA
-  LZMA2Codec::create,
-  LZMA2Codec::create,
+    LZMA2Codec::create,
+    LZMA2Codec::create,
 #else
 #else
-  nullptr,
-  nullptr,
+    nullptr,
+    nullptr,
 #endif
 #endif
-};
-
-}  // namespace
+  };
 
 
-std::unique_ptr<Codec> getCodec(CodecType type, int level) {
   size_t idx = static_cast<size_t>(type);
   if (idx >= static_cast<size_t>(CodecType::NUM_CODEC_TYPES)) {
     throw std::invalid_argument(to<std::string>(
         "Compression type ", idx, " not supported"));
   }
   size_t idx = static_cast<size_t>(type);
   if (idx >= static_cast<size_t>(CodecType::NUM_CODEC_TYPES)) {
     throw std::invalid_argument(to<std::string>(
         "Compression type ", idx, " not supported"));
   }
-  auto factory = gCodecFactories[idx];
+  auto factory = codecFactories[idx];
   if (!factory) {
     throw std::invalid_argument(to<std::string>(
         "Compression type ", idx, " not supported"));
   if (!factory) {
     throw std::invalid_argument(to<std::string>(
         "Compression type ", idx, " not supported"));