Replace the bytes of Data[Offset :] by Slice[Start : Start + Length - 1]
| 155 | |
| 156 | /// Replace the bytes of Data[Offset :] by Slice[Start : Start + Length - 1] |
| 157 | Expect<void> setBytes(Span<const Byte> Slice, const uint64_t Offset, |
| 158 | const uint64_t Start, const uint64_t Length) noexcept { |
| 159 | // Check the memory boundary. |
| 160 | if (unlikely(!checkAccessBound(Offset, Length))) { |
| 161 | spdlog::error(ErrCode::Value::MemoryOutOfBounds); |
| 162 | spdlog::error(ErrInfo::InfoBoundary(Offset, Length, getSize())); |
| 163 | return Unexpect(ErrCode::Value::MemoryOutOfBounds); |
| 164 | } |
| 165 | |
| 166 | // Check the input data validation. |
| 167 | if (unlikely(std::numeric_limits<uint64_t>::max() - Start < Length || |
| 168 | Start + Length > static_cast<uint64_t>(Slice.size()))) { |
| 169 | spdlog::error(ErrCode::Value::MemoryOutOfBounds); |
| 170 | spdlog::error(ErrInfo::InfoBoundary(Start, Length, |
| 171 | static_cast<uint64_t>(Slice.size()))); |
| 172 | return Unexpect(ErrCode::Value::MemoryOutOfBounds); |
| 173 | } |
| 174 | |
| 175 | // Copy the data. |
| 176 | if (likely(Length > 0)) { |
| 177 | std::copy(Slice.begin() + Start, Slice.begin() + Start + Length, |
| 178 | DataPtr + Offset); |
| 179 | } |
| 180 | return {}; |
| 181 | } |
| 182 | |
| 183 | /// Fill the bytes of Data[Offset : Offset + Length - 1] by Val. |
| 184 | Expect<void> fillBytes(const uint8_t Val, const uint64_t Offset, |
no test coverage detected