bkietz commented on code in PR #571: URL: https://github.com/apache/arrow-nanoarrow/pull/571#discussion_r1704473137
########## src/nanoarrow/ipc/writer.c: ########## @@ -150,3 +155,160 @@ ArrowErrorCode ArrowIpcOutputStreamInitFile(struct ArrowIpcOutputStream* stream, stream->private_data = private_data; return NANOARROW_OK; } + +struct ArrowIpcArrayStreamWriterPrivate { + struct ArrowArrayStream in; + struct ArrowIpcOutputStream output_stream; + struct ArrowIpcEncoder encoder; + struct ArrowSchema schema; + struct ArrowArray array; + struct ArrowArrayView array_view; + struct ArrowBuffer buffer; + struct ArrowBuffer body_buffer; + int64_t buffer_cursor; + int64_t body_buffer_cursor; +}; + +ArrowErrorCode ArrowIpcArrayStreamWriterInit(struct ArrowIpcArrayStreamWriter* writer, + struct ArrowArrayStream* in, + struct ArrowIpcOutputStream* output_stream) { + NANOARROW_DCHECK(writer != NULL && in != NULL && output_stream != NULL); + + struct ArrowIpcArrayStreamWriterPrivate* private = + (struct ArrowIpcArrayStreamWriterPrivate*)ArrowMalloc( + sizeof(struct ArrowIpcArrayStreamWriterPrivate)); + + if (private == NULL) { + return ENOMEM; + } + + NANOARROW_RETURN_NOT_OK(ArrowIpcEncoderInit(&private->encoder)); + ArrowIpcOutputStreamMove(output_stream, &private->output_stream); + ArrowArrayStreamMove(in, &private->in); + private->schema.release = NULL; + private->array.release = NULL; + ArrowArrayViewInitFromType(&private->array_view, NANOARROW_TYPE_UNINITIALIZED); + ArrowBufferInit(&private->buffer); + ArrowBufferInit(&private->body_buffer); + private->buffer_cursor = 0; + private->body_buffer_cursor = 0; + // It'd probably be better to push directly from encode_buffer to the output_stream Review Comment: On reflection I'm not sure this is actually reasonable; we need the Message to precede encoded body buffers and we're not done building the Message when we need to encode buffers so we can't push them into the stream yet. We could potentially add reservation and rewinding to the output stream to enable cases like this but a) that'd be pretty complicated b) I'm not sure we'd gain much. Writing the Message directly to the output stream would require some major shenanigans with flatcc's emitters; not sure if that's feasible either. -- 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: github-unsubscr...@arrow.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org