10 #include <rapidsmpf/communicator/communicator.hpp>
11 #include <rapidsmpf/memory/buffer.hpp>
12 #include <rapidsmpf/memory/buffer_resource.hpp>
13 #include <rapidsmpf/memory/packed_data.hpp>
89 +
sizeof(std::uint32_t) +
sizeof(std::uint64_t);
117 return expected_num_chunks_;
137 return metadata_size_;
156 RAPIDSMPF_EXPECTS(!data_,
"buffer is already set");
157 data_ = std::move(data);
166 return data_ !=
nullptr;
175 return metadata_ !=
nullptr && !metadata_->empty();
184 RAPIDSMPF_EXPECTS(data_,
"data buffer is not set");
185 return data_->mem_type();
194 return std::move(metadata_);
203 return std::move(data_);
244 std::vector<std::uint8_t>
const& msg,
BufferResource* br,
bool validate =
true
267 return data_size_ == 0 || (data_ && data_->is_latest_write_done());
275 [[nodiscard]] std::string
str()
const;
282 [[nodiscard]] std::unique_ptr<std::vector<std::uint8_t>>
serialize()
const;
292 std::unique_ptr<std::vector<std::uint8_t>> metadata =
nullptr,
293 std::unique_ptr<Buffer> data =
nullptr
299 expected_num_chunks_;
300 std::uint32_t metadata_size_;
301 std::uint64_t data_size_;
304 std::unique_ptr<std::vector<std::uint8_t>> metadata_;
307 std::unique_ptr<Buffer> data_;
Class managing buffer resources.
A partition chunk representing either a data message or a control message.
void set_data_buffer(std::unique_ptr< Buffer > data)
Set the data buffer.
static constexpr std::size_t metadata_message_header_size()
The size of the metadata message header.
constexpr PartID part_id() const
Partition ID of the message.
std::unique_ptr< std::vector< std::uint8_t > > serialize() const
Returns a metadata message that represents this chunk.
bool is_metadata_buffer_set() const
Whether the metadata buffer is set.
std::unique_ptr< std::vector< std::uint8_t > > release_metadata_buffer()
Release the ownership of the metadata buffer.
constexpr std::size_t expected_num_chunks() const
The expected number of chunks for the message.
Chunk & operator=(Chunk &&other) noexcept=default
move assignment operator
Chunk(Chunk &&other) noexcept=default
move constructor
static Chunk from_packed_data(ChunkID chunk_id, PartID part_id, PackedData &&packed_data)
Create a chunk from a packed data.
constexpr bool is_control_message() const
Whether the message is a control message.
static bool validate_format(std::vector< std::uint8_t > const &serialized_buf)
Validate if a deserialized buffer follows the Chunk format.
static Chunk deserialize(std::vector< std::uint8_t > const &msg, BufferResource *br, bool validate=true)
Create a chunk by deserializing a metadata message.
static Chunk from_finished_partition(ChunkID chunk_id, PartID part_id, std::size_t expected_num_chunks)
Create a chunk for a finished partition (control message).
constexpr std::uint32_t metadata_size() const
Get the size of the metadata of the message.
bool is_ready() const
Whether the chunk is ready for consumption.
MemoryType data_memory_type() const
Get the memory type of the data buffer.
constexpr std::size_t data_size() const
Get the size of the packed data of the message.
bool is_data_buffer_set() const
Whether the data buffer is set.
constexpr ChunkID chunk_id() const
The ID of the chunk.
std::string str() const
Returns a description of this chunk.
std::unique_ptr< Buffer > release_data_buffer()
Release the ownership of the data buffer.
std::ostream & operator<<(std::ostream &os, Chunk const &obj)
Overloads the stream insertion operator for the Chunk class.
std::uint64_t ChunkID
The globally unique ID of a chunk.
std::uint32_t PartID
Partition ID, which goes from 0 to the total number of partitions.
MemoryType
Enum representing the type of memory sorted in decreasing order of preference.
Bag of bytes with metadata suitable for sending over the wire.