[ 
https://issues.apache.org/jira/browse/ARROW-2027?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16361466#comment-16361466
 ] 

ASF GitHub Bot commented on ARROW-2027:
---------------------------------------

xuepanchen closed pull request #1598: ARROW-2027: [C++] Add padding when 
writing message body in ipc::Message::SerializeTo
URL: https://github.com/apache/arrow/pull/1598
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/cpp/src/arrow/ipc/message.cc b/cpp/src/arrow/ipc/message.cc
index 1835cefde..448c0e7ec 100644
--- a/cpp/src/arrow/ipc/message.cc
+++ b/cpp/src/arrow/ipc/message.cc
@@ -28,6 +28,7 @@
 #include "arrow/ipc/Message_generated.h"
 #include "arrow/ipc/Schema_generated.h"
 #include "arrow/ipc/metadata-internal.h"
+#include "arrow/ipc/util.h"
 #include "arrow/status.h"
 #include "arrow/util/logging.h"
 
@@ -154,15 +155,33 @@ Status Message::ReadFrom(const std::shared_ptr<Buffer>& 
metadata, io::InputStrea
 Status Message::SerializeTo(io::OutputStream* file, int64_t* output_length) 
const {
   int32_t metadata_length = 0;
   RETURN_NOT_OK(internal::WriteMessage(*metadata(), file, &metadata_length));
-
   *output_length = metadata_length;
 
+#ifndef NDEBUG
+  int64_t current_position = -1;
+  RETURN_NOT_OK(file->Tell(&current_position));
+  DCHECK(BitUtil::IsMultipleOf8(current_position));
+#endif
+
   auto body_buffer = body();
   if (body_buffer) {
-    RETURN_NOT_OK(file->Write(body_buffer->data(), body_buffer->size()));
-    *output_length += body_buffer->size();
+    int64_t size = body_buffer->size();
+    int64_t padding = BitUtil::RoundUpToMultipleOf8(size) - size;
+
+    RETURN_NOT_OK(file->Write(body_buffer->data(), size));
+    *output_length += size;
+
+    if (padding > 0) {
+      RETURN_NOT_OK(file->Write(kPaddingBytes, padding));
+      *output_length += padding;
+    }
   }
 
+#ifndef NDEBUG
+  RETURN_NOT_OK(file->Tell(&current_position));
+  DCHECK(BitUtil::IsMultipleOf8(current_position));
+#endif
+
   return Status::OK();
 }
 


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


> [C++] ipc::Message::SerializeTo does not pad the message body
> -------------------------------------------------------------
>
>                 Key: ARROW-2027
>                 URL: https://issues.apache.org/jira/browse/ARROW-2027
>             Project: Apache Arrow
>          Issue Type: Bug
>          Components: C++
>            Reporter: Wes McKinney
>            Assignee: Panchen Xue
>            Priority: Major
>              Labels: pull-request-available
>             Fix For: 0.9.0
>
>
> I just want to note this here as a follow-up to ARROW-1860. I think that 
> padding is the correct behavior, but I wasn't sure enough to make the fix 
> there



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to