#include <fixed_bytes.hpp>
|
constexpr | fixed_bytes () |
|
| fixed_bytes (const std::array< word_t, num_words()> &arr) |
|
template<typename Word , size_t NumWords, typename Enable = typename std::enable_if<std::is_integral<Word>::value && std::is_unsigned<Word>::value && !std::is_same<Word, bool>::value && std::less<size_t>{}(sizeof(Word), sizeof(word_t))>::type> |
| fixed_bytes (const std::array< Word, NumWords > &arr) |
|
template<typename Word , size_t NumWords, typename Enable = typename std::enable_if<std::is_integral<Word>::value && std::is_unsigned<Word>::value && !std::is_same<Word, bool>::value && std::less<size_t>{}(sizeof(Word), sizeof(word_t))>::type> |
| fixed_bytes (const Word(&arr)[NumWords]) |
|
const auto & | get_array () const |
|
auto | data () |
|
auto | size () const |
|
std::array< uint8_t, Size > | extract_as_byte_array () const |
|
void | print () const |
|
template<size_t Size>
class sysio::fixed_bytes< Size >
Fixed size byte array sorted lexicographically
- Template Parameters
-
Definition at line 57 of file fixed_bytes.hpp.
◆ word_t
◆ fixed_bytes() [1/4]
◆ fixed_bytes() [2/4]
Constructor to fixed_bytes object from std::array of num_words() word_t types
- Parameters
-
Definition at line 120 of file fixed_bytes.hpp.
121 {
122 std::copy(arr.begin(), arr.end(), _data.begin());
123 }
◆ fixed_bytes() [3/4]
template<size_t Size>
template<typename Word , size_t NumWords, typename Enable = typename std::enable_if<std::is_integral<Word>::value && std::is_unsigned<Word>::value && !std::is_same<Word, bool>::value && std::less<size_t>{}(sizeof(Word), sizeof(word_t))>::type>
Constructor to fixed_bytes object from std::array of Word types smaller in size than word_t
- Parameters
-
Definition at line 135 of file fixed_bytes.hpp.
136 {
137 static_assert(
sizeof(
word_t) == (
sizeof(
word_t)/
sizeof(Word)) *
sizeof(Word),
138 "size of the backing word size is not divisible by the size of the array element" );
139 static_assert( sizeof(Word) * NumWords <= Size, "too many words supplied to fixed_bytes constructor" );
140
141 set_from_word_sequence<Word, NumWords>(arr.data(), arr.data() + arr.size(), *this);
142 }
◆ fixed_bytes() [4/4]
template<size_t Size>
template<typename Word , size_t NumWords, typename Enable = typename std::enable_if<std::is_integral<Word>::value && std::is_unsigned<Word>::value && !std::is_same<Word, bool>::value && std::less<size_t>{}(sizeof(Word), sizeof(word_t))>::type>
Constructor to fixed_bytes object from fixed-sized C array of Word types smaller in size than word_t
- Parameters
-
Definition at line 154 of file fixed_bytes.hpp.
155 {
156 static_assert(
sizeof(
word_t) == (
sizeof(
word_t)/
sizeof(Word)) *
sizeof(Word),
157 "size of the backing word size is not divisible by the size of the array element" );
158 static_assert( sizeof(Word) * NumWords <= Size, "too many words supplied to fixed_bytes constructor" );
159
160 set_from_word_sequence<Word, NumWords>(arr, arr + NumWords, *this);
161 }
◆ data()
Get the underlying data of the contained std::array
Definition at line 200 of file fixed_bytes.hpp.
200{ return _data.data(); }
◆ extract_as_byte_array()
Extract the contained data as an array of bytes
- Returns
- - the extracted data as array of bytes
Definition at line 222 of file fixed_bytes.hpp.
222 {
223 std::array<uint8_t, Size> arr;
224
225 const size_t num_sub_words =
sizeof(
word_t);
226
227 auto arr_itr = arr.begin();
228 auto data_itr = _data.begin();
229
230 for( size_t counter = _data.size(); counter > 0; --counter, ++data_itr ) {
231 size_t sub_words_left = num_sub_words;
232
233 auto temp_word = *data_itr;
234 if( counter == 1 ) {
237 }
238 for( ; sub_words_left > 0; --sub_words_left ) {
239 *(arr_itr + sub_words_left - 1) =
static_cast<uint8_t>(temp_word & 0xFF);
240 temp_word >>= 8;
241 }
242 arr_itr += num_sub_words;
243 }
244
245 return arr;
246 }
static constexpr size_t padded_bytes()
◆ get_array()
◆ make_from_word_sequence()
template<size_t Size>
template<typename FirstWord , typename... Rest>
Create a new fixed_bytes object from a sequence of words
- Template Parameters
-
FirstWord | - The type of the first word in the sequence |
Rest | - The type of the remaining words in the sequence |
- Parameters
-
first_word | - The first word in the sequence |
rest | - The remaining words in the sequence |
Definition at line 174 of file fixed_bytes.hpp.
181 {
182 static_assert(
sizeof(
word_t) == (
sizeof(
word_t)/
sizeof(FirstWord)) *
sizeof(FirstWord),
183 "size of the backing word size is not divisible by the size of the words supplied as arguments" );
184 static_assert( sizeof(FirstWord) * (1 + sizeof...(Rest)) <= Size, "too many words supplied to make_from_word_sequence" );
185
187 std::array<FirstWord, 1+sizeof...(Rest)> arr{{ first_word, rest... }};
188 set_from_word_sequence<FirstWord, 1+sizeof...(Rest)>(arr.data(), arr.data() + arr.size(), key);
190 }
◆ num_words()
◆ padded_bytes()
Get number of padded bytes contained in this fixed_bytes object. Padded bytes are the remaining bytes inside the fixed_bytes object after all the words are allocated
Definition at line 108 of file fixed_bytes.hpp.
static constexpr size_t num_words()
◆ print()
Prints fixed_bytes as a hexidecimal string
- Parameters
-
Definition at line 253 of file fixed_bytes.hpp.
253 {
255 printhex(static_cast<const void*>(arr.data()), arr.size());
256 }
std::array< uint8_t, Size > extract_as_byte_array() const
◆ size()
Get the size of the contained std::array
Definition at line 214 of file fixed_bytes.hpp.
214{ return _data.size(); }
The documentation for this class was generated from the following file: