paleolimbot commented on code in PR #924:
URL: https://github.com/apache/arrow-nanoarrow/pull/924#discussion_r3809627264


##########
src/nanoarrow/ipc/decoder.c:
##########
@@ -1692,6 +1711,70 @@ ArrowErrorCode ArrowIpcDecoderDecodeHeader(struct 
ArrowIpcDecoder* decoder,
   }
 
   private_data->last_message = message_header;
+  private_data->last_message_metadata = ns(Message_custom_metadata(message));
+  return NANOARROW_OK;
+}
+
+ArrowErrorCode ArrowIpcDecoderGetMessageMetadata(struct ArrowIpcDecoder* 
decoder,
+                                                 struct ArrowBuffer* out,
+                                                 struct ArrowError* error) {
+  NANOARROW_DCHECK(decoder != NULL && decoder->private_data != NULL && out != 
NULL);
+  struct ArrowIpcDecoderPrivate* private_data =
+      (struct ArrowIpcDecoderPrivate*)decoder->private_data;
+
+  return ArrowIpcDecoderBuildMetadata(private_data->last_message_metadata, 
out, error);
+}
+
+ArrowErrorCode ArrowIpcDecoderGetMessageMetadataValue(struct ArrowIpcDecoder* 
decoder,
+                                                      struct ArrowStringView 
key,
+                                                      struct ArrowStringView* 
value_out,
+                                                      struct ArrowError* 
error) {

Review Comment:
   Optional (since iterating over flatbuffers keyvalue metadata isn't that 
hard), but these could be written in terms of 
`ArrowIpcDecoderVisitMessageMetadata()` to consolidate the iteration.



##########
src/nanoarrow/nanoarrow_ipc.h:
##########
@@ -778,6 +842,23 @@ NANOARROW_DLL void ArrowIpcEncoderReset(struct 
ArrowIpcEncoder* encoder);
 NANOARROW_DLL ArrowErrorCode ArrowIpcEncoderFinalizeBuffer(
     struct ArrowIpcEncoder* encoder, char encapsulate, struct ArrowBuffer* 
out);
 
+/// \brief Set the custom metadata of the next encoded message
+///
+/// Attaches metadata to the next message encoded by 
ArrowIpcEncoderEncodeSchema() or
+/// ArrowIpcEncoderEncodeSimpleRecordBatch() (i.e., Message::custom_metadata, 
which is
+/// distinct from the metadata of the Schema or Field that the message may 
contain).
+/// The metadata applies to exactly one message: after a message is encoded the
+/// encoder's message metadata is cleared. Any metadata that was set but not 
yet
+/// encoded is replaced by this call; pass NULL to clear it.
+///
+/// metadata uses the same representation as ArrowSchema::metadata and may be 
built
+/// with ArrowMetadataBuilderInit()/ArrowMetadataBuilderAppend(). It is copied 
by this
+/// call and need not outlive it.
+///
+/// Returns ENOMEM if allocation fails, NANOARROW_OK otherwise.
+NANOARROW_DLL ArrowErrorCode ArrowIpcEncoderSetMessageMetadata(
+    struct ArrowIpcEncoder* encoder, const char* metadata, struct ArrowError* 
error);

Review Comment:
   I think it makes sense for `metadata` here to be an `ArrowBuffer`, since the 
caller probably just built one and there's no need to copy.



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