1 // Copyright (c) 2007-2013 Hartmut Kaiser 2 // Copyright (c) 2014 Thomas Heller 3 // 4 // Distributed under the Boost Software License, Version 1.0. (See accompanying 5 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 6 7 #ifndef HPX_SERIALIZATION_SERIALIZATION_CHUNK_HPP 8 #define HPX_SERIALIZATION_SERIALIZATION_CHUNK_HPP 9 10 #include <hpx/config.hpp> 11 12 #include <climits> 13 #include <cstddef> 14 #include <cstdint> 15 #include <cstring> 16 17 #if CHAR_BIT != 8 18 # error This code assumes an eight-bit byte. 19 #endif 20 21 namespace hpx { namespace serialization 22 { 23 /////////////////////////////////////////////////////////////////////// 24 union chunk_data 25 { 26 std::size_t index_; // position inside the data buffer //-V117 27 void const* cpos_; // const pointer to external data buffer //-V117 28 void* pos_; // pointer to external data buffer //-V117 29 }; 30 31 enum chunk_type 32 { 33 chunk_type_index = 0, 34 chunk_type_pointer = 1 35 }; 36 37 struct serialization_chunk 38 { 39 chunk_data data_; // index or pointer 40 std::size_t size_; // size of the serialization_chunk starting index_/pos_ 41 std::uint64_t rkey_; // optional RDMA remote key for parcelport put/get 42 // operations 43 std::uint8_t type_; // chunk_type 44 }; 45 46 /////////////////////////////////////////////////////////////////////// create_index_chunk(std::size_t index,std::size_t size)47 inline serialization_chunk create_index_chunk(std::size_t index, std::size_t size) 48 { 49 serialization_chunk retval = { 50 { 0 }, size, 0, static_cast<std::uint8_t>(chunk_type_index) 51 }; 52 retval.data_.index_ = index; 53 return retval; 54 } 55 create_pointer_chunk(void const * pos,std::size_t size,std::uint64_t rkey=0)56 inline serialization_chunk create_pointer_chunk( 57 void const* pos, std::size_t size, std::uint64_t rkey=0) 58 { 59 serialization_chunk retval = { 60 { 0 }, size, rkey, static_cast<std::uint8_t>(chunk_type_pointer) 61 }; 62 retval.data_.cpos_ = pos; 63 return retval; 64 } 65 66 }} 67 68 #endif 69