Skip to content

Commit 419e7ef

Browse files
committed
Add DecodeWithContext to LZFSETransform.
1 parent 7cb0094 commit 419e7ef

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

view/kernelcache/core/transformers/KernelCacheTransforms.cpp

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,40 @@ class LZFSETransform : public Transform
248248
return false;
249249
}
250250

251+
252+
virtual bool DecodeWithContext(Ref<TransformContext> context, const std::map<std::string, DataBuffer>& params) override
253+
{
254+
if (!context || !context->GetInput())
255+
return false;
256+
257+
const uint8_t* dataPtr = context->GetInput()->GetDataPointer();
258+
size_t dataLength = context->GetInput()->GetDataLength();
259+
if (!dataPtr || !dataLength)
260+
return false;
261+
262+
size_t outputBufferSize = dataLength * 6;
263+
std::unique_ptr<uint8_t[]> scratchBuffer(new uint8_t[lzfse_decode_scratch_size()]);
264+
while (true)
265+
{
266+
DataBuffer output(outputBufferSize);
267+
size_t outSize = lzfse_decode_buffer((uint8_t *)output.GetData(), outputBufferSize, (uint8_t *)dataPtr, dataLength, scratchBuffer.get());
268+
if (!outSize)
269+
return false;
270+
if ((outSize > 0) && (outSize < outputBufferSize))
271+
{
272+
output.SetSize(outSize);
273+
context->SetChild(output, "");
274+
return true;
275+
}
276+
if (output.GetLength() > (size_t(1) << 33)) // 8GB max
277+
return false;
278+
outputBufferSize *= 2;
279+
}
280+
281+
return false;
282+
}
283+
284+
251285
virtual bool Encode(const DataBuffer& input, DataBuffer& output, const std::map<std::string, DataBuffer>&) override
252286
{
253287
size_t outputBufferSize = input.GetLength() + (input.GetLength() / 16) + 64;

0 commit comments

Comments
 (0)