27 if (
static_cast<int>(in_size) < 0)
28 Throw<std::runtime_error>(
"lz4_decompress: integer overflow (input)");
34 if (n == 0 || n >= in_size)
35 Throw<std::runtime_error>(
"lz4_decompress: invalid blob");
37 if (
static_cast<int>(outSize) <= 0)
38 Throw<std::runtime_error>(
"lz4_decompress: integer overflow (output)");
40 void*
const out = bf(outSize);
42 if (LZ4_decompress_safe(
43 reinterpret_cast<char const*
>(
in) + n,
44 reinterpret_cast<char*
>(
out),
45 static_cast<int>(in_size - n),
46 static_cast<int>(outSize)) !=
static_cast<int>(outSize))
47 Throw<std::runtime_error>(
"lz4_decompress: LZ4_decompress_safe");
49 return {
out, outSize};
88 using namespace nudb::detail;
94 Throw<std::runtime_error>(
"nodeobject decompress");
114 auto const hs = field<std::uint16_t>::size;
115 if (in_size < hs + 32)
116 Throw<std::runtime_error>(
117 "nodeobject codec v1: short inner node size: " +
std::string(
"in_size = ") +
119 istream is(p, in_size);
121 read<std::uint16_t>(is, mask);
127 write<std::uint32_t>(os, 0);
128 write<std::uint32_t>(os, 0);
132 Throw<std::runtime_error>(
"nodeobject codec v1: empty inner node");
134 for (
int i = 16; i--; bit >>= 1)
139 Throw<std::runtime_error>(
140 "nodeobject codec v1: short inner node subsize: " +
std::string(
"in_size = ") +
151 Throw<std::runtime_error>(
"nodeobject codec v1: long inner node, in_size = " +
std::to_string(in_size));
156 if (in_size != 16 * 32)
157 Throw<std::runtime_error>(
158 "nodeobject codec v1: short full inner node, in_size = " +
std::to_string(in_size));
159 istream is(p, in_size);
164 write<std::uint32_t>(os, 0);
165 write<std::uint32_t>(os, 0);
168 write(os, is(512), 512);
172 Throw<std::runtime_error>(
"nodeobject codec: bad type=" +
std::to_string(type));
190 using namespace nudb::detail;
195 istream is(
in, in_size);
200 read<std::uint32_t>(is, index);
201 read<std::uint32_t>(is, unused);
202 read<std::uint8_t>(is, kind);
203 read<std::uint32_t>(is, prefix);
209 for (
unsigned bit = 0x8000; bit; bit >>= 1)
211 void const*
const h = is(32);
222 auto const type = 2U;
224 result.
second = vs + field<std::uint16_t>::size +
229 write<varint>(os, type);
230 write<std::uint16_t>(os, mask);
235 auto const type = 3U;
237 result.
second = vs + n * 32;
241 write<varint>(os, type);
264 result.
second = vn + lzr.second;
268 Throw<std::logic_error>(
"nodeobject codec: unknown=" +
std::to_string(codecType));
281 using namespace nudb::detail;
286 istream is(
in, in_size);
291 read<std::uint32_t>(is, index);
292 read<std::uint32_t>(is, unused);
293 read<std::uint8_t>(is, kind);
294 read<std::uint32_t>(is, prefix);
298 write<std::uint32_t>(os, 0);
299 write<std::uint32_t>(os, 0);