MCPcopy Create free account
hub / github.com/apache/arrow / DecompressBuffer

Function DecompressBuffer

cpp/src/arrow/ipc/reader.cc:558–593  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

556};
557
558Result<std::shared_ptr<Buffer>> DecompressBuffer(const std::shared_ptr<Buffer>& buf,
559 const IpcReadOptions& options,
560 util::Codec* codec) {
561 if (buf == nullptr || buf->size() == 0) {
562 return buf;
563 }
564
565 if (buf->size() < 8) {
566 return Status::Invalid(
567 "Likely corrupted message, compressed buffers "
568 "are larger than 8 bytes by construction");
569 }
570
571 const uint8_t* data = buf->data();
572 int64_t compressed_size = buf->size() - sizeof(int64_t);
573 int64_t uncompressed_size = bit_util::FromLittleEndian(util::SafeLoadAs<int64_t>(data));
574
575 if (uncompressed_size == -1) {
576 return SliceBuffer(buf, sizeof(int64_t), compressed_size);
577 }
578
579 ARROW_ASSIGN_OR_RAISE(auto uncompressed,
580 AllocateBuffer(uncompressed_size, options.memory_pool));
581
582 ARROW_ASSIGN_OR_RAISE(
583 int64_t actual_decompressed,
584 codec->Decompress(compressed_size, data + sizeof(int64_t), uncompressed_size,
585 uncompressed->mutable_data()));
586 if (actual_decompressed != uncompressed_size) {
587 return Status::Invalid("Failed to fully decompress buffer, expected ",
588 uncompressed_size, " bytes but decompressed ",
589 actual_decompressed);
590 }
591
592 return uncompressed;
593}
594
595Status DecompressBuffers(Compression::type compression, const IpcReadOptions& options,
596 ArrayDataVector* fields) {

Callers 1

DecompressBuffersFunction · 0.85

Calls 5

SliceBufferFunction · 0.85
InvalidFunction · 0.50
FromLittleEndianFunction · 0.50
sizeMethod · 0.45
dataMethod · 0.45

Tested by

no test coverage detected