libcouchbase 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +18 -0
- data/.gitmodules +3 -0
- data/.rspec +1 -0
- data/.travis.yml +35 -0
- data/Gemfile +4 -0
- data/LICENSE +24 -0
- data/README.md +389 -0
- data/Rakefile +75 -0
- data/ext/README.md +6 -0
- data/ext/Rakefile +20 -0
- data/ext/libcouchbase/.gitignore +130 -0
- data/ext/libcouchbase/.travis.yml +19 -0
- data/ext/libcouchbase/CMakeLists.txt +429 -0
- data/ext/libcouchbase/CONTRIBUTING.md +124 -0
- data/ext/libcouchbase/LICENSE +202 -0
- data/ext/libcouchbase/README.markdown +163 -0
- data/ext/libcouchbase/RELEASE_NOTES.markdown +2691 -0
- data/ext/libcouchbase/cmake/Modules/ConfigureDtrace.cmake +27 -0
- data/ext/libcouchbase/cmake/Modules/CopyPDB.cmake +42 -0
- data/ext/libcouchbase/cmake/Modules/DistScript.cmake +17 -0
- data/ext/libcouchbase/cmake/Modules/DownloadLcbDep.cmake +20 -0
- data/ext/libcouchbase/cmake/Modules/FindCouchbaseHdrHistogram.cmake +15 -0
- data/ext/libcouchbase/cmake/Modules/FindCouchbaseLibev.cmake +73 -0
- data/ext/libcouchbase/cmake/Modules/FindCouchbaseLibevent.cmake +52 -0
- data/ext/libcouchbase/cmake/Modules/FindCouchbaseLibuv.cmake +56 -0
- data/ext/libcouchbase/cmake/Modules/FindCouchbaseSnappy.cmake +11 -0
- data/ext/libcouchbase/cmake/Modules/GenerateConfigDotH.cmake +29 -0
- data/ext/libcouchbase/cmake/Modules/GetLibcouchbaseFlags.cmake +133 -0
- data/ext/libcouchbase/cmake/Modules/GetPlatformCCInfo.cmake +45 -0
- data/ext/libcouchbase/cmake/Modules/GetVersionInfo.cmake +70 -0
- data/ext/libcouchbase/cmake/config-cmake.h.in +60 -0
- data/ext/libcouchbase/cmake/configure +357 -0
- data/ext/libcouchbase/cmake/defs.mk.in +8 -0
- data/ext/libcouchbase/cmake/dtrace-instr-link.pl +38 -0
- data/ext/libcouchbase/cmake/source_files.cmake +73 -0
- data/ext/libcouchbase/configure.pl +1 -0
- data/ext/libcouchbase/contrib/cJSON/cJSON.c +624 -0
- data/ext/libcouchbase/contrib/cJSON/cJSON.h +158 -0
- data/ext/libcouchbase/contrib/cbsasl/CMakeLists.txt +9 -0
- data/ext/libcouchbase/contrib/cbsasl/COPYING +202 -0
- data/ext/libcouchbase/contrib/cbsasl/include/cbsasl/cbsasl.h +217 -0
- data/ext/libcouchbase/contrib/cbsasl/src/client.c +205 -0
- data/ext/libcouchbase/contrib/cbsasl/src/common.c +46 -0
- data/ext/libcouchbase/contrib/cbsasl/src/cram-md5/hmac.c +67 -0
- data/ext/libcouchbase/contrib/cbsasl/src/cram-md5/hmac.h +33 -0
- data/ext/libcouchbase/contrib/cbsasl/src/cram-md5/md5.c +296 -0
- data/ext/libcouchbase/contrib/cbsasl/src/cram-md5/md5.h +45 -0
- data/ext/libcouchbase/contrib/cbsasl/src/hash.c +573 -0
- data/ext/libcouchbase/contrib/cbsasl/src/hash.h +15 -0
- data/ext/libcouchbase/contrib/cbsasl/src/util.h +31 -0
- data/ext/libcouchbase/contrib/cliopts/CMakeLists.txt +2 -0
- data/ext/libcouchbase/contrib/cliopts/cliopts.c +747 -0
- data/ext/libcouchbase/contrib/cliopts/cliopts.h +493 -0
- data/ext/libcouchbase/contrib/genhash/genhash.c +372 -0
- data/ext/libcouchbase/contrib/genhash/genhash.h +235 -0
- data/ext/libcouchbase/contrib/gtest-1.7.0/CHANGES +157 -0
- data/ext/libcouchbase/contrib/gtest-1.7.0/CMakeLists.txt +252 -0
- data/ext/libcouchbase/contrib/gtest-1.7.0/CONTRIBUTORS +37 -0
- data/ext/libcouchbase/contrib/gtest-1.7.0/LICENSE +28 -0
- data/ext/libcouchbase/contrib/gtest-1.7.0/MINIFY.sh +15 -0
- data/ext/libcouchbase/contrib/gtest-1.7.0/README +435 -0
- data/ext/libcouchbase/contrib/gtest-1.7.0/cmake/internal_utils.cmake +227 -0
- data/ext/libcouchbase/contrib/gtest-1.7.0/include/gtest/gtest-death-test.h +294 -0
- data/ext/libcouchbase/contrib/gtest-1.7.0/include/gtest/gtest-message.h +250 -0
- data/ext/libcouchbase/contrib/gtest-1.7.0/include/gtest/gtest-param-test.h +1421 -0
- data/ext/libcouchbase/contrib/gtest-1.7.0/include/gtest/gtest-param-test.h.pump +487 -0
- data/ext/libcouchbase/contrib/gtest-1.7.0/include/gtest/gtest-printers.h +855 -0
- data/ext/libcouchbase/contrib/gtest-1.7.0/include/gtest/gtest-spi.h +232 -0
- data/ext/libcouchbase/contrib/gtest-1.7.0/include/gtest/gtest-test-part.h +179 -0
- data/ext/libcouchbase/contrib/gtest-1.7.0/include/gtest/gtest-typed-test.h +259 -0
- data/ext/libcouchbase/contrib/gtest-1.7.0/include/gtest/gtest.h +2291 -0
- data/ext/libcouchbase/contrib/gtest-1.7.0/include/gtest/gtest_pred_impl.h +358 -0
- data/ext/libcouchbase/contrib/gtest-1.7.0/include/gtest/gtest_prod.h +58 -0
- data/ext/libcouchbase/contrib/gtest-1.7.0/include/gtest/internal/gtest-death-test-internal.h +319 -0
- data/ext/libcouchbase/contrib/gtest-1.7.0/include/gtest/internal/gtest-filepath.h +206 -0
- data/ext/libcouchbase/contrib/gtest-1.7.0/include/gtest/internal/gtest-internal.h +1158 -0
- data/ext/libcouchbase/contrib/gtest-1.7.0/include/gtest/internal/gtest-linked_ptr.h +233 -0
- data/ext/libcouchbase/contrib/gtest-1.7.0/include/gtest/internal/gtest-param-util-generated.h +5143 -0
- data/ext/libcouchbase/contrib/gtest-1.7.0/include/gtest/internal/gtest-param-util-generated.h.pump +301 -0
- data/ext/libcouchbase/contrib/gtest-1.7.0/include/gtest/internal/gtest-param-util.h +619 -0
- data/ext/libcouchbase/contrib/gtest-1.7.0/include/gtest/internal/gtest-port.h +1947 -0
- data/ext/libcouchbase/contrib/gtest-1.7.0/include/gtest/internal/gtest-string.h +167 -0
- data/ext/libcouchbase/contrib/gtest-1.7.0/include/gtest/internal/gtest-tuple.h +1012 -0
- data/ext/libcouchbase/contrib/gtest-1.7.0/include/gtest/internal/gtest-tuple.h.pump +339 -0
- data/ext/libcouchbase/contrib/gtest-1.7.0/include/gtest/internal/gtest-type-util.h +3331 -0
- data/ext/libcouchbase/contrib/gtest-1.7.0/include/gtest/internal/gtest-type-util.h.pump +297 -0
- data/ext/libcouchbase/contrib/gtest-1.7.0/src/gtest-all.cc +48 -0
- data/ext/libcouchbase/contrib/gtest-1.7.0/src/gtest-death-test.cc +1344 -0
- data/ext/libcouchbase/contrib/gtest-1.7.0/src/gtest-filepath.cc +382 -0
- data/ext/libcouchbase/contrib/gtest-1.7.0/src/gtest-internal-inl.h +1218 -0
- data/ext/libcouchbase/contrib/gtest-1.7.0/src/gtest-port.cc +805 -0
- data/ext/libcouchbase/contrib/gtest-1.7.0/src/gtest-printers.cc +363 -0
- data/ext/libcouchbase/contrib/gtest-1.7.0/src/gtest-test-part.cc +110 -0
- data/ext/libcouchbase/contrib/gtest-1.7.0/src/gtest-typed-test.cc +110 -0
- data/ext/libcouchbase/contrib/gtest-1.7.0/src/gtest.cc +5015 -0
- data/ext/libcouchbase/contrib/gtest-1.7.0/src/gtest_main.cc +38 -0
- data/ext/libcouchbase/contrib/http_parser/LICENSE-MIT +23 -0
- data/ext/libcouchbase/contrib/http_parser/README.md +178 -0
- data/ext/libcouchbase/contrib/http_parser/http_parser.c +2060 -0
- data/ext/libcouchbase/contrib/http_parser/http_parser.h +321 -0
- data/ext/libcouchbase/contrib/jsonsl/LICENSE +20 -0
- data/ext/libcouchbase/contrib/jsonsl/jsonsl.c +1452 -0
- data/ext/libcouchbase/contrib/jsonsl/jsonsl.h +971 -0
- data/ext/libcouchbase/contrib/lcb-jsoncpp/CMakeLists.txt +6 -0
- data/ext/libcouchbase/contrib/lcb-jsoncpp/LICENSE +55 -0
- data/ext/libcouchbase/contrib/lcb-jsoncpp/lcb-jsoncpp-forwards.h +255 -0
- data/ext/libcouchbase/contrib/lcb-jsoncpp/lcb-jsoncpp.cpp +4892 -0
- data/ext/libcouchbase/contrib/lcb-jsoncpp/lcb-jsoncpp.h +1961 -0
- data/ext/libcouchbase/contrib/snappy/CMakeLists.txt +8 -0
- data/ext/libcouchbase/contrib/snappy/COPYING +28 -0
- data/ext/libcouchbase/contrib/snappy/snappy-c.cc +90 -0
- data/ext/libcouchbase/contrib/snappy/snappy-c.h +138 -0
- data/ext/libcouchbase/contrib/snappy/snappy-internal.h +150 -0
- data/ext/libcouchbase/contrib/snappy/snappy-lcb-msvc.h +5 -0
- data/ext/libcouchbase/contrib/snappy/snappy-sinksource.cc +71 -0
- data/ext/libcouchbase/contrib/snappy/snappy-sinksource.h +137 -0
- data/ext/libcouchbase/contrib/snappy/snappy-stubs-internal.cc +42 -0
- data/ext/libcouchbase/contrib/snappy/snappy-stubs-internal.h +491 -0
- data/ext/libcouchbase/contrib/snappy/snappy-stubs-public.h +98 -0
- data/ext/libcouchbase/contrib/snappy/snappy.cc +1307 -0
- data/ext/libcouchbase/contrib/snappy/snappy.h +184 -0
- data/ext/libcouchbase/contrib/win32-defs/iocpdefs.h +133 -0
- data/ext/libcouchbase/contrib/win32-defs/mingwdefs.h +4396 -0
- data/ext/libcouchbase/contrib/win32-defs/win_stdint.h +258 -0
- data/ext/libcouchbase/example/CMakeLists.txt +37 -0
- data/ext/libcouchbase/example/README.markdown +47 -0
- data/ext/libcouchbase/example/db/db.c +167 -0
- data/ext/libcouchbase/example/db/vb.c +227 -0
- data/ext/libcouchbase/example/instancepool/main.cc +102 -0
- data/ext/libcouchbase/example/instancepool/pool.cc +102 -0
- data/ext/libcouchbase/example/instancepool/pool.h +69 -0
- data/ext/libcouchbase/example/libeventdirect/main.c +148 -0
- data/ext/libcouchbase/example/mcc/mcc.cc +246 -0
- data/ext/libcouchbase/example/minimal/minimal.c +130 -0
- data/ext/libcouchbase/example/observe/observe.c +146 -0
- data/ext/libcouchbase/example/subdoc/subdoc-multi.cc +132 -0
- data/ext/libcouchbase/example/subdoc/subdoc-simple.cc +191 -0
- data/ext/libcouchbase/example/tick/tick.c +119 -0
- data/ext/libcouchbase/example/views/views-example.cc +83 -0
- data/ext/libcouchbase/include/libcouchbase/_cxxwrap.h +150 -0
- data/ext/libcouchbase/include/libcouchbase/api-legacy.h +1689 -0
- data/ext/libcouchbase/include/libcouchbase/api3.h +2 -0
- data/ext/libcouchbase/include/libcouchbase/assert.h +44 -0
- data/ext/libcouchbase/include/libcouchbase/cbft.h +109 -0
- data/ext/libcouchbase/include/libcouchbase/cntl-private.h +356 -0
- data/ext/libcouchbase/include/libcouchbase/cntl.h +937 -0
- data/ext/libcouchbase/include/libcouchbase/configuration.h.in +23 -0
- data/ext/libcouchbase/include/libcouchbase/couchbase.h +3677 -0
- data/ext/libcouchbase/include/libcouchbase/deprecated.h +300 -0
- data/ext/libcouchbase/include/libcouchbase/error.h +595 -0
- data/ext/libcouchbase/include/libcouchbase/http.h +1 -0
- data/ext/libcouchbase/include/libcouchbase/iops.h +1050 -0
- data/ext/libcouchbase/include/libcouchbase/ixmgmt.h +263 -0
- data/ext/libcouchbase/include/libcouchbase/kvbuf.h +132 -0
- data/ext/libcouchbase/include/libcouchbase/n1ql.h +364 -0
- data/ext/libcouchbase/include/libcouchbase/pktfwd.h +270 -0
- data/ext/libcouchbase/include/libcouchbase/plugins/io/bsdio-inl.c +367 -0
- data/ext/libcouchbase/include/libcouchbase/plugins/io/wsaerr-inl.c +76 -0
- data/ext/libcouchbase/include/libcouchbase/plugins/io/wsaerr.h +199 -0
- data/ext/libcouchbase/include/libcouchbase/subdoc.h +312 -0
- data/ext/libcouchbase/include/libcouchbase/sysdefs.h +98 -0
- data/ext/libcouchbase/include/libcouchbase/vbucket.h +643 -0
- data/ext/libcouchbase/include/libcouchbase/views.h +298 -0
- data/ext/libcouchbase/include/libcouchbase/visibility.h +65 -0
- data/ext/libcouchbase/include/memcached/COPYING +30 -0
- data/ext/libcouchbase/include/memcached/README +10 -0
- data/ext/libcouchbase/include/memcached/protocol_binary.h +1916 -0
- data/ext/libcouchbase/include/memcached/vbucket.h +42 -0
- data/ext/libcouchbase/packaging/README +7 -0
- data/ext/libcouchbase/packaging/abicheck/.gitignore +4 -0
- data/ext/libcouchbase/packaging/abicheck/Makefile +17 -0
- data/ext/libcouchbase/packaging/abicheck/README.md +27 -0
- data/ext/libcouchbase/packaging/abicheck/template.xml +3 -0
- data/ext/libcouchbase/packaging/deb/compat +1 -0
- data/ext/libcouchbase/packaging/deb/control +73 -0
- data/ext/libcouchbase/packaging/deb/copyright +10 -0
- data/ext/libcouchbase/packaging/deb/libcouchbase-dev.docs +3 -0
- data/ext/libcouchbase/packaging/deb/package.mk +31 -0
- data/ext/libcouchbase/packaging/deb/rules +46 -0
- data/ext/libcouchbase/packaging/deb/source/format +1 -0
- data/ext/libcouchbase/packaging/distinfo/README +1 -0
- data/ext/libcouchbase/packaging/distinfo/distinfo.cmake.in +4 -0
- data/ext/libcouchbase/packaging/dllversion.rc.in +39 -0
- data/ext/libcouchbase/packaging/libcouchbase.pc.in +10 -0
- data/ext/libcouchbase/packaging/nuget/libcouchbase.autopkg +76 -0
- data/ext/libcouchbase/packaging/parse-git-describe.pl +166 -0
- data/ext/libcouchbase/packaging/rpm/libcouchbase.spec.in +108 -0
- data/ext/libcouchbase/packaging/rpm/package.mk +40 -0
- data/ext/libcouchbase/plugins/io/iocp/CMakeLists.txt +9 -0
- data/ext/libcouchbase/plugins/io/iocp/iocp_iops.c +466 -0
- data/ext/libcouchbase/plugins/io/iocp/iocp_iops.h +217 -0
- data/ext/libcouchbase/plugins/io/iocp/iocp_loop.c +295 -0
- data/ext/libcouchbase/plugins/io/iocp/iocp_timer.c +79 -0
- data/ext/libcouchbase/plugins/io/iocp/iocp_util.c +229 -0
- data/ext/libcouchbase/plugins/io/libev/CMakeLists.txt +29 -0
- data/ext/libcouchbase/plugins/io/libev/libev_io_opts.h +65 -0
- data/ext/libcouchbase/plugins/io/libev/plugin-libev.c +289 -0
- data/ext/libcouchbase/plugins/io/libevent/CMakeLists.txt +29 -0
- data/ext/libcouchbase/plugins/io/libevent/libevent_io_opts.h +67 -0
- data/ext/libcouchbase/plugins/io/libevent/plugin-libevent.c +292 -0
- data/ext/libcouchbase/plugins/io/libuv/CMakeLists.txt +42 -0
- data/ext/libcouchbase/plugins/io/libuv/libuv_compat.h +212 -0
- data/ext/libcouchbase/plugins/io/libuv/libuv_io_opts.h +118 -0
- data/ext/libcouchbase/plugins/io/libuv/plugin-internal.h +148 -0
- data/ext/libcouchbase/plugins/io/libuv/plugin-libuv.c +648 -0
- data/ext/libcouchbase/plugins/io/select/CMakeLists.txt +11 -0
- data/ext/libcouchbase/plugins/io/select/plugin-select.c +448 -0
- data/ext/libcouchbase/plugins/io/select/select_io_opts.h +39 -0
- data/ext/libcouchbase/src/README.md +103 -0
- data/ext/libcouchbase/src/aspend.h +106 -0
- data/ext/libcouchbase/src/auth.cc +74 -0
- data/ext/libcouchbase/src/auth.h +54 -0
- data/ext/libcouchbase/src/bootstrap.c +269 -0
- data/ext/libcouchbase/src/bootstrap.h +129 -0
- data/ext/libcouchbase/src/bucketconfig/bc_cccp.c +495 -0
- data/ext/libcouchbase/src/bucketconfig/bc_file.c +347 -0
- data/ext/libcouchbase/src/bucketconfig/bc_http.c +630 -0
- data/ext/libcouchbase/src/bucketconfig/bc_http.h +82 -0
- data/ext/libcouchbase/src/bucketconfig/bc_mcraw.c +150 -0
- data/ext/libcouchbase/src/bucketconfig/clconfig.h +681 -0
- data/ext/libcouchbase/src/bucketconfig/confmon.c +474 -0
- data/ext/libcouchbase/src/callbacks.c +378 -0
- data/ext/libcouchbase/src/cbft.cc +210 -0
- data/ext/libcouchbase/src/cntl.cc +847 -0
- data/ext/libcouchbase/src/config_static.h +159 -0
- data/ext/libcouchbase/src/connspec.cc +462 -0
- data/ext/libcouchbase/src/connspec.h +105 -0
- data/ext/libcouchbase/src/ctx-log-inl.h +27 -0
- data/ext/libcouchbase/src/dump.c +98 -0
- data/ext/libcouchbase/src/getconfig.c +100 -0
- data/ext/libcouchbase/src/gethrtime.c +109 -0
- data/ext/libcouchbase/src/handler.c +922 -0
- data/ext/libcouchbase/src/hashset.c +164 -0
- data/ext/libcouchbase/src/hashset.h +86 -0
- data/ext/libcouchbase/src/hashtable.c +75 -0
- data/ext/libcouchbase/src/hdr_timings.c +92 -0
- data/ext/libcouchbase/src/hostlist.cc +301 -0
- data/ext/libcouchbase/src/hostlist.h +171 -0
- data/ext/libcouchbase/src/http/http-priv.h +307 -0
- data/ext/libcouchbase/src/http/http.cc +633 -0
- data/ext/libcouchbase/src/http/http.h +34 -0
- data/ext/libcouchbase/src/http/http_io.cc +307 -0
- data/ext/libcouchbase/src/instance.cc +722 -0
- data/ext/libcouchbase/src/internal.h +244 -0
- data/ext/libcouchbase/src/iofactory.c +575 -0
- data/ext/libcouchbase/src/jsparse/parser.cc +519 -0
- data/ext/libcouchbase/src/jsparse/parser.h +173 -0
- data/ext/libcouchbase/src/lcbht/lcbht.c +282 -0
- data/ext/libcouchbase/src/lcbht/lcbht.h +199 -0
- data/ext/libcouchbase/src/lcbio/connect.c +557 -0
- data/ext/libcouchbase/src/lcbio/connect.h +364 -0
- data/ext/libcouchbase/src/lcbio/ctx.c +611 -0
- data/ext/libcouchbase/src/lcbio/ctx.h +405 -0
- data/ext/libcouchbase/src/lcbio/iotable.c +290 -0
- data/ext/libcouchbase/src/lcbio/iotable.h +84 -0
- data/ext/libcouchbase/src/lcbio/ioutils.c +350 -0
- data/ext/libcouchbase/src/lcbio/ioutils.h +203 -0
- data/ext/libcouchbase/src/lcbio/lcbio.h +51 -0
- data/ext/libcouchbase/src/lcbio/manager.c +584 -0
- data/ext/libcouchbase/src/lcbio/manager.h +156 -0
- data/ext/libcouchbase/src/lcbio/protoctx.c +84 -0
- data/ext/libcouchbase/src/lcbio/rw-inl.h +115 -0
- data/ext/libcouchbase/src/lcbio/ssl.h +149 -0
- data/ext/libcouchbase/src/lcbio/timer-ng.h +179 -0
- data/ext/libcouchbase/src/lcbio/timer.c +132 -0
- data/ext/libcouchbase/src/legacy.c +430 -0
- data/ext/libcouchbase/src/list.c +144 -0
- data/ext/libcouchbase/src/list.h +127 -0
- data/ext/libcouchbase/src/logging.c +244 -0
- data/ext/libcouchbase/src/logging.h +86 -0
- data/ext/libcouchbase/src/mc/compress.c +90 -0
- data/ext/libcouchbase/src/mc/compress.h +61 -0
- data/ext/libcouchbase/src/mc/forward.c +186 -0
- data/ext/libcouchbase/src/mc/forward.h +90 -0
- data/ext/libcouchbase/src/mc/iovcursor-inl.h +279 -0
- data/ext/libcouchbase/src/mc/iovcursor.h +66 -0
- data/ext/libcouchbase/src/mc/mcreq-flush-inl.h +111 -0
- data/ext/libcouchbase/src/mc/mcreq.c +954 -0
- data/ext/libcouchbase/src/mc/mcreq.h +977 -0
- data/ext/libcouchbase/src/mcserver/mcserver.c +784 -0
- data/ext/libcouchbase/src/mcserver/mcserver.h +121 -0
- data/ext/libcouchbase/src/mcserver/negotiate.c +656 -0
- data/ext/libcouchbase/src/mcserver/negotiate.h +119 -0
- data/ext/libcouchbase/src/n1ql/ixmgmt.cc +860 -0
- data/ext/libcouchbase/src/n1ql/n1ql-internal.h +22 -0
- data/ext/libcouchbase/src/n1ql/n1ql.cc +729 -0
- data/ext/libcouchbase/src/n1ql/params.cc +215 -0
- data/ext/libcouchbase/src/netbuf/netbuf-defs.h +89 -0
- data/ext/libcouchbase/src/netbuf/netbuf-mblock.h +235 -0
- data/ext/libcouchbase/src/netbuf/netbuf.c +929 -0
- data/ext/libcouchbase/src/netbuf/netbuf.h +452 -0
- data/ext/libcouchbase/src/newconfig.c +385 -0
- data/ext/libcouchbase/src/nodeinfo.cc +194 -0
- data/ext/libcouchbase/src/operations/cbflush.c +71 -0
- data/ext/libcouchbase/src/operations/counter.c +116 -0
- data/ext/libcouchbase/src/operations/durability-cas.c +224 -0
- data/ext/libcouchbase/src/operations/durability-seqno.c +157 -0
- data/ext/libcouchbase/src/operations/durability.c +668 -0
- data/ext/libcouchbase/src/operations/durability_internal.h +199 -0
- data/ext/libcouchbase/src/operations/get.c +409 -0
- data/ext/libcouchbase/src/operations/observe-seqno.c +96 -0
- data/ext/libcouchbase/src/operations/observe.c +340 -0
- data/ext/libcouchbase/src/operations/pktfwd.c +86 -0
- data/ext/libcouchbase/src/operations/remove.c +83 -0
- data/ext/libcouchbase/src/operations/stats.c +461 -0
- data/ext/libcouchbase/src/operations/store.c +360 -0
- data/ext/libcouchbase/src/operations/subdoc.cc +510 -0
- data/ext/libcouchbase/src/operations/touch.c +81 -0
- data/ext/libcouchbase/src/packetutils.c +60 -0
- data/ext/libcouchbase/src/packetutils.h +147 -0
- data/ext/libcouchbase/src/probes.d +211 -0
- data/ext/libcouchbase/src/rdb/bigalloc.c +225 -0
- data/ext/libcouchbase/src/rdb/bigalloc.h +73 -0
- data/ext/libcouchbase/src/rdb/chunkalloc.c +174 -0
- data/ext/libcouchbase/src/rdb/libcalloc.c +94 -0
- data/ext/libcouchbase/src/rdb/rope.c +419 -0
- data/ext/libcouchbase/src/rdb/rope.h +488 -0
- data/ext/libcouchbase/src/retrychk.c +113 -0
- data/ext/libcouchbase/src/retryq.c +424 -0
- data/ext/libcouchbase/src/retryq.h +157 -0
- data/ext/libcouchbase/src/ringbuffer.c +442 -0
- data/ext/libcouchbase/src/ringbuffer.h +100 -0
- data/ext/libcouchbase/src/settings.c +95 -0
- data/ext/libcouchbase/src/settings.h +188 -0
- data/ext/libcouchbase/src/simplestring.c +211 -0
- data/ext/libcouchbase/src/simplestring.h +228 -0
- data/ext/libcouchbase/src/sllist-inl.h +197 -0
- data/ext/libcouchbase/src/sllist.h +76 -0
- data/ext/libcouchbase/src/ssl/CMakeLists.txt +23 -0
- data/ext/libcouchbase/src/ssl/ssl_c.c +415 -0
- data/ext/libcouchbase/src/ssl/ssl_common.c +454 -0
- data/ext/libcouchbase/src/ssl/ssl_e.c +408 -0
- data/ext/libcouchbase/src/ssl/ssl_iot_common.h +180 -0
- data/ext/libcouchbase/src/ssobuf.h +82 -0
- data/ext/libcouchbase/src/strcodecs/base64.c +123 -0
- data/ext/libcouchbase/src/strcodecs/strcodecs.h +285 -0
- data/ext/libcouchbase/src/timings.c +208 -0
- data/ext/libcouchbase/src/trace.h +105 -0
- data/ext/libcouchbase/src/utilities.c +171 -0
- data/ext/libcouchbase/src/vbucket/CMakeLists.txt +2 -0
- data/ext/libcouchbase/src/vbucket/aliases.h +35 -0
- data/ext/libcouchbase/src/vbucket/crc32.h +83 -0
- data/ext/libcouchbase/src/vbucket/hash.h +30 -0
- data/ext/libcouchbase/src/vbucket/json-inl.h +112 -0
- data/ext/libcouchbase/src/vbucket/ketama.c +66 -0
- data/ext/libcouchbase/src/vbucket/rfc1321/global.h +32 -0
- data/ext/libcouchbase/src/vbucket/rfc1321/md5.h +35 -0
- data/ext/libcouchbase/src/vbucket/rfc1321/md5c-inl.h +335 -0
- data/ext/libcouchbase/src/vbucket/vbucket.c +1543 -0
- data/ext/libcouchbase/src/views/docreq.c +194 -0
- data/ext/libcouchbase/src/views/docreq.h +83 -0
- data/ext/libcouchbase/src/views/viewreq.c +358 -0
- data/ext/libcouchbase/src/views/viewreq.h +36 -0
- data/ext/libcouchbase/src/wait.c +161 -0
- data/ext/libcouchbase/tests/CMakeLists.txt +140 -0
- data/ext/libcouchbase/tests/basic/t_base64.cc +81 -0
- data/ext/libcouchbase/tests/basic/t_ccbc103.cc +95 -0
- data/ext/libcouchbase/tests/basic/t_connstr.cc +404 -0
- data/ext/libcouchbase/tests/basic/t_creds.cc +32 -0
- data/ext/libcouchbase/tests/basic/t_ctlcodes.cc +92 -0
- data/ext/libcouchbase/tests/basic/t_hashset.cc +262 -0
- data/ext/libcouchbase/tests/basic/t_host.cc +198 -0
- data/ext/libcouchbase/tests/basic/t_jsparse.cc +137 -0
- data/ext/libcouchbase/tests/basic/t_jsparse.h +589 -0
- data/ext/libcouchbase/tests/basic/t_list.cc +155 -0
- data/ext/libcouchbase/tests/basic/t_logger.cc +65 -0
- data/ext/libcouchbase/tests/basic/t_misc.cc +24 -0
- data/ext/libcouchbase/tests/basic/t_n1qlstrings.cc +18 -0
- data/ext/libcouchbase/tests/basic/t_netbuf.cc +446 -0
- data/ext/libcouchbase/tests/basic/t_packet.cc +222 -0
- data/ext/libcouchbase/tests/basic/t_ringbuffer.cc +278 -0
- data/ext/libcouchbase/tests/basic/t_slist.cc +429 -0
- data/ext/libcouchbase/tests/basic/t_strerror.cc +64 -0
- data/ext/libcouchbase/tests/basic/t_string.cc +112 -0
- data/ext/libcouchbase/tests/basic/t_urlencode.cc +132 -0
- data/ext/libcouchbase/tests/check-all.cc +608 -0
- data/ext/libcouchbase/tests/htparse/t_basic.cc +193 -0
- data/ext/libcouchbase/tests/ioserver/connection.cc +166 -0
- data/ext/libcouchbase/tests/ioserver/future.cc +50 -0
- data/ext/libcouchbase/tests/ioserver/ioserver.cc +104 -0
- data/ext/libcouchbase/tests/ioserver/ioserver.h +478 -0
- data/ext/libcouchbase/tests/ioserver/socket.cc +88 -0
- data/ext/libcouchbase/tests/ioserver/ssl_connection.cc +145 -0
- data/ext/libcouchbase/tests/ioserver/threads-pthreads.cc +119 -0
- data/ext/libcouchbase/tests/ioserver/threads-win32.cc +117 -0
- data/ext/libcouchbase/tests/ioserver/threads.h +66 -0
- data/ext/libcouchbase/tests/iotests/iotests.h +15 -0
- data/ext/libcouchbase/tests/iotests/mock-environment.cc +524 -0
- data/ext/libcouchbase/tests/iotests/mock-environment.h +385 -0
- data/ext/libcouchbase/tests/iotests/mock-unit-test.cc +67 -0
- data/ext/libcouchbase/tests/iotests/mock-unit-test.h +61 -0
- data/ext/libcouchbase/tests/iotests/serverparams.h +76 -0
- data/ext/libcouchbase/tests/iotests/t_arithmetic.cc +143 -0
- data/ext/libcouchbase/tests/iotests/t_behavior.cc +226 -0
- data/ext/libcouchbase/tests/iotests/t_configcache.cc +117 -0
- data/ext/libcouchbase/tests/iotests/t_confmon.cc +241 -0
- data/ext/libcouchbase/tests/iotests/t_durability.cc +1059 -0
- data/ext/libcouchbase/tests/iotests/t_forward.cc +110 -0
- data/ext/libcouchbase/tests/iotests/t_get.cc +512 -0
- data/ext/libcouchbase/tests/iotests/t_http.cc +438 -0
- data/ext/libcouchbase/tests/iotests/t_iops.cc +175 -0
- data/ext/libcouchbase/tests/iotests/t_lock.cc +275 -0
- data/ext/libcouchbase/tests/iotests/t_misc.cc +713 -0
- data/ext/libcouchbase/tests/iotests/t_mutate.cc +609 -0
- data/ext/libcouchbase/tests/iotests/t_n1ql.cc +270 -0
- data/ext/libcouchbase/tests/iotests/t_netfail.cc +654 -0
- data/ext/libcouchbase/tests/iotests/t_obseqno.cc +157 -0
- data/ext/libcouchbase/tests/iotests/t_regression.cc +321 -0
- data/ext/libcouchbase/tests/iotests/t_sched.cc +88 -0
- data/ext/libcouchbase/tests/iotests/t_serverops.cc +230 -0
- data/ext/libcouchbase/tests/iotests/t_smoke.cc +528 -0
- data/ext/libcouchbase/tests/iotests/t_subdoc.cc +822 -0
- data/ext/libcouchbase/tests/iotests/t_syncmode.cc +64 -0
- data/ext/libcouchbase/tests/iotests/t_views.cc +405 -0
- data/ext/libcouchbase/tests/iotests/testutil.cc +250 -0
- data/ext/libcouchbase/tests/iotests/testutil.h +163 -0
- data/ext/libcouchbase/tests/mc/mctest.h +119 -0
- data/ext/libcouchbase/tests/mc/pktmaker.h +101 -0
- data/ext/libcouchbase/tests/mc/t_alloc.cc +269 -0
- data/ext/libcouchbase/tests/mc/t_context.cc +100 -0
- data/ext/libcouchbase/tests/mc/t_flush.cc +185 -0
- data/ext/libcouchbase/tests/mc/t_forward.cc +239 -0
- data/ext/libcouchbase/tests/mc/t_ioflush.cc +102 -0
- data/ext/libcouchbase/tests/mc/t_iovcursor.cc +173 -0
- data/ext/libcouchbase/tests/mocksupport/procutil.c +305 -0
- data/ext/libcouchbase/tests/mocksupport/procutil.h +89 -0
- data/ext/libcouchbase/tests/mocksupport/server.c +391 -0
- data/ext/libcouchbase/tests/mocksupport/server.h +72 -0
- data/ext/libcouchbase/tests/mocksupport/timeout.c +69 -0
- data/ext/libcouchbase/tests/nonio_tests.cc +23 -0
- data/ext/libcouchbase/tests/rdb/rdbtest.h +133 -0
- data/ext/libcouchbase/tests/rdb/t_basic.cc +128 -0
- data/ext/libcouchbase/tests/rdb/t_bigalloc.cc +93 -0
- data/ext/libcouchbase/tests/rdb/t_refs.cc +112 -0
- data/ext/libcouchbase/tests/socktests/socktest.cc +347 -0
- data/ext/libcouchbase/tests/socktests/socktest.h +448 -0
- data/ext/libcouchbase/tests/socktests/t_basic.cc +143 -0
- data/ext/libcouchbase/tests/socktests/t_ctx.cc +73 -0
- data/ext/libcouchbase/tests/socktests/t_manager.cc +179 -0
- data/ext/libcouchbase/tests/socktests/t_putex.cc +256 -0
- data/ext/libcouchbase/tests/socktests/t_read.cc +187 -0
- data/ext/libcouchbase/tests/socktests/t_reentrant.cc +143 -0
- data/ext/libcouchbase/tests/socktests/t_ssl.cc +80 -0
- data/ext/libcouchbase/tests/socktests/t_write.cc +95 -0
- data/ext/libcouchbase/tests/start_mock.bat +15 -0
- data/ext/libcouchbase/tests/start_mock.sh +42 -0
- data/ext/libcouchbase/tests/unit_tests.cc +43 -0
- data/ext/libcouchbase/tests/vbucket/confdata/bad.json +101 -0
- data/ext/libcouchbase/tests/vbucket/confdata/full_25.json +363 -0
- data/ext/libcouchbase/tests/vbucket/confdata/memd_25.json +90 -0
- data/ext/libcouchbase/tests/vbucket/confdata/memd_30.json +1 -0
- data/ext/libcouchbase/tests/vbucket/confdata/memd_45.json +1 -0
- data/ext/libcouchbase/tests/vbucket/confdata/terse_25.json +291 -0
- data/ext/libcouchbase/tests/vbucket/confdata/terse_30.json +1 -0
- data/ext/libcouchbase/tests/vbucket/t_config.cc +341 -0
- data/ext/libcouchbase/tools/CMakeLists.txt +51 -0
- data/ext/libcouchbase/tools/cbc-handlers.h +462 -0
- data/ext/libcouchbase/tools/cbc-n1qlback.cc +439 -0
- data/ext/libcouchbase/tools/cbc-pillowfight.cc +822 -0
- data/ext/libcouchbase/tools/cbc.cc +1541 -0
- data/ext/libcouchbase/tools/common/histogram.cc +43 -0
- data/ext/libcouchbase/tools/common/histogram.h +23 -0
- data/ext/libcouchbase/tools/common/my_inttypes.h +22 -0
- data/ext/libcouchbase/tools/common/options.cc +420 -0
- data/ext/libcouchbase/tools/common/options.h +81 -0
- data/ext/libcouchbase/tools/docgen/docgen.h +469 -0
- data/ext/libcouchbase/tools/docgen/loc.h +210 -0
- data/ext/libcouchbase/tools/docgen/placeholders.h +211 -0
- data/ext/libcouchbase/tools/docgen/seqgen.h +94 -0
- data/lib/libcouchbase.rb +36 -0
- data/lib/libcouchbase/bucket.rb +819 -0
- data/lib/libcouchbase/callbacks.rb +72 -0
- data/lib/libcouchbase/connection.rb +790 -0
- data/lib/libcouchbase/design_docs.rb +86 -0
- data/lib/libcouchbase/error.rb +68 -0
- data/lib/libcouchbase/ext/libcouchbase.rb +1135 -0
- data/lib/libcouchbase/ext/libcouchbase/cmdbase.rb +23 -0
- data/lib/libcouchbase/ext/libcouchbase/cmdcounter.rb +36 -0
- data/lib/libcouchbase/ext/libcouchbase/cmdendure.rb +26 -0
- data/lib/libcouchbase/ext/libcouchbase/cmdfts.rb +24 -0
- data/lib/libcouchbase/ext/libcouchbase/cmdget.rb +30 -0
- data/lib/libcouchbase/ext/libcouchbase/cmdgetreplica.rb +49 -0
- data/lib/libcouchbase/ext/libcouchbase/cmdhttp.rb +58 -0
- data/lib/libcouchbase/ext/libcouchbase/cmdn1ql.rb +40 -0
- data/lib/libcouchbase/ext/libcouchbase/cmdobseqno.rb +33 -0
- data/lib/libcouchbase/ext/libcouchbase/cmdobserve.rb +30 -0
- data/lib/libcouchbase/ext/libcouchbase/cmdstore.rb +40 -0
- data/lib/libcouchbase/ext/libcouchbase/cmdstoredur.rb +45 -0
- data/lib/libcouchbase/ext/libcouchbase/cmdsubdoc.rb +49 -0
- data/lib/libcouchbase/ext/libcouchbase/cmdverbosity.rb +29 -0
- data/lib/libcouchbase/ext/libcouchbase/cmdviewquery.rb +61 -0
- data/lib/libcouchbase/ext/libcouchbase/contigbuf.rb +14 -0
- data/lib/libcouchbase/ext/libcouchbase/create_st.rb +15 -0
- data/lib/libcouchbase/ext/libcouchbase/create_st0.rb +23 -0
- data/lib/libcouchbase/ext/libcouchbase/create_st1.rb +26 -0
- data/lib/libcouchbase/ext/libcouchbase/create_st2.rb +32 -0
- data/lib/libcouchbase/ext/libcouchbase/create_st3.rb +26 -0
- data/lib/libcouchbase/ext/libcouchbase/crst_u.rb +20 -0
- data/lib/libcouchbase/ext/libcouchbase/durability_opts_st_v.rb +11 -0
- data/lib/libcouchbase/ext/libcouchbase/durability_opts_t.rb +14 -0
- data/lib/libcouchbase/ext/libcouchbase/durabilityopt_sv0.rb +63 -0
- data/lib/libcouchbase/ext/libcouchbase/enums.rb +991 -0
- data/lib/libcouchbase/ext/libcouchbase/fragbuf.rb +18 -0
- data/lib/libcouchbase/ext/libcouchbase/ftshandle.rb +7 -0
- data/lib/libcouchbase/ext/libcouchbase/histogram.rb +34 -0
- data/lib/libcouchbase/ext/libcouchbase/http_request_t.rb +7 -0
- data/lib/libcouchbase/ext/libcouchbase/keybuf.rb +20 -0
- data/lib/libcouchbase/ext/libcouchbase/multicmd_ctx.rb +30 -0
- data/lib/libcouchbase/ext/libcouchbase/mutation_token.rb +17 -0
- data/lib/libcouchbase/ext/libcouchbase/n1qlhandle.rb +7 -0
- data/lib/libcouchbase/ext/libcouchbase/n1qlparams.rb +7 -0
- data/lib/libcouchbase/ext/libcouchbase/respbase.rb +29 -0
- data/lib/libcouchbase/ext/libcouchbase/respcounter.rb +32 -0
- data/lib/libcouchbase/ext/libcouchbase/respendure.rb +49 -0
- data/lib/libcouchbase/ext/libcouchbase/respfts.rb +40 -0
- data/lib/libcouchbase/ext/libcouchbase/respget.rb +44 -0
- data/lib/libcouchbase/ext/libcouchbase/resphttp.rb +48 -0
- data/lib/libcouchbase/ext/libcouchbase/respmcversion.rb +38 -0
- data/lib/libcouchbase/ext/libcouchbase/respn1ql.rb +41 -0
- data/lib/libcouchbase/ext/libcouchbase/respobseqno.rb +52 -0
- data/lib/libcouchbase/ext/libcouchbase/respobserve.rb +41 -0
- data/lib/libcouchbase/ext/libcouchbase/respserverbase.rb +32 -0
- data/lib/libcouchbase/ext/libcouchbase/respstats.rb +38 -0
- data/lib/libcouchbase/ext/libcouchbase/respstore.rb +32 -0
- data/lib/libcouchbase/ext/libcouchbase/respstoredur.rb +38 -0
- data/lib/libcouchbase/ext/libcouchbase/respsubdoc.rb +35 -0
- data/lib/libcouchbase/ext/libcouchbase/respviewquery.rb +67 -0
- data/lib/libcouchbase/ext/libcouchbase/sdentry.rb +22 -0
- data/lib/libcouchbase/ext/libcouchbase/sdspec.rb +26 -0
- data/lib/libcouchbase/ext/libcouchbase/t.rb +7 -0
- data/lib/libcouchbase/ext/libcouchbase/valbuf.rb +22 -0
- data/lib/libcouchbase/ext/libcouchbase/valbuf_u_buf.rb +14 -0
- data/lib/libcouchbase/ext/libcouchbase/viewhandle.rb +7 -0
- data/lib/libcouchbase/ext/libcouchbase_iocp.rb +26 -0
- data/lib/libcouchbase/ext/libcouchbase_libuv.rb +18 -0
- data/lib/libcouchbase/ext/tasks.rb +87 -0
- data/lib/libcouchbase/n1ql.rb +73 -0
- data/lib/libcouchbase/query_full_text.rb +147 -0
- data/lib/libcouchbase/query_n1ql.rb +121 -0
- data/lib/libcouchbase/query_view.rb +129 -0
- data/lib/libcouchbase/results_fiber.rb +262 -0
- data/lib/libcouchbase/results_native.rb +211 -0
- data/lib/libcouchbase/version.rb +5 -0
- data/libcouchbase.gemspec +61 -0
- data/spec/bucket_spec.rb +270 -0
- data/spec/connection_spec.rb +277 -0
- data/spec/design_docs_spec.rb +23 -0
- data/spec/error_spec.rb +26 -0
- data/spec/fts_spec.rb +129 -0
- data/spec/n1ql_spec.rb +201 -0
- data/spec/results_libuv_spec.rb +229 -0
- data/spec/results_native_spec.rb +259 -0
- data/spec/seed/2016-10-25T043505Z/2016-10-25T043505Z-full/bucket-default/design.json +1 -0
- data/spec/seed/2016-10-25T043505Z/2016-10-25T043505Z-full/bucket-default/node-127.0.0.1%3A8091/data-0000.cbb +0 -0
- data/spec/seed/2016-10-25T043505Z/2016-10-25T043505Z-full/bucket-default/node-127.0.0.1%3A8091/failover.json +1 -0
- data/spec/seed/2016-10-25T043505Z/2016-10-25T043505Z-full/bucket-default/node-127.0.0.1%3A8091/meta.json +1 -0
- data/spec/seed/2016-10-25T043505Z/2016-10-25T043505Z-full/bucket-default/node-127.0.0.1%3A8091/seqno.json +1 -0
- data/spec/seed/2016-10-25T043505Z/2016-10-25T043505Z-full/bucket-default/node-127.0.0.1%3A8091/snapshot_markers.json +1 -0
- data/spec/view_spec.rb +195 -0
- metadata +775 -0
@@ -0,0 +1,137 @@
|
|
1
|
+
// Copyright 2011 Google Inc. All Rights Reserved.
|
2
|
+
//
|
3
|
+
// Redistribution and use in source and binary forms, with or without
|
4
|
+
// modification, are permitted provided that the following conditions are
|
5
|
+
// met:
|
6
|
+
//
|
7
|
+
// * Redistributions of source code must retain the above copyright
|
8
|
+
// notice, this list of conditions and the following disclaimer.
|
9
|
+
// * Redistributions in binary form must reproduce the above
|
10
|
+
// copyright notice, this list of conditions and the following disclaimer
|
11
|
+
// in the documentation and/or other materials provided with the
|
12
|
+
// distribution.
|
13
|
+
// * Neither the name of Google Inc. nor the names of its
|
14
|
+
// contributors may be used to endorse or promote products derived from
|
15
|
+
// this software without specific prior written permission.
|
16
|
+
//
|
17
|
+
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
18
|
+
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
19
|
+
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
20
|
+
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
21
|
+
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
22
|
+
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
23
|
+
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
24
|
+
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
25
|
+
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
26
|
+
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
27
|
+
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
28
|
+
|
29
|
+
#ifndef UTIL_SNAPPY_SNAPPY_SINKSOURCE_H_
|
30
|
+
#define UTIL_SNAPPY_SNAPPY_SINKSOURCE_H_
|
31
|
+
|
32
|
+
#include <stddef.h>
|
33
|
+
|
34
|
+
|
35
|
+
namespace snappy {
|
36
|
+
|
37
|
+
// A Sink is an interface that consumes a sequence of bytes.
|
38
|
+
class Sink {
|
39
|
+
public:
|
40
|
+
Sink() { }
|
41
|
+
virtual ~Sink();
|
42
|
+
|
43
|
+
// Append "bytes[0,n-1]" to this.
|
44
|
+
virtual void Append(const char* bytes, size_t n) = 0;
|
45
|
+
|
46
|
+
// Returns a writable buffer of the specified length for appending.
|
47
|
+
// May return a pointer to the caller-owned scratch buffer which
|
48
|
+
// must have at least the indicated length. The returned buffer is
|
49
|
+
// only valid until the next operation on this Sink.
|
50
|
+
//
|
51
|
+
// After writing at most "length" bytes, call Append() with the
|
52
|
+
// pointer returned from this function and the number of bytes
|
53
|
+
// written. Many Append() implementations will avoid copying
|
54
|
+
// bytes if this function returned an internal buffer.
|
55
|
+
//
|
56
|
+
// If a non-scratch buffer is returned, the caller may only pass a
|
57
|
+
// prefix of it to Append(). That is, it is not correct to pass an
|
58
|
+
// interior pointer of the returned array to Append().
|
59
|
+
//
|
60
|
+
// The default implementation always returns the scratch buffer.
|
61
|
+
virtual char* GetAppendBuffer(size_t length, char* scratch);
|
62
|
+
|
63
|
+
|
64
|
+
private:
|
65
|
+
// No copying
|
66
|
+
Sink(const Sink&);
|
67
|
+
void operator=(const Sink&);
|
68
|
+
};
|
69
|
+
|
70
|
+
// A Source is an interface that yields a sequence of bytes
|
71
|
+
class Source {
|
72
|
+
public:
|
73
|
+
Source() { }
|
74
|
+
virtual ~Source();
|
75
|
+
|
76
|
+
// Return the number of bytes left to read from the source
|
77
|
+
virtual size_t Available() const = 0;
|
78
|
+
|
79
|
+
// Peek at the next flat region of the source. Does not reposition
|
80
|
+
// the source. The returned region is empty iff Available()==0.
|
81
|
+
//
|
82
|
+
// Returns a pointer to the beginning of the region and store its
|
83
|
+
// length in *len.
|
84
|
+
//
|
85
|
+
// The returned region is valid until the next call to Skip() or
|
86
|
+
// until this object is destroyed, whichever occurs first.
|
87
|
+
//
|
88
|
+
// The returned region may be larger than Available() (for example
|
89
|
+
// if this ByteSource is a view on a substring of a larger source).
|
90
|
+
// The caller is responsible for ensuring that it only reads the
|
91
|
+
// Available() bytes.
|
92
|
+
virtual const char* Peek(size_t* len) = 0;
|
93
|
+
|
94
|
+
// Skip the next n bytes. Invalidates any buffer returned by
|
95
|
+
// a previous call to Peek().
|
96
|
+
// REQUIRES: Available() >= n
|
97
|
+
virtual void Skip(size_t n) = 0;
|
98
|
+
|
99
|
+
private:
|
100
|
+
// No copying
|
101
|
+
Source(const Source&);
|
102
|
+
void operator=(const Source&);
|
103
|
+
};
|
104
|
+
|
105
|
+
// A Source implementation that yields the contents of a flat array
|
106
|
+
class ByteArraySource : public Source {
|
107
|
+
public:
|
108
|
+
ByteArraySource(const char* p, size_t n) : ptr_(p), left_(n) { }
|
109
|
+
virtual ~ByteArraySource();
|
110
|
+
virtual size_t Available() const;
|
111
|
+
virtual const char* Peek(size_t* len);
|
112
|
+
virtual void Skip(size_t n);
|
113
|
+
private:
|
114
|
+
const char* ptr_;
|
115
|
+
size_t left_;
|
116
|
+
};
|
117
|
+
|
118
|
+
// A Sink implementation that writes to a flat array without any bound checks.
|
119
|
+
class UncheckedByteArraySink : public Sink {
|
120
|
+
public:
|
121
|
+
explicit UncheckedByteArraySink(char* dest) : dest_(dest) { }
|
122
|
+
virtual ~UncheckedByteArraySink();
|
123
|
+
virtual void Append(const char* data, size_t n);
|
124
|
+
virtual char* GetAppendBuffer(size_t len, char* scratch);
|
125
|
+
|
126
|
+
// Return the current output pointer so that a caller can see how
|
127
|
+
// many bytes were produced.
|
128
|
+
// Note: this is not a Sink method.
|
129
|
+
char* CurrentDestination() const { return dest_; }
|
130
|
+
private:
|
131
|
+
char* dest_;
|
132
|
+
};
|
133
|
+
|
134
|
+
|
135
|
+
}
|
136
|
+
|
137
|
+
#endif // UTIL_SNAPPY_SNAPPY_SINKSOURCE_H_
|
@@ -0,0 +1,42 @@
|
|
1
|
+
// Copyright 2011 Google Inc. All Rights Reserved.
|
2
|
+
//
|
3
|
+
// Redistribution and use in source and binary forms, with or without
|
4
|
+
// modification, are permitted provided that the following conditions are
|
5
|
+
// met:
|
6
|
+
//
|
7
|
+
// * Redistributions of source code must retain the above copyright
|
8
|
+
// notice, this list of conditions and the following disclaimer.
|
9
|
+
// * Redistributions in binary form must reproduce the above
|
10
|
+
// copyright notice, this list of conditions and the following disclaimer
|
11
|
+
// in the documentation and/or other materials provided with the
|
12
|
+
// distribution.
|
13
|
+
// * Neither the name of Google Inc. nor the names of its
|
14
|
+
// contributors may be used to endorse or promote products derived from
|
15
|
+
// this software without specific prior written permission.
|
16
|
+
//
|
17
|
+
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
18
|
+
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
19
|
+
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
20
|
+
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
21
|
+
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
22
|
+
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
23
|
+
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
24
|
+
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
25
|
+
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
26
|
+
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
27
|
+
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
28
|
+
|
29
|
+
#include <algorithm>
|
30
|
+
#include <string>
|
31
|
+
|
32
|
+
#include "snappy-stubs-internal.h"
|
33
|
+
|
34
|
+
namespace snappy {
|
35
|
+
|
36
|
+
void Varint::Append32(string* s, uint32 value) {
|
37
|
+
char buf[Varint::kMax32];
|
38
|
+
const char* p = Varint::Encode32(buf, value);
|
39
|
+
s->append(buf, p - buf);
|
40
|
+
}
|
41
|
+
|
42
|
+
} // namespace snappy
|
@@ -0,0 +1,491 @@
|
|
1
|
+
// Copyright 2011 Google Inc. All Rights Reserved.
|
2
|
+
//
|
3
|
+
// Redistribution and use in source and binary forms, with or without
|
4
|
+
// modification, are permitted provided that the following conditions are
|
5
|
+
// met:
|
6
|
+
//
|
7
|
+
// * Redistributions of source code must retain the above copyright
|
8
|
+
// notice, this list of conditions and the following disclaimer.
|
9
|
+
// * Redistributions in binary form must reproduce the above
|
10
|
+
// copyright notice, this list of conditions and the following disclaimer
|
11
|
+
// in the documentation and/or other materials provided with the
|
12
|
+
// distribution.
|
13
|
+
// * Neither the name of Google Inc. nor the names of its
|
14
|
+
// contributors may be used to endorse or promote products derived from
|
15
|
+
// this software without specific prior written permission.
|
16
|
+
//
|
17
|
+
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
18
|
+
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
19
|
+
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
20
|
+
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
21
|
+
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
22
|
+
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
23
|
+
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
24
|
+
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
25
|
+
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
26
|
+
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
27
|
+
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
28
|
+
//
|
29
|
+
// Various stubs for the open-source version of Snappy.
|
30
|
+
|
31
|
+
#ifndef UTIL_SNAPPY_OPENSOURCE_SNAPPY_STUBS_INTERNAL_H_
|
32
|
+
#define UTIL_SNAPPY_OPENSOURCE_SNAPPY_STUBS_INTERNAL_H_
|
33
|
+
|
34
|
+
#ifdef HAVE_CONFIG_H
|
35
|
+
#include "config.h"
|
36
|
+
#endif
|
37
|
+
|
38
|
+
#include <string>
|
39
|
+
|
40
|
+
#include <assert.h>
|
41
|
+
#include <stdlib.h>
|
42
|
+
#include <string.h>
|
43
|
+
|
44
|
+
#ifdef HAVE_SYS_MMAN_H
|
45
|
+
#include <sys/mman.h>
|
46
|
+
#endif
|
47
|
+
|
48
|
+
#include "snappy-stubs-public.h"
|
49
|
+
|
50
|
+
#if defined(__x86_64__)
|
51
|
+
|
52
|
+
// Enable 64-bit optimized versions of some routines.
|
53
|
+
#define ARCH_K8 1
|
54
|
+
|
55
|
+
#endif
|
56
|
+
|
57
|
+
// Needed by OS X, among others.
|
58
|
+
#ifndef MAP_ANONYMOUS
|
59
|
+
#define MAP_ANONYMOUS MAP_ANON
|
60
|
+
#endif
|
61
|
+
|
62
|
+
// Pull in std::min, std::ostream, and the likes. This is safe because this
|
63
|
+
// header file is never used from any public header files.
|
64
|
+
using namespace std;
|
65
|
+
|
66
|
+
// The size of an array, if known at compile-time.
|
67
|
+
// Will give unexpected results if used on a pointer.
|
68
|
+
// We undefine it first, since some compilers already have a definition.
|
69
|
+
#ifdef ARRAYSIZE
|
70
|
+
#undef ARRAYSIZE
|
71
|
+
#endif
|
72
|
+
#define ARRAYSIZE(a) (sizeof(a) / sizeof(*(a)))
|
73
|
+
|
74
|
+
// Static prediction hints.
|
75
|
+
#ifdef HAVE_BUILTIN_EXPECT
|
76
|
+
#define PREDICT_FALSE(x) (__builtin_expect(x, 0))
|
77
|
+
#define PREDICT_TRUE(x) (__builtin_expect(!!(x), 1))
|
78
|
+
#else
|
79
|
+
#define PREDICT_FALSE(x) x
|
80
|
+
#define PREDICT_TRUE(x) x
|
81
|
+
#endif
|
82
|
+
|
83
|
+
// This is only used for recomputing the tag byte table used during
|
84
|
+
// decompression; for simplicity we just remove it from the open-source
|
85
|
+
// version (anyone who wants to regenerate it can just do the call
|
86
|
+
// themselves within main()).
|
87
|
+
#define DEFINE_bool(flag_name, default_value, description) \
|
88
|
+
bool FLAGS_ ## flag_name = default_value
|
89
|
+
#define DECLARE_bool(flag_name) \
|
90
|
+
extern bool FLAGS_ ## flag_name
|
91
|
+
|
92
|
+
namespace snappy {
|
93
|
+
|
94
|
+
static const uint32 kuint32max = static_cast<uint32>(0xFFFFFFFF);
|
95
|
+
static const int64 kint64max = static_cast<int64>(0x7FFFFFFFFFFFFFFFLL);
|
96
|
+
|
97
|
+
// Potentially unaligned loads and stores.
|
98
|
+
|
99
|
+
// x86 and PowerPC can simply do these loads and stores native.
|
100
|
+
|
101
|
+
#if defined(__i386__) || defined(__x86_64__) || defined(__powerpc__)
|
102
|
+
|
103
|
+
#define UNALIGNED_LOAD16(_p) (*reinterpret_cast<const uint16 *>(_p))
|
104
|
+
#define UNALIGNED_LOAD32(_p) (*reinterpret_cast<const uint32 *>(_p))
|
105
|
+
#define UNALIGNED_LOAD64(_p) (*reinterpret_cast<const uint64 *>(_p))
|
106
|
+
|
107
|
+
#define UNALIGNED_STORE16(_p, _val) (*reinterpret_cast<uint16 *>(_p) = (_val))
|
108
|
+
#define UNALIGNED_STORE32(_p, _val) (*reinterpret_cast<uint32 *>(_p) = (_val))
|
109
|
+
#define UNALIGNED_STORE64(_p, _val) (*reinterpret_cast<uint64 *>(_p) = (_val))
|
110
|
+
|
111
|
+
// ARMv7 and newer support native unaligned accesses, but only of 16-bit
|
112
|
+
// and 32-bit values (not 64-bit); older versions either raise a fatal signal,
|
113
|
+
// do an unaligned read and rotate the words around a bit, or do the reads very
|
114
|
+
// slowly (trip through kernel mode). There's no simple #define that says just
|
115
|
+
// “ARMv7 or higher”, so we have to filter away all ARMv5 and ARMv6
|
116
|
+
// sub-architectures.
|
117
|
+
//
|
118
|
+
// This is a mess, but there's not much we can do about it.
|
119
|
+
|
120
|
+
#elif defined(__arm__) && \
|
121
|
+
!defined(__ARM_ARCH_4__) && \
|
122
|
+
!defined(__ARM_ARCH_4T__) && \
|
123
|
+
!defined(__ARM_ARCH_5__) && \
|
124
|
+
!defined(__ARM_ARCH_5T__) && \
|
125
|
+
!defined(__ARM_ARCH_5TE__) && \
|
126
|
+
!defined(__ARM_ARCH_5TEJ__) && \
|
127
|
+
!defined(__ARM_ARCH_6__) && \
|
128
|
+
!defined(__ARM_ARCH_6J__) && \
|
129
|
+
!defined(__ARM_ARCH_6K__) && \
|
130
|
+
!defined(__ARM_ARCH_6Z__) && \
|
131
|
+
!defined(__ARM_ARCH_6ZK__) && \
|
132
|
+
!defined(__ARM_ARCH_6T2__)
|
133
|
+
|
134
|
+
#define UNALIGNED_LOAD16(_p) (*reinterpret_cast<const uint16 *>(_p))
|
135
|
+
#define UNALIGNED_LOAD32(_p) (*reinterpret_cast<const uint32 *>(_p))
|
136
|
+
|
137
|
+
#define UNALIGNED_STORE16(_p, _val) (*reinterpret_cast<uint16 *>(_p) = (_val))
|
138
|
+
#define UNALIGNED_STORE32(_p, _val) (*reinterpret_cast<uint32 *>(_p) = (_val))
|
139
|
+
|
140
|
+
// TODO(user): NEON supports unaligned 64-bit loads and stores.
|
141
|
+
// See if that would be more efficient on platforms supporting it,
|
142
|
+
// at least for copies.
|
143
|
+
|
144
|
+
inline uint64 UNALIGNED_LOAD64(const void *p) {
|
145
|
+
uint64 t;
|
146
|
+
memcpy(&t, p, sizeof t);
|
147
|
+
return t;
|
148
|
+
}
|
149
|
+
|
150
|
+
inline void UNALIGNED_STORE64(void *p, uint64 v) {
|
151
|
+
memcpy(p, &v, sizeof v);
|
152
|
+
}
|
153
|
+
|
154
|
+
#else
|
155
|
+
|
156
|
+
// These functions are provided for architectures that don't support
|
157
|
+
// unaligned loads and stores.
|
158
|
+
|
159
|
+
inline uint16 UNALIGNED_LOAD16(const void *p) {
|
160
|
+
uint16 t;
|
161
|
+
memcpy(&t, p, sizeof t);
|
162
|
+
return t;
|
163
|
+
}
|
164
|
+
|
165
|
+
inline uint32 UNALIGNED_LOAD32(const void *p) {
|
166
|
+
uint32 t;
|
167
|
+
memcpy(&t, p, sizeof t);
|
168
|
+
return t;
|
169
|
+
}
|
170
|
+
|
171
|
+
inline uint64 UNALIGNED_LOAD64(const void *p) {
|
172
|
+
uint64 t;
|
173
|
+
memcpy(&t, p, sizeof t);
|
174
|
+
return t;
|
175
|
+
}
|
176
|
+
|
177
|
+
inline void UNALIGNED_STORE16(void *p, uint16 v) {
|
178
|
+
memcpy(p, &v, sizeof v);
|
179
|
+
}
|
180
|
+
|
181
|
+
inline void UNALIGNED_STORE32(void *p, uint32 v) {
|
182
|
+
memcpy(p, &v, sizeof v);
|
183
|
+
}
|
184
|
+
|
185
|
+
inline void UNALIGNED_STORE64(void *p, uint64 v) {
|
186
|
+
memcpy(p, &v, sizeof v);
|
187
|
+
}
|
188
|
+
|
189
|
+
#endif
|
190
|
+
|
191
|
+
// This can be more efficient than UNALIGNED_LOAD64 + UNALIGNED_STORE64
|
192
|
+
// on some platforms, in particular ARM.
|
193
|
+
inline void UnalignedCopy64(const void *src, void *dst) {
|
194
|
+
if (sizeof(void *) == 8) {
|
195
|
+
UNALIGNED_STORE64(dst, UNALIGNED_LOAD64(src));
|
196
|
+
} else {
|
197
|
+
const char *src_char = reinterpret_cast<const char *>(src);
|
198
|
+
char *dst_char = reinterpret_cast<char *>(dst);
|
199
|
+
|
200
|
+
UNALIGNED_STORE32(dst_char, UNALIGNED_LOAD32(src_char));
|
201
|
+
UNALIGNED_STORE32(dst_char + 4, UNALIGNED_LOAD32(src_char + 4));
|
202
|
+
}
|
203
|
+
}
|
204
|
+
|
205
|
+
// The following guarantees declaration of the byte swap functions.
|
206
|
+
#ifdef WORDS_BIGENDIAN
|
207
|
+
|
208
|
+
#ifdef HAVE_SYS_BYTEORDER_H
|
209
|
+
#include <sys/byteorder.h>
|
210
|
+
#endif
|
211
|
+
|
212
|
+
#ifdef HAVE_SYS_ENDIAN_H
|
213
|
+
#include <sys/endian.h>
|
214
|
+
#endif
|
215
|
+
|
216
|
+
#ifdef _MSC_VER
|
217
|
+
#include <stdlib.h>
|
218
|
+
#define bswap_16(x) _byteswap_ushort(x)
|
219
|
+
#define bswap_32(x) _byteswap_ulong(x)
|
220
|
+
#define bswap_64(x) _byteswap_uint64(x)
|
221
|
+
|
222
|
+
#elif defined(__APPLE__)
|
223
|
+
// Mac OS X / Darwin features
|
224
|
+
#include <libkern/OSByteOrder.h>
|
225
|
+
#define bswap_16(x) OSSwapInt16(x)
|
226
|
+
#define bswap_32(x) OSSwapInt32(x)
|
227
|
+
#define bswap_64(x) OSSwapInt64(x)
|
228
|
+
|
229
|
+
#elif defined(HAVE_BYTESWAP_H)
|
230
|
+
#include <byteswap.h>
|
231
|
+
|
232
|
+
#elif defined(bswap32)
|
233
|
+
// FreeBSD defines bswap{16,32,64} in <sys/endian.h> (already #included).
|
234
|
+
#define bswap_16(x) bswap16(x)
|
235
|
+
#define bswap_32(x) bswap32(x)
|
236
|
+
#define bswap_64(x) bswap64(x)
|
237
|
+
|
238
|
+
#elif defined(BSWAP_64)
|
239
|
+
// Solaris 10 defines BSWAP_{16,32,64} in <sys/byteorder.h> (already #included).
|
240
|
+
#define bswap_16(x) BSWAP_16(x)
|
241
|
+
#define bswap_32(x) BSWAP_32(x)
|
242
|
+
#define bswap_64(x) BSWAP_64(x)
|
243
|
+
|
244
|
+
#else
|
245
|
+
|
246
|
+
inline uint16 bswap_16(uint16 x) {
|
247
|
+
return (x << 8) | (x >> 8);
|
248
|
+
}
|
249
|
+
|
250
|
+
inline uint32 bswap_32(uint32 x) {
|
251
|
+
x = ((x & 0xff00ff00UL) >> 8) | ((x & 0x00ff00ffUL) << 8);
|
252
|
+
return (x >> 16) | (x << 16);
|
253
|
+
}
|
254
|
+
|
255
|
+
inline uint64 bswap_64(uint64 x) {
|
256
|
+
x = ((x & 0xff00ff00ff00ff00ULL) >> 8) | ((x & 0x00ff00ff00ff00ffULL) << 8);
|
257
|
+
x = ((x & 0xffff0000ffff0000ULL) >> 16) | ((x & 0x0000ffff0000ffffULL) << 16);
|
258
|
+
return (x >> 32) | (x << 32);
|
259
|
+
}
|
260
|
+
|
261
|
+
#endif
|
262
|
+
|
263
|
+
#endif // WORDS_BIGENDIAN
|
264
|
+
|
265
|
+
// Convert to little-endian storage, opposite of network format.
|
266
|
+
// Convert x from host to little endian: x = LittleEndian.FromHost(x);
|
267
|
+
// convert x from little endian to host: x = LittleEndian.ToHost(x);
|
268
|
+
//
|
269
|
+
// Store values into unaligned memory converting to little endian order:
|
270
|
+
// LittleEndian.Store16(p, x);
|
271
|
+
//
|
272
|
+
// Load unaligned values stored in little endian converting to host order:
|
273
|
+
// x = LittleEndian.Load16(p);
|
274
|
+
class LittleEndian {
|
275
|
+
public:
|
276
|
+
// Conversion functions.
|
277
|
+
#ifdef WORDS_BIGENDIAN
|
278
|
+
|
279
|
+
static uint16 FromHost16(uint16 x) { return bswap_16(x); }
|
280
|
+
static uint16 ToHost16(uint16 x) { return bswap_16(x); }
|
281
|
+
|
282
|
+
static uint32 FromHost32(uint32 x) { return bswap_32(x); }
|
283
|
+
static uint32 ToHost32(uint32 x) { return bswap_32(x); }
|
284
|
+
|
285
|
+
static bool IsLittleEndian() { return false; }
|
286
|
+
|
287
|
+
#else // !defined(WORDS_BIGENDIAN)
|
288
|
+
|
289
|
+
static uint16 FromHost16(uint16 x) { return x; }
|
290
|
+
static uint16 ToHost16(uint16 x) { return x; }
|
291
|
+
|
292
|
+
static uint32 FromHost32(uint32 x) { return x; }
|
293
|
+
static uint32 ToHost32(uint32 x) { return x; }
|
294
|
+
|
295
|
+
static bool IsLittleEndian() { return true; }
|
296
|
+
|
297
|
+
#endif // !defined(WORDS_BIGENDIAN)
|
298
|
+
|
299
|
+
// Functions to do unaligned loads and stores in little-endian order.
|
300
|
+
static uint16 Load16(const void *p) {
|
301
|
+
return ToHost16(UNALIGNED_LOAD16(p));
|
302
|
+
}
|
303
|
+
|
304
|
+
static void Store16(void *p, uint16 v) {
|
305
|
+
UNALIGNED_STORE16(p, FromHost16(v));
|
306
|
+
}
|
307
|
+
|
308
|
+
static uint32 Load32(const void *p) {
|
309
|
+
return ToHost32(UNALIGNED_LOAD32(p));
|
310
|
+
}
|
311
|
+
|
312
|
+
static void Store32(void *p, uint32 v) {
|
313
|
+
UNALIGNED_STORE32(p, FromHost32(v));
|
314
|
+
}
|
315
|
+
};
|
316
|
+
|
317
|
+
// Some bit-manipulation functions.
|
318
|
+
class Bits {
|
319
|
+
public:
|
320
|
+
// Return floor(log2(n)) for positive integer n. Returns -1 iff n == 0.
|
321
|
+
static int Log2Floor(uint32 n);
|
322
|
+
|
323
|
+
// Return the first set least / most significant bit, 0-indexed. Returns an
|
324
|
+
// undefined value if n == 0. FindLSBSetNonZero() is similar to ffs() except
|
325
|
+
// that it's 0-indexed.
|
326
|
+
static int FindLSBSetNonZero(uint32 n);
|
327
|
+
static int FindLSBSetNonZero64(uint64 n);
|
328
|
+
|
329
|
+
private:
|
330
|
+
DISALLOW_COPY_AND_ASSIGN(Bits);
|
331
|
+
};
|
332
|
+
|
333
|
+
#ifdef HAVE_BUILTIN_CTZ
|
334
|
+
|
335
|
+
inline int Bits::Log2Floor(uint32 n) {
|
336
|
+
return n == 0 ? -1 : 31 ^ __builtin_clz(n);
|
337
|
+
}
|
338
|
+
|
339
|
+
inline int Bits::FindLSBSetNonZero(uint32 n) {
|
340
|
+
return __builtin_ctz(n);
|
341
|
+
}
|
342
|
+
|
343
|
+
inline int Bits::FindLSBSetNonZero64(uint64 n) {
|
344
|
+
return __builtin_ctzll(n);
|
345
|
+
}
|
346
|
+
|
347
|
+
#else // Portable versions.
|
348
|
+
|
349
|
+
inline int Bits::Log2Floor(uint32 n) {
|
350
|
+
if (n == 0)
|
351
|
+
return -1;
|
352
|
+
int log = 0;
|
353
|
+
uint32 value = n;
|
354
|
+
for (int i = 4; i >= 0; --i) {
|
355
|
+
int shift = (1 << i);
|
356
|
+
uint32 x = value >> shift;
|
357
|
+
if (x != 0) {
|
358
|
+
value = x;
|
359
|
+
log += shift;
|
360
|
+
}
|
361
|
+
}
|
362
|
+
assert(value == 1);
|
363
|
+
return log;
|
364
|
+
}
|
365
|
+
|
366
|
+
inline int Bits::FindLSBSetNonZero(uint32 n) {
|
367
|
+
int rc = 31;
|
368
|
+
for (int i = 4, shift = 1 << 4; i >= 0; --i) {
|
369
|
+
const uint32 x = n << shift;
|
370
|
+
if (x != 0) {
|
371
|
+
n = x;
|
372
|
+
rc -= shift;
|
373
|
+
}
|
374
|
+
shift >>= 1;
|
375
|
+
}
|
376
|
+
return rc;
|
377
|
+
}
|
378
|
+
|
379
|
+
// FindLSBSetNonZero64() is defined in terms of FindLSBSetNonZero().
|
380
|
+
inline int Bits::FindLSBSetNonZero64(uint64 n) {
|
381
|
+
const uint32 bottombits = static_cast<uint32>(n);
|
382
|
+
if (bottombits == 0) {
|
383
|
+
// Bottom bits are zero, so scan in top bits
|
384
|
+
return 32 + FindLSBSetNonZero(static_cast<uint32>(n >> 32));
|
385
|
+
} else {
|
386
|
+
return FindLSBSetNonZero(bottombits);
|
387
|
+
}
|
388
|
+
}
|
389
|
+
|
390
|
+
#endif // End portable versions.
|
391
|
+
|
392
|
+
// Variable-length integer encoding.
|
393
|
+
class Varint {
|
394
|
+
public:
|
395
|
+
// Maximum lengths of varint encoding of uint32.
|
396
|
+
static const int kMax32 = 5;
|
397
|
+
|
398
|
+
// Attempts to parse a varint32 from a prefix of the bytes in [ptr,limit-1].
|
399
|
+
// Never reads a character at or beyond limit. If a valid/terminated varint32
|
400
|
+
// was found in the range, stores it in *OUTPUT and returns a pointer just
|
401
|
+
// past the last byte of the varint32. Else returns NULL. On success,
|
402
|
+
// "result <= limit".
|
403
|
+
static const char* Parse32WithLimit(const char* ptr, const char* limit,
|
404
|
+
uint32* OUTPUT);
|
405
|
+
|
406
|
+
// REQUIRES "ptr" points to a buffer of length sufficient to hold "v".
|
407
|
+
// EFFECTS Encodes "v" into "ptr" and returns a pointer to the
|
408
|
+
// byte just past the last encoded byte.
|
409
|
+
static char* Encode32(char* ptr, uint32 v);
|
410
|
+
|
411
|
+
// EFFECTS Appends the varint representation of "value" to "*s".
|
412
|
+
static void Append32(string* s, uint32 value);
|
413
|
+
};
|
414
|
+
|
415
|
+
inline const char* Varint::Parse32WithLimit(const char* p,
|
416
|
+
const char* l,
|
417
|
+
uint32* OUTPUT) {
|
418
|
+
const unsigned char* ptr = reinterpret_cast<const unsigned char*>(p);
|
419
|
+
const unsigned char* limit = reinterpret_cast<const unsigned char*>(l);
|
420
|
+
uint32 b, result;
|
421
|
+
if (ptr >= limit) return NULL;
|
422
|
+
b = *(ptr++); result = b & 127; if (b < 128) goto done;
|
423
|
+
if (ptr >= limit) return NULL;
|
424
|
+
b = *(ptr++); result |= (b & 127) << 7; if (b < 128) goto done;
|
425
|
+
if (ptr >= limit) return NULL;
|
426
|
+
b = *(ptr++); result |= (b & 127) << 14; if (b < 128) goto done;
|
427
|
+
if (ptr >= limit) return NULL;
|
428
|
+
b = *(ptr++); result |= (b & 127) << 21; if (b < 128) goto done;
|
429
|
+
if (ptr >= limit) return NULL;
|
430
|
+
b = *(ptr++); result |= (b & 127) << 28; if (b < 16) goto done;
|
431
|
+
return NULL; // Value is too long to be a varint32
|
432
|
+
done:
|
433
|
+
*OUTPUT = result;
|
434
|
+
return reinterpret_cast<const char*>(ptr);
|
435
|
+
}
|
436
|
+
|
437
|
+
inline char* Varint::Encode32(char* sptr, uint32 v) {
|
438
|
+
// Operate on characters as unsigneds
|
439
|
+
unsigned char* ptr = reinterpret_cast<unsigned char*>(sptr);
|
440
|
+
static const int B = 128;
|
441
|
+
if (v < (1<<7)) {
|
442
|
+
*(ptr++) = v;
|
443
|
+
} else if (v < (1<<14)) {
|
444
|
+
*(ptr++) = v | B;
|
445
|
+
*(ptr++) = v>>7;
|
446
|
+
} else if (v < (1<<21)) {
|
447
|
+
*(ptr++) = v | B;
|
448
|
+
*(ptr++) = (v>>7) | B;
|
449
|
+
*(ptr++) = v>>14;
|
450
|
+
} else if (v < (1<<28)) {
|
451
|
+
*(ptr++) = v | B;
|
452
|
+
*(ptr++) = (v>>7) | B;
|
453
|
+
*(ptr++) = (v>>14) | B;
|
454
|
+
*(ptr++) = v>>21;
|
455
|
+
} else {
|
456
|
+
*(ptr++) = v | B;
|
457
|
+
*(ptr++) = (v>>7) | B;
|
458
|
+
*(ptr++) = (v>>14) | B;
|
459
|
+
*(ptr++) = (v>>21) | B;
|
460
|
+
*(ptr++) = v>>28;
|
461
|
+
}
|
462
|
+
return reinterpret_cast<char*>(ptr);
|
463
|
+
}
|
464
|
+
|
465
|
+
// If you know the internal layout of the std::string in use, you can
|
466
|
+
// replace this function with one that resizes the string without
|
467
|
+
// filling the new space with zeros (if applicable) --
|
468
|
+
// it will be non-portable but faster.
|
469
|
+
inline void STLStringResizeUninitialized(string* s, size_t new_size) {
|
470
|
+
s->resize(new_size);
|
471
|
+
}
|
472
|
+
|
473
|
+
// Return a mutable char* pointing to a string's internal buffer,
|
474
|
+
// which may not be null-terminated. Writing through this pointer will
|
475
|
+
// modify the string.
|
476
|
+
//
|
477
|
+
// string_as_array(&str)[i] is valid for 0 <= i < str.size() until the
|
478
|
+
// next call to a string method that invalidates iterators.
|
479
|
+
//
|
480
|
+
// As of 2006-04, there is no standard-blessed way of getting a
|
481
|
+
// mutable reference to a string's internal buffer. However, issue 530
|
482
|
+
// (http://www.open-std.org/JTC1/SC22/WG21/docs/lwg-defects.html#530)
|
483
|
+
// proposes this as the method. It will officially be part of the standard
|
484
|
+
// for C++0x. This should already work on all current implementations.
|
485
|
+
inline char* string_as_array(string* str) {
|
486
|
+
return str->empty() ? NULL : &*str->begin();
|
487
|
+
}
|
488
|
+
|
489
|
+
} // namespace snappy
|
490
|
+
|
491
|
+
#endif // UTIL_SNAPPY_OPENSOURCE_SNAPPY_STUBS_INTERNAL_H_
|