iceoryx_posh 2.0.3
chunk_settings.hpp
1// Copyright (c) 2021 by Apex.AI Inc. All rights reserved.
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14//
15// SPDX-License-Identifier: Apache-2.0
16
17#ifndef IOX_POSH_MEPOO_CHUNK_SETTINGS_HPP
18#define IOX_POSH_MEPOO_CHUNK_SETTINGS_HPP
19
20#include "iceoryx_hoofs/cxx/expected.hpp"
21#include "iceoryx_posh/iceoryx_posh_types.hpp"
22
23#include <cstdint>
24
25namespace iox
26{
27namespace mepoo
28{
30{
31 public:
32 enum class Error
33 {
34 ALIGNMENT_NOT_POWER_OF_TWO,
35 USER_HEADER_ALIGNMENT_EXCEEDS_CHUNK_HEADER_ALIGNMENT,
36 USER_HEADER_SIZE_NOT_MULTIPLE_OF_ITS_ALIGNMENT,
37 REQUIRED_CHUNK_SIZE_EXCEEDS_MAX_CHUNK_SIZE,
38 };
39
46 static cxx::expected<ChunkSettings, ChunkSettings::Error>
47 create(const uint32_t userPayloadSize,
48 const uint32_t userPayloadAlignment = iox::CHUNK_DEFAULT_USER_PAYLOAD_ALIGNMENT,
49 const uint32_t userHeaderSize = iox::CHUNK_NO_USER_HEADER_SIZE,
50 const uint32_t userHeaderAlignment = iox::CHUNK_NO_USER_HEADER_ALIGNMENT) noexcept;
51
54 uint32_t requiredChunkSize() const noexcept;
55
58 uint32_t userPayloadSize() const noexcept;
59
62 uint32_t userPayloadAlignment() const noexcept;
63
66 uint32_t userHeaderSize() const noexcept;
67
70 uint32_t userHeaderAlignment() const noexcept;
71
72 private:
73 ChunkSettings(const uint32_t userPayloadSize,
74 const uint32_t userPayloadAlignment,
75 const uint32_t userHeaderSize,
76 const uint32_t userHeaderAlignment,
77 const uint32_t requiredChunkSize) noexcept;
78
79 static uint64_t calculateRequiredChunkSize(const uint32_t userPayloadSize,
80 const uint32_t userPayloadAlignment,
81 const uint32_t userHeaderSize) noexcept;
82
83 private:
84 uint32_t m_userPayloadSize{0U};
85 uint32_t m_userPayloadAlignment{0U};
86 uint32_t m_userHeaderSize{0U};
87 uint32_t m_userHeaderAlignment{0U};
88 uint32_t m_requiredChunkSize{0U};
89};
90
91} // namespace mepoo
92} // namespace iox
93
94#endif // IOX_POSH_MEPOO_CHUNK_SETTINGS_HPP
Definition: chunk_settings.hpp:30
uint32_t userHeaderAlignment() const noexcept
getter method for the user-header alignment
static cxx::expected< ChunkSettings, ChunkSettings::Error > create(const uint32_t userPayloadSize, const uint32_t userPayloadAlignment=iox::CHUNK_DEFAULT_USER_PAYLOAD_ALIGNMENT, const uint32_t userHeaderSize=iox::CHUNK_NO_USER_HEADER_SIZE, const uint32_t userHeaderAlignment=iox::CHUNK_NO_USER_HEADER_ALIGNMENT) noexcept
constructs and initializes a ChunkSettings
uint32_t userHeaderSize() const noexcept
getter method for the user-header size
uint32_t userPayloadSize() const noexcept
getter method for the user-payload size
uint32_t userPayloadAlignment() const noexcept
getter method for the user-payload alignment
uint32_t requiredChunkSize() const noexcept
getter method for the chunk size fulfilling the user-payload and user-header requirements