| 601 | } |
| 602 | |
| 603 | Status WriteMessage(const Buffer& message, const IpcWriteOptions& options, |
| 604 | io::OutputStream* file, int32_t* message_length) { |
| 605 | const int32_t prefix_size = options.write_legacy_ipc_format ? 4 : 8; |
| 606 | const int32_t flatbuffer_size = static_cast<int32_t>(message.size()); |
| 607 | |
| 608 | int32_t padded_message_length = static_cast<int32_t>( |
| 609 | PaddedLength(flatbuffer_size + prefix_size, options.alignment)); |
| 610 | |
| 611 | int32_t padding = padded_message_length - flatbuffer_size - prefix_size; |
| 612 | |
| 613 | // The returned message size includes the length prefix, the flatbuffer, |
| 614 | // plus padding |
| 615 | *message_length = padded_message_length; |
| 616 | |
| 617 | // ARROW-6314: Write continuation / padding token |
| 618 | if (!options.write_legacy_ipc_format) { |
| 619 | RETURN_NOT_OK(file->Write(&internal::kIpcContinuationToken, sizeof(int32_t))); |
| 620 | } |
| 621 | |
| 622 | // Write the flatbuffer size prefix including padding in little endian |
| 623 | int32_t padded_flatbuffer_size = |
| 624 | bit_util::ToLittleEndian(padded_message_length - prefix_size); |
| 625 | RETURN_NOT_OK(file->Write(&padded_flatbuffer_size, sizeof(int32_t))); |
| 626 | |
| 627 | // Write the flatbuffer |
| 628 | RETURN_NOT_OK(file->Write(message.data(), flatbuffer_size)); |
| 629 | if (padding > 0) { |
| 630 | RETURN_NOT_OK(file->Write(kPaddingBytes, padding)); |
| 631 | } |
| 632 | |
| 633 | return Status::OK(); |
| 634 | } |
| 635 | |
| 636 | // ---------------------------------------------------------------------- |
| 637 | // Implement MessageDecoder |
no test coverage detected