| 42 | class SnappyCodec : public Codec { |
| 43 | public: |
| 44 | Result<int64_t> Decompress(int64_t input_len, const uint8_t* input, |
| 45 | int64_t output_buffer_len, uint8_t* output_buffer) override { |
| 46 | size_t decompressed_size; |
| 47 | if (!snappy::GetUncompressedLength(reinterpret_cast<const char*>(input), |
| 48 | static_cast<size_t>(input_len), |
| 49 | &decompressed_size)) { |
| 50 | return Status::IOError("Corrupt snappy compressed data."); |
| 51 | } |
| 52 | if (output_buffer_len < static_cast<int64_t>(decompressed_size)) { |
| 53 | return Status::Invalid("Output buffer size (", output_buffer_len, ") must be ", |
| 54 | decompressed_size, " or larger."); |
| 55 | } |
| 56 | if (!snappy::RawUncompress(reinterpret_cast<const char*>(input), |
| 57 | static_cast<size_t>(input_len), |
| 58 | reinterpret_cast<char*>(output_buffer))) { |
| 59 | return Status::IOError("Corrupt snappy compressed data."); |
| 60 | } |
| 61 | return static_cast<int64_t>(decompressed_size); |
| 62 | } |
| 63 | |
| 64 | int64_t MaxCompressedLen(int64_t input_len, |
| 65 | const uint8_t* ARROW_ARG_UNUSED(input)) override { |