JakeDern commented on code in PR #10128:
URL: https://github.com/apache/arrow-rs/pull/10128#discussion_r3653671990
##########
arrow-ipc/src/writer.rs:
##########
@@ -1836,41 +1885,56 @@ pub fn write_message<W: Write>(
));
}
+ let aligned_size = write_message_header(&mut writer, &encoded.ipc_message,
write_options)?;
+
+ // write arrow data
+ let body_len = if arrow_data_len > 0 {
+ write_body_buffer(&mut writer, &encoded.arrow_data,
write_options.alignment)?
+ } else {
+ 0
+ };
+
+ Ok((aligned_size, body_len))
+}
+
+/// Write the encapsulated-message header to `writer`: the continuation marker
and
+/// metadata length, the flatbuffer metadata (`ipc_message`), and the alignment
+/// padding that follows it.
+///
+/// Returns the padded header length (continuation prefix + metadata +
padding),
+/// which is also the value encoded in the continuation length field.
+fn write_message_header<W: Write>(
+ writer: &mut W,
+ ipc_message: &[u8],
+ write_options: &IpcWriteOptions,
+) -> Result<usize, ArrowError> {
let a = usize::from(write_options.alignment - 1);
- let buffer = encoded.ipc_message;
- let flatbuf_size = buffer.len();
+ let flatbuf_size = ipc_message.len();
let prefix_size = if write_options.write_legacy_ipc_format {
4
} else {
8
};
let aligned_size = (flatbuf_size + prefix_size + a) & !a;
- let padding_bytes = aligned_size - flatbuf_size - prefix_size;
- write_continuation(
- &mut writer,
+ write_continuation_and_meta_size(
+ &mut *writer,
write_options,
(aligned_size - prefix_size) as i32,
)?;
// write the flatbuf
if flatbuf_size > 0 {
- writer.write_all(&buffer)?;
+ writer.write_all(ipc_message)?;
}
- // write padding
- writer.write_all(&PADDING[..padding_bytes])?;
- // write arrow data
- let body_len = if arrow_data_len > 0 {
- write_body_buffers(&mut writer, &encoded.arrow_data,
write_options.alignment)?
- } else {
- 0
- };
+ // write padding
+ writer.write_all(&PADDING[..aligned_size - flatbuf_size - prefix_size])?;
- Ok((aligned_size, body_len))
+ Ok(aligned_size)
}
-fn write_body_buffers<W: Write>(
+fn write_body_buffer<W: Write>(
Review Comment:
Reverted the name change for now
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]