| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | // | ||
| 2 | // Copyright (c) 2025 Vinnie Falco (vinnie.falco@gmail.com) | ||
| 3 | // Copyright (c) 2025 Mohammad Nejati | ||
| 4 | // | ||
| 5 | // Distributed under the Boost Software License, Version 1.0. (See accompanying | ||
| 6 | // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) | ||
| 7 | // | ||
| 8 | // Official repository: https://github.com/cppalliance/capy | ||
| 9 | // | ||
| 10 | |||
| 11 | #include <boost/capy/polystore.hpp> | ||
| 12 | #include <boost/capy/zlib/inflate.hpp> | ||
| 13 | |||
| 14 | #include "stream_cast.hpp" | ||
| 15 | |||
| 16 | #include <boost/core/detail/static_assert.hpp> | ||
| 17 | |||
| 18 | #include <zlib.h> | ||
| 19 | |||
| 20 | namespace boost { | ||
| 21 | namespace capy { | ||
| 22 | namespace zlib { | ||
| 23 | |||
| 24 | BOOST_CORE_STATIC_ASSERT(sizeof(stream) == sizeof(z_stream_s)); | ||
| 25 | BOOST_CORE_STATIC_ASSERT(is_layout_identical<stream, z_stream_s>()); | ||
| 26 | |||
| 27 | //------------------------------------------------ | ||
| 28 | |||
| 29 | class inflate_service_impl | ||
| 30 | : public inflate_service | ||
| 31 | { | ||
| 32 | public: | ||
| 33 | using key_type = inflate_service; | ||
| 34 | |||
| 35 | explicit | ||
| 36 | 1 | inflate_service_impl( | |
| 37 | capy::polystore&) noexcept | ||
| 38 | 1 | { | |
| 39 | 1 | } | |
| 40 | |||
| 41 | 1 | ~inflate_service_impl() | |
| 42 | 1 | { | |
| 43 | 1 | } | |
| 44 | |||
| 45 | char const* | ||
| 46 | ✗ | version() const noexcept override | |
| 47 | { | ||
| 48 | ✗ | return zlibVersion(); | |
| 49 | } | ||
| 50 | |||
| 51 | int | ||
| 52 | ✗ | init( | |
| 53 | stream& st) const override | ||
| 54 | { | ||
| 55 | ✗ | stream_cast sc(st); | |
| 56 | ✗ | return inflateInit(sc.get()); | |
| 57 | } | ||
| 58 | |||
| 59 | int | ||
| 60 | ✗ | init2( | |
| 61 | stream& st, | ||
| 62 | int windowBits) const override | ||
| 63 | { | ||
| 64 | ✗ | stream_cast sc(st); | |
| 65 | ✗ | return inflateInit2(sc.get(), windowBits); | |
| 66 | } | ||
| 67 | |||
| 68 | int | ||
| 69 | ✗ | inflate( | |
| 70 | stream& st, | ||
| 71 | int flush) const override | ||
| 72 | { | ||
| 73 | ✗ | stream_cast sc(st); | |
| 74 | ✗ | return ::inflate(sc.get(), flush); | |
| 75 | } | ||
| 76 | |||
| 77 | int | ||
| 78 | ✗ | inflate_end( | |
| 79 | stream& st) const override | ||
| 80 | { | ||
| 81 | ✗ | stream_cast sc(st); | |
| 82 | ✗ | return inflateEnd(sc.get()); | |
| 83 | } | ||
| 84 | |||
| 85 | int | ||
| 86 | ✗ | set_dict( | |
| 87 | stream& st, | ||
| 88 | unsigned char const* dict, | ||
| 89 | unsigned len) const override | ||
| 90 | { | ||
| 91 | ✗ | stream_cast sc(st); | |
| 92 | ✗ | return inflateSetDictionary(sc.get(), dict, len); | |
| 93 | } | ||
| 94 | |||
| 95 | int | ||
| 96 | ✗ | get_dict( | |
| 97 | stream& st, | ||
| 98 | unsigned char* dest, | ||
| 99 | unsigned* len) const override | ||
| 100 | { | ||
| 101 | ✗ | stream_cast sc(st); | |
| 102 | ✗ | return inflateGetDictionary(sc.get(), dest, len); | |
| 103 | } | ||
| 104 | |||
| 105 | int | ||
| 106 | ✗ | sync( | |
| 107 | stream& st) const override | ||
| 108 | { | ||
| 109 | ✗ | stream_cast sc(st); | |
| 110 | ✗ | return inflateSync(sc.get()); | |
| 111 | } | ||
| 112 | |||
| 113 | int | ||
| 114 | ✗ | dup( | |
| 115 | stream& dest, | ||
| 116 | stream& src) const override | ||
| 117 | { | ||
| 118 | ✗ | stream_cast sc0(dest); | |
| 119 | ✗ | stream_cast sc1(src); | |
| 120 | ✗ | return inflateCopy(sc0.get(), sc1.get()); | |
| 121 | } | ||
| 122 | |||
| 123 | int | ||
| 124 | ✗ | reset( | |
| 125 | stream& st) const override | ||
| 126 | { | ||
| 127 | ✗ | stream_cast sc(st); | |
| 128 | ✗ | return inflateReset(sc.get()); | |
| 129 | } | ||
| 130 | |||
| 131 | int | ||
| 132 | ✗ | reset2( | |
| 133 | stream& st, | ||
| 134 | int windowBits) const override | ||
| 135 | { | ||
| 136 | ✗ | stream_cast sc(st); | |
| 137 | ✗ | return inflateReset2(sc.get(), windowBits); | |
| 138 | } | ||
| 139 | |||
| 140 | int | ||
| 141 | ✗ | prime( | |
| 142 | stream& st, | ||
| 143 | int bits, | ||
| 144 | int value) const override | ||
| 145 | { | ||
| 146 | ✗ | stream_cast sc(st); | |
| 147 | ✗ | return inflatePrime(sc.get(), bits, value); | |
| 148 | } | ||
| 149 | |||
| 150 | long | ||
| 151 | ✗ | mark( | |
| 152 | stream& st) const override | ||
| 153 | { | ||
| 154 | ✗ | stream_cast sc(st); | |
| 155 | ✗ | return inflateMark(sc.get()); | |
| 156 | } | ||
| 157 | |||
| 158 | int | ||
| 159 | ✗ | get_header( | |
| 160 | stream& st, | ||
| 161 | void* header) const override | ||
| 162 | { | ||
| 163 | ✗ | stream_cast sc(st); | |
| 164 | ✗ | return inflateGetHeader(sc.get(), | |
| 165 | ✗ | reinterpret_cast<gz_headerp>(header)); | |
| 166 | } | ||
| 167 | |||
| 168 | int | ||
| 169 | ✗ | back_init( | |
| 170 | stream& st, | ||
| 171 | int windowBits, | ||
| 172 | unsigned char* window) const override | ||
| 173 | { | ||
| 174 | ✗ | stream_cast sc(st); | |
| 175 | ✗ | return inflateBackInit(sc.get(), windowBits, window); | |
| 176 | } | ||
| 177 | |||
| 178 | int | ||
| 179 | ✗ | back_end( | |
| 180 | stream& st) const override | ||
| 181 | { | ||
| 182 | ✗ | stream_cast sc(st); | |
| 183 | ✗ | return inflateBackEnd(sc.get()); | |
| 184 | } | ||
| 185 | |||
| 186 | unsigned long | ||
| 187 | ✗ | compile_flags() const override | |
| 188 | { | ||
| 189 | ✗ | return zlibCompileFlags(); | |
| 190 | } | ||
| 191 | }; | ||
| 192 | |||
| 193 | inflate_service& | ||
| 194 | 1 | install_inflate_service(polystore& ctx) | |
| 195 | { | ||
| 196 | 1 | return ctx.emplace<inflate_service_impl>(ctx); | |
| 197 | } | ||
| 198 | |||
| 199 | } // zlib | ||
| 200 | } // capy | ||
| 201 | } // boost | ||
| 202 |