fresh-borzoni commented on code in PR #639:
URL: https://github.com/apache/fluss-rust/pull/639#discussion_r3473445595


##########
crates/fluss/src/record/arrow.rs:
##########
@@ -990,38 +1001,79 @@ impl LogRecordBatch {
         LittleEndian::read_i32(&self.data[offset..offset + 
RECORDS_COUNT_LENGTH])
     }
 
+    /// Splits the batch body into its per-record change types and the trailing
+    /// Arrow IPC payload (see [`APPEND_ONLY_FLAG_MASK`] for the layout).
+    fn decode_change_types(&self) -> Result<(BatchChangeTypes, &[u8])> {
+        let body = self
+            .data
+            .get(RECORDS_OFFSET..)
+            .ok_or_else(|| Error::UnexpectedError {
+                message: format!(
+                    "Corrupt log record batch: data length {} is less than 
RECORDS_OFFSET {}",
+                    self.data.len(),
+                    RECORDS_OFFSET
+                ),
+                source: None,
+            })?;
+
+        if self.is_append_only() {
+            return Ok((BatchChangeTypes::Uniform(ChangeType::AppendOnly), 
body));
+        }
+
+        let record_count = self.record_count() as usize;
+        let (change_type_bytes, arrow_data) =
+            body.split_at_checked(record_count)
+                .ok_or_else(|| Error::UnexpectedError {
+                    message: format!(
+                        "Corrupt changelog batch: body length {} is smaller 
than its \
+                         {record_count}-record change-type vector",
+                        body.len()
+                    ),
+                    source: None,
+                })?;

Review Comment:
   split_at_checked already bounds this before the allocation, I added a guard 
for a clearer error anyway 😒 



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