Phoenix500526 commented on code in PR #10277:
URL: https://github.com/apache/arrow-rs/pull/10277#discussion_r3651644583


##########
arrow-ipc/src/writer.rs:
##########
@@ -135,6 +135,226 @@ impl<'a> IpcBodySink<'a> {
     }
 }
 
+struct MetadataLayout {
+    padded_header_len: usize,
+    padded_metadata_len: usize,
+    metadata_padding: usize,
+}
+
+#[inline]
+fn metadata_layout(metadata_len: usize, write_options: &IpcWriteOptions) -> 
MetadataLayout {
+    let prefix_size = if write_options.write_legacy_ipc_format {
+        4
+    } else {
+        8
+    };
+    let alignment_mask = usize::from(write_options.alignment - 1);
+    let padded_header_len = (metadata_len + prefix_size + alignment_mask) & 
!alignment_mask;
+    let padded_metadata_len = padded_header_len - prefix_size;
+    let metadata_padding = padded_metadata_len - metadata_len;
+
+    MetadataLayout {
+        padded_header_len,
+        padded_metadata_len,
+        metadata_padding,
+    }
+}
+
+/// Destination for a complete framed IPC message.
+///
+/// This emits the stream/file framing around the serialized FlatBuffer
+/// [`crate::Message`] metadata plus its optional body buffers.
+trait IpcMessageSink {
+    fn write_slice(&mut self, bytes: &[u8]) -> Result<(), ArrowError>;
+
+    fn write_vec(&mut self, bytes: Vec<u8>) -> Result<(), ArrowError> {
+        self.write_slice(&bytes)
+    }
+
+    fn write_encoded_buffer(&mut self, buffer: EncodedBuffer) -> Result<(), 
ArrowError> {
+        self.write_slice(buffer.as_slice())
+    }
+
+    fn write_padding(&mut self, len: usize) -> Result<(), ArrowError> {
+        self.write_slice(&PADDING[..len])
+    }
+
+    /// Writes the IPC continuation marker and metadata length prefix.
+    fn write_continuation(

Review Comment:
   Done



-- 
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]

Reply via email to