Write a buffer into `arrow_data`, a vector of bytes, and adds its [`crate::Buffer`] to `buffers`. Returns the new offset in `arrow_data` From Each constituent buffer is first compressed with the indicated compressor, and then written with the uncompressed length in the first 8 bytes as a 64-bit
(
buffer: &[u8], // input
buffers: &mut Vec<crate::Buffer>, // output buffer descriptors
arrow_data: &mut Vec<u8>, // output stream
offset: i64,
| 2114 | /// follows is not compressed, which can be useful for cases where |
| 2115 | /// compression does not yield appreciable savings. |
| 2116 | fn write_buffer( |
| 2117 | buffer: &[u8], // input |
| 2118 | buffers: &mut Vec<crate::Buffer>, // output buffer descriptors |
| 2119 | arrow_data: &mut Vec<u8>, // output stream |
| 2120 | offset: i64, // current output stream offset |
| 2121 | compression_codec: Option<CompressionCodec>, |
| 2122 | compression_context: &mut CompressionContext, |
| 2123 | alignment: u8, |
| 2124 | ) -> Result<i64, ArrowError> { |
| 2125 | let len: i64 = match compression_codec { |
| 2126 | Some(compressor) => compressor.compress_to_vec(buffer, arrow_data, compression_context)?, |
| 2127 | None => { |
| 2128 | arrow_data.extend_from_slice(buffer); |
| 2129 | buffer.len() |
| 2130 | } |
| 2131 | } |
| 2132 | .try_into() |
| 2133 | .map_err(|e| { |
| 2134 | ArrowError::InvalidArgumentError(format!("Could not convert compressed size to i64: {e}")) |
| 2135 | })?; |
| 2136 | |
| 2137 | // make new index entry |
| 2138 | buffers.push(crate::Buffer::new(offset, len)); |
| 2139 | // padding and make offset aligned |
| 2140 | let pad_len = pad_to_alignment(alignment, len as usize); |
| 2141 | arrow_data.extend_from_slice(&PADDING[..pad_len]); |
| 2142 | |
| 2143 | Ok(offset + len + (pad_len as i64)) |
| 2144 | } |
| 2145 | |
| 2146 | const PADDING: [u8; 64] = [0; 64]; |
| 2147 |
no test coverage detected