| 783 | } // namespace |
| 784 | |
| 785 | Status WriteIpcPayload(const IpcPayload& payload, const IpcWriteOptions& options, |
| 786 | io::OutputStream* dst, int32_t* metadata_length) { |
| 787 | RETURN_NOT_OK(WriteMessage(*payload.metadata, options, dst, metadata_length)); |
| 788 | |
| 789 | #ifndef NDEBUG |
| 790 | RETURN_NOT_OK(CheckAligned(dst)); |
| 791 | #endif |
| 792 | |
| 793 | // Now write the buffers |
| 794 | for (size_t i = 0; i < payload.body_buffers.size(); ++i) { |
| 795 | const std::shared_ptr<Buffer>& buffer = payload.body_buffers[i]; |
| 796 | int64_t size = 0; |
| 797 | int64_t padding = 0; |
| 798 | |
| 799 | // The buffer might be null if we are handling zero row lengths. |
| 800 | if (buffer) { |
| 801 | size = buffer->size(); |
| 802 | padding = bit_util::RoundUpToMultipleOf8(size) - size; |
| 803 | } |
| 804 | |
| 805 | if (size > 0) { |
| 806 | RETURN_NOT_OK(dst->Write(buffer)); |
| 807 | } |
| 808 | |
| 809 | if (padding > 0) { |
| 810 | RETURN_NOT_OK(dst->Write(kPaddingBytes, padding)); |
| 811 | } |
| 812 | } |
| 813 | |
| 814 | #ifndef NDEBUG |
| 815 | RETURN_NOT_OK(CheckAligned(dst)); |
| 816 | #endif |
| 817 | |
| 818 | return Status::OK(); |
| 819 | } |
| 820 | |
| 821 | Status GetSchemaPayload(const Schema& schema, const IpcWriteOptions& options, |
| 822 | const DictionaryFieldMapper& mapper, IpcPayload* out) { |