paleolimbot commented on code in PR #585:
URL: https://github.com/apache/arrow-nanoarrow/pull/585#discussion_r1718693252
##########
src/nanoarrow/ipc/writer.c:
##########
@@ -329,3 +364,62 @@ ArrowErrorCode ArrowIpcWriterWriteArrayStream(struct
ArrowIpcWriter* writer,
ArrowArrayViewReset(&array_view);
return NANOARROW_OK;
}
+
+#define NANOARROW_IPC_FILE_PADDED_MAGIC "ARROW1\0"
+
+ArrowErrorCode ArrowIpcWriterStartFile(struct ArrowIpcWriter* writer,
+ struct ArrowError* error) {
+ NANOARROW_DCHECK(writer != NULL && writer->private_data != NULL);
+
+ struct ArrowIpcWriterPrivate* private =
+ (struct ArrowIpcWriterPrivate*)writer->private_data;
+
+ NANOARROW_DCHECK(!private->writing_file && private->bytes_written == 0);
+
+ struct ArrowBufferView magic = {
+ .data.data = NANOARROW_IPC_FILE_PADDED_MAGIC,
+ .size_bytes = sizeof(NANOARROW_IPC_FILE_PADDED_MAGIC),
+ };
+ NANOARROW_RETURN_NOT_OK(
+ ArrowIpcOutputStreamWrite(&private->output_stream, magic, error));
+
+ private->writing_file = 1;
+ private->bytes_written = magic.size_bytes;
+ return NANOARROW_OK;
+}
+
+ArrowErrorCode ArrowIpcWriterFinalizeFile(struct ArrowIpcWriter* writer,
+ struct ArrowError* error) {
+ NANOARROW_DCHECK(writer != NULL && writer->private_data != NULL);
+
+ struct ArrowIpcWriterPrivate* private =
+ (struct ArrowIpcWriterPrivate*)writer->private_data;
+
+ NANOARROW_DCHECK(private->writing_file);
+
+ NANOARROW_ASSERT_OK(ArrowBufferResize(&private->buffer, 0, 0));
+ NANOARROW_RETURN_NOT_OK(
+ ArrowIpcEncoderEncodeFooter(&private->encoder, &private->footer, error));
+ NANOARROW_RETURN_NOT_OK_WITH_ERROR(
+ ArrowIpcEncoderFinalizeBuffer(&private->encoder, /*encapsulate=*/0,
+ &private->buffer),
+ error);
+
+ _NANOARROW_CHECK_RANGE(private->buffer.size_bytes, 0, INT32_MAX);
+ int32_t size = (int32_t) private->buffer.size_bytes;
+ struct ArrowStringView magic =
ArrowCharView(NANOARROW_IPC_FILE_PADDED_MAGIC);
Review Comment:
I think a comment or `DCHECK(strlen(...) == 6)` or `ArrowBufferWrite()` with
explicit size would be helpful (to avoid somebody who is probably future me
thinking this is a mistake!)
--
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]