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: " +
152 Throw<std::runtime_error>(
153 "nodeobject codec v1: long inner node, in_size = " +
std::to_string(in_size));
158 if (in_size != 16 * 32)
159 Throw<std::runtime_error>(
160 "nodeobject codec v1: short full inner node, in_size = " +
162 istream is(p, in_size);
167 write<std::uint32_t>(os, 0);
168 write<std::uint32_t>(os, 0);
171 write(os, is(512), 512);
175 Throw<std::runtime_error>(
"nodeobject codec: bad type=" +
std::to_string(type));
193 using namespace nudb::detail;
198 istream is(
in, in_size);
203 read<std::uint32_t>(is, index);
204 read<std::uint32_t>(is, unused);
205 read<std::uint8_t>(is, kind);
206 read<std::uint32_t>(is, prefix);
212 for (
unsigned bit = 0x8000; bit; bit >>= 1)
214 void const*
const h = is(32);
225 auto const type = 2U;
227 result.
second = vs + field<std::uint16_t>::size +
232 write<varint>(os, type);
233 write<std::uint16_t>(os, mask);
234 write(os, vh.data(), n * 32);
238 auto const type = 3U;
240 result.
second = vs + n * 32;
244 write<varint>(os, type);
245 write(os, vh.data(), n * 32);
267 result.
second = vn + lzr.second;
271 Throw<std::logic_error>(
"nodeobject codec: unknown=" +
std::to_string(codecType));
284 using namespace nudb::detail;
289 istream is(
in, in_size);
294 read<std::uint32_t>(is, index);
295 read<std::uint32_t>(is, unused);
296 read<std::uint8_t>(is, kind);
297 read<std::uint32_t>(is, prefix);
301 write<std::uint32_t>(os, 0);
302 write<std::uint32_t>(os, 0);