MCPcopy Create free account
hub / github.com/apache/arrow-rs / write_buffer

Function write_buffer

arrow-ipc/src/writer.rs:2116–2144  ·  view source on GitHub ↗

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,             

Source from the content-addressed store, hash-verified

2114/// follows is not compressed, which can be useful for cases where
2115/// compression does not yield appreciable savings.
2116fn 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
2146const PADDING: [u8; 64] = [0; 64];
2147

Callers 1

write_array_dataFunction · 0.85

Calls 5

pad_to_alignmentFunction · 0.85
compress_to_vecMethod · 0.80
extend_from_sliceMethod · 0.80
lenMethod · 0.45
pushMethod · 0.45

Tested by

no test coverage detected