* @brief Writes the given object in the given buffer at the given offset. * Returns the new offset end of the written data. * * @param o Object. * @param bytes Buffer to write. * @param offset Offset to write at. * @return int64_t The new offset. */
| 50 | * @return int64_t The new offset. |
| 51 | */ |
| 52 | inline static int64_t write(const T& o, buffer_t& bytes, int64_t offset) |
| 53 | { |
| 54 | if constexpr (impl::has_output_size_member_function_v<serializable<T>>) { |
| 55 | auto size = serializable<T>::output_size(o); |
| 56 | bytes.resize(std::max(offset + size, static_cast<int64_t>(bytes.size()))); |
| 57 | serializable<T>::write(o, bytes, offset); |
| 58 | return offset + size; |
| 59 | } else { |
| 60 | auto buf = serializable<T>::write(o); |
| 61 | bytes.insert(bytes.begin() + offset, std::make_move_iterator(buf.begin()), |
| 62 | std::make_move_iterator(buf.end())); |
| 63 | return offset + buf.size(); |
| 64 | } |
| 65 | } |
| 66 | }; |
| 67 | |
| 68 | template <typename T> |