MXL : Media eXchange Layer
MXL
Loading...
Searching...
No Matches
SliceRange.cpp
Go to the documentation of this file.
1// SPDX-FileCopyrightText: 2026 Contributors to the Media eXchange Layer project.
2//
3// SPDX-License-Identifier: Apache-2.0
4
5#include "SliceRange.hpp"
6#include "Exception.hpp"
7
9{
10 SliceRange SliceRange::make(std::uint16_t start, std::uint16_t end)
11 {
12 if (start > end)
13 {
14 throw Exception::invalidArgument("Invalid SliceRange: start must be less or equal to end");
15 }
16
17 return SliceRange{start, end};
18 }
19
20 std::uint32_t SliceRange::transferSize(std::uint32_t sliceSize) const noexcept
21 {
22 return ((_end - _start) * sliceSize);
23 }
24
25 std::uint32_t SliceRange::transferOffset(std::uint32_t payloadOffset, std::uint32_t sliceSize) const noexcept
26 {
27 return payloadOffset + (_start * sliceSize);
28 }
29
30 std::uint16_t SliceRange::start() const noexcept
31 {
32 return _start;
33 }
34
35 std::uint16_t SliceRange::end() const noexcept
36 {
37 return _end;
38 }
39}
static Exception invalidArgument(fmt::format_string< T... > fmt, T &&... args)
Make an MXL_ERR_INVALID_ARG exception.
Definition Exception.hpp:43
SliceRange(std::uint16_t start, std::uint16_t end) noexcept
std::uint32_t transferSize(std::uint32_t sliceSize) const noexcept
Get the size of the range (end - start).
std::uint32_t transferOffset(std::uint32_t payloadOffset, std::uint32_t sliceSize) const noexcept
Get the offset within the payload for the start of the range.
std::uint16_t end() const noexcept
Get the exclusive end of the range.
std::uint16_t start() const noexcept
Get the inclusive start of the range.
static SliceRange make(std::uint16_t start, std::uint16_t end)
Create a SliceRange representing the range [start, end).