jaulib v1.3.0
Jau Support Library (C++, Java, ..)
octets.hpp
Go to the documentation of this file.
1/*
2 * Author: Sven Gothel <sgothel@jausoft.com>
3 * Copyright (c) 2020-2024 Gothel Software e.K.
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining
6 * a copy of this software and associated documentation files (the
7 * "Software"), to deal in the Software without restriction, including
8 * without limitation the rights to use, copy, modify, merge, publish,
9 * distribute, sublicense, and/or sell copies of the Software, and to
10 * permit persons to whom the Software is furnished to do so, subject to
11 * the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be
14 * included in all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 */
24
25#ifndef JAU_OCTETS_HPP_
26#define JAU_OCTETS_HPP_
27
28#include <cstring>
29#include <string>
30#include <memory>
31#include <cstdint>
32#include <initializer_list>
33#include <algorithm>
34
35#include <mutex>
36#include <atomic>
37
38#include <jau/basic_types.hpp>
39#include <jau/uuid.hpp>
40#include <jau/eui48.hpp>
41
42#include <jau/debug.hpp>
43
44// #define JAU_TRACE_OCTETS 1
45#ifdef JAU_TRACE_OCTETS
46 #define JAU_TRACE_OCTETS_PRINT(...) { fprintf(stderr, __VA_ARGS__); fprintf(stderr, "\n"); fflush(stderr); }
47#else
48 #define JAU_TRACE_OCTETS_PRINT(...)
49#endif
50
51namespace jau {
52
53 /** \addtogroup ByteUtils
54 *
55 * @{
56 */
57
58 /**
59 * Transient read only and endian aware octet data, i.e. non persistent passthrough, owned by caller.
60 *
61 * Endian byte order is passed at construction.
62 *
63 * Constructor and assignment operations are `noexcept`. In case invalid arguments are passed, abort() is being called.
64 * This is a design choice based on reusing already existing underlying resources.
65 */
67 {
68 private:
69 /** Used memory size <= capacity, maybe zero. */
70 nsize_t _size;
71 /** Memory pointer, might be nullptr. Actual capacity known by owner, e.g. POctets. */
72 uint8_t * _data;
73 /** byte-order flag, little or big endian */
74 lb_endian_t _byte_order;
75
76 protected:
77 /**
78 * Validates the given data_ and size_.
79 *
80 * Aborts if data_ is nullptr and size_ > 0.
81 *
82 * @param data_ a memory pointer
83 * @param size_ claimed memory size
84 */
85 static inline void checkPtr(uint8_t *data_, nsize_t size_) noexcept {
86 if( nullptr == data_ && 0 < size_ ) {
87 ABORT("TROOctets: nullptr with size %s > 0", std::to_string(size_).c_str());
88 abort(); // never reached
89 }
90 }
91
92 constexpr uint8_t * data() noexcept { return _data; }
93
94 /**
95 * Internally sets the _size and _data fields after validation.
96 *
97 * Aborts if data_ is nullptr and size_ > 0.
98 *
99 * @param data_ a memory pointer
100 * @param size_ used memory size
101 * @param byte_order lb_endian::little or lb_endian::big byte order, one may pass lb_endian::native.
102 */
103 inline void setData(uint8_t *data_, nsize_t size_, const lb_endian_t byte_order) noexcept {
104 JAU_TRACE_OCTETS_PRINT("POctets setData: %zu bytes @ %p -> %zu bytes @ %p",
105 _size, _data, size_, data_);
106 checkPtr(data_, size_);
107 _size = size_;
108 _data = data_;
109 _byte_order = byte_order;
110 }
111 constexpr void setSize(nsize_t s) noexcept { _size = s; }
112
113 public:
114 /**
115 * Transient passthrough read-only memory, w/o ownership ..
116 *
117 * Aborts if source is nullptr and len > 0.
118 *
119 * @param source a non nullptr memory, otherwise throws exception. Actual capacity known by owner.
120 * @param len readable size of the memory, may be zero
121 * @param byte_order lb_endian::little or lb_endian::big byte order, one may pass lb_endian::native.
122 */
123 TROOctets(const uint8_t *source, const nsize_t len, const lb_endian_t byte_order_val ) noexcept
124 : _size( len ), _data( const_cast<uint8_t *>(source) ),
125 _byte_order( byte_order_val )
126 {
127 checkPtr(_data, _size);
128 }
129
130 /**
131 * Default constructor with nullptr memory, zero size and lb_endian::native byte order.
132 *
133 * Conveniently exists to allow instantiation of variables
134 * intended for later assignment.
135 */
136 TROOctets() noexcept
137 : _size( 0 ), _data( nullptr ),
138 _byte_order( lb_endian_t::native )
139 { }
140
141 TROOctets(const TROOctets &o) noexcept = default;
142 TROOctets(TROOctets &&o) noexcept = default;
143 TROOctets& operator=(const TROOctets &o) noexcept = default;
144 TROOctets& operator=(TROOctets &&o) noexcept = default;
145
146 virtual ~TROOctets() noexcept = default;
147
148 inline void check_range(const nsize_t i, const nsize_t count, const char *file, int line) const {
149 if( i+count > _size ) {
150 throw IndexOutOfBoundsException(i, count, _size, file, line);
151 }
152 }
153
154 constexpr bool is_range_valid(const nsize_t i, const nsize_t count) const noexcept {
155 return i+count <= _size;
156 }
157
158 /** Returns byte order of this octet store. */
159 constexpr lb_endian_t byte_order() const noexcept { return _byte_order; }
160
161 /** Returns the used memory size for read and write operations, may be zero. */
162 constexpr nsize_t size() const noexcept { return _size; }
163
164 uint8_t get_uint8(const nsize_t i) const {
166 return _data[i];
167 }
168 constexpr uint8_t get_uint8_nc(const nsize_t i) const noexcept {
169 return _data[i];
170 }
171
172 int8_t get_int8(const nsize_t i) const {
174 return jau::get_int8(_data + i);
175 }
176 constexpr int8_t get_int8_nc(const nsize_t i) const noexcept {
177 return jau::get_int8(_data + i);
178 }
179
180 uint16_t get_uint16(const nsize_t i) const {
182 return jau::get_uint16(_data + i, byte_order());
183 }
184 constexpr uint16_t get_uint16_nc(const nsize_t i) const noexcept {
185 return jau::get_uint16(_data + i, byte_order());
186 }
187
188 uint32_t get_uint32(const nsize_t i) const {
190 return jau::get_uint32(_data + i, byte_order());
191 }
192 constexpr uint32_t get_uint32_nc(const nsize_t i) const noexcept {
193 return jau::get_uint32(_data + i, byte_order());
194 }
195
196 EUI48 get_eui48(const nsize_t i) const {
197 check_range(i, sizeof(EUI48), E_FILE_LINE);
198 return EUI48(_data+i, byte_order() );
199 }
200 inline EUI48 get_eui48_nc(const nsize_t i) const noexcept {
201 return EUI48(_data+i, byte_order() );
202 }
203
204 uint64_t get_uint64(const nsize_t i) const {
206 return jau::get_uint64(_data + i, byte_order());
207 }
208 constexpr uint64_t get_uint64_nc(const nsize_t i) const noexcept {
209 return jau::get_uint64(_data + i, byte_order());
210 }
211
214 return jau::get_uint128(_data + i, byte_order());
215 }
216 constexpr uint128dp_t get_uint128_nc(const nsize_t i) const noexcept {
217 return jau::get_uint128(_data + i, byte_order());
218 }
219
222 return jau::get_uint192(_data + i, byte_order());
223 }
224 constexpr uint192dp_t get_uint192_nc(const nsize_t i) const noexcept {
225 return jau::get_uint192(_data + i, byte_order());
226 }
227
230 return jau::get_uint256(_data + i, byte_order());
231 }
232 constexpr uint256dp_t get_uint256_nc(const nsize_t i) const noexcept {
233 return jau::get_uint256(_data + i, byte_order());
234 }
235
236 /** Assumes a null terminated string */
237 std::string get_string(const nsize_t i) const {
238 check_range(i, 1, E_FILE_LINE); // minimum size
239 return std::string( (const char*)(_data+i) );
240 }
241 /** Assumes a null terminated string */
242 inline std::string get_string_nc(const nsize_t i) const noexcept {
243 return std::string( (const char*)(_data+i) );
244 }
245
246 /** Assumes a string with defined length, not necessarily null terminated */
247 std::string get_string(const nsize_t i, const nsize_t length) const {
248 check_range(i, length, E_FILE_LINE);
249 return std::string( (const char*)(_data+i), length );
250 }
251
252 uuid16_t get_uuid16(const nsize_t i) const {
253 return uuid16_t(get_uint16(i));
254 }
255 inline uuid16_t get_uuid16_nc(const nsize_t i) const noexcept {
256 return uuid16_t(get_uint16_nc(i));
257 }
258
261 return jau::get_uuid128(_data + i, byte_order());
262 }
263 inline uuid128_t get_uuid128_nc(const nsize_t i) const noexcept {
264 return jau::get_uuid128(_data + i, byte_order());
265 }
266
267 std::unique_ptr<const uuid_t> get_uuid(const nsize_t i, const uuid_t::TypeSize tsize) const {
269 return uuid_t::create(tsize, _data + i, byte_order());
270 }
271
272 constexpr uint8_t const * get_ptr() const noexcept { return _data; }
273 uint8_t const * get_ptr(const nsize_t i) const {
275 return _data + i;
276 }
277 constexpr uint8_t const * get_ptr_nc(const nsize_t i) const noexcept {
278 return _data + i;
279 }
280
281 bool operator==(const TROOctets& rhs) const noexcept {
282 return _size == rhs._size && 0 == std::memcmp(_data, rhs._data, _size);
283 }
284 bool operator!=(const TROOctets& rhs) const noexcept {
285 return !(*this == rhs);
286 }
287
288 std::string toString() const noexcept {
289 return "size "+std::to_string(_size)+", ["+to_string( byte_order() )+", "+to_string( byte_order() )+"], ro: "+bytesHexString(_data, 0, _size, true /* lsbFirst */);
290 }
291 };
292
293 /**
294 * Transient endian aware octet data, i.e. non persistent passthrough, owned by caller.
295 *
296 * Endian byte order is passed at construction.
297 *
298 * Constructor and assignment operations are `noexcept`. In case invalid arguments are passed, abort() is being called.
299 * This is a design choice based on reusing already existing underlying resources.
300 */
301 class TOctets : public TROOctets
302 {
303 public:
304 /**
305 * Transient passthrough r/w memory, w/o ownership ..
306 *
307 * Aborts if source is nullptr and len > 0.
308 *
309 * @param source transient data source
310 * @param len length of transient data source
311 * @param byte_order lb_endian::little or lb_endian::big byte order, one may pass lb_endian::native.
312 */
313 TOctets(uint8_t *source, const nsize_t len, const lb_endian_t byte_order) noexcept
314 : TROOctets(source, len, byte_order) {}
315
316 TOctets(const TOctets &o) noexcept = default;
317 TOctets(TOctets &&o) noexcept = default;
318 TOctets& operator=(const TOctets &o) noexcept = default;
319 TOctets& operator=(TOctets &&o) noexcept = default;
320
321 ~TOctets() noexcept override = default;
322
323 void put_int8(const nsize_t i, const int8_t v) {
325 data()[i] = static_cast<uint8_t>(v);
326 }
327 constexpr void put_int8_nc(const nsize_t i, const int8_t v) noexcept {
328 data()[i] = static_cast<uint8_t>(v);
329 }
330
331 void put_uint8(const nsize_t i, const uint8_t v) {
333 data()[i] = v;
334 }
335 constexpr void put_uint8_nc(const nsize_t i, const uint8_t v) noexcept {
336 data()[i] = v;
337 }
338
339 void put_uint16(const nsize_t i, const uint16_t v) {
341 jau::put_uint16(data() + i, v, byte_order());
342 }
343 constexpr void put_uint16_nc(const nsize_t i, const uint16_t v) noexcept {
344 jau::put_uint16(data() + i, v, byte_order());
345 }
346
347 void put_uint32(const nsize_t i, const uint32_t v) {
349 jau::put_uint32(data() + i, v, byte_order());
350 }
351 constexpr void put_uint32_nc(const nsize_t i, const uint32_t v) noexcept {
352 jau::put_uint32(data() + i, v, byte_order());
353 }
354
355 void put_eui48(const nsize_t i, const EUI48 & v) {
356 check_range(i, sizeof(v.b), E_FILE_LINE);
357 v.put(data() + i, byte_order() );
358 }
359 inline void put_eui48_nc(const nsize_t i, const EUI48 & v) noexcept {
360 v.put(data() + i, byte_order() );
361 }
362
363 void put_uint64(const nsize_t i, const uint64_t & v) {
365 jau::put_uint64(data() + i, v, byte_order());
366 }
367 constexpr void put_uint64_nc(const nsize_t i, const uint64_t & v) noexcept {
368 jau::put_uint64(data() + i, v, byte_order());
369 }
370
371 void put_uint128(const nsize_t i, const uint128dp_t & v) {
373 jau::put_uint128(data() + i, v, byte_order());
374 }
375 constexpr void put_uint128_nc(const nsize_t i, const uint128dp_t & v) noexcept {
376 jau::put_uint128(data() + i, v, byte_order());
377 }
378
379 void put_uint192(const nsize_t i, const uint192dp_t & v) {
381 jau::put_uint192(data() + i, v, byte_order());
382 }
383 constexpr void put_uint192_nc(const nsize_t i, const uint192dp_t & v) noexcept {
384 jau::put_uint192(data() + i, v, byte_order());
385 }
386
387 void put_uint256(const nsize_t i, const uint256dp_t & v) {
389 jau::put_uint256(data() + i, v, byte_order());
390 }
391 constexpr void put_uint256_nc(const nsize_t i, const uint256dp_t & v) noexcept {
392 jau::put_uint256(data() + i, v, byte_order());
393 }
394
395 void put_octets(const nsize_t i, const TROOctets & v) {
397 std::memcpy(data() + i, v.get_ptr(), v.size());
398 }
399 void put_octets_nc(const nsize_t i, const TROOctets & v) noexcept {
400 std::memcpy(data() + i, v.get_ptr(), v.size());
401 }
402 void put_octets(const nsize_t i, const TROOctets & v, const nsize_t v_off, const nsize_t v_len) noexcept {
403 const nsize_t size = std::min(v.size()-v_off, v_len);
405 std::memcpy(data() + i, v.get_ptr() + v_off, size);
406 }
407 void put_octets_nc(const nsize_t i, const TROOctets & v, const nsize_t v_off, const nsize_t v_len) noexcept {
408 const nsize_t size = std::min(v.size()-v_off, v_len);
409 std::memcpy(data() + i, v.get_ptr() + v_off, size);
410 }
411
412 void put_bytes(const nsize_t i, const uint8_t *source, const nsize_t byte_count) {
413 check_range(i, byte_count, E_FILE_LINE);
414 std::memcpy(data() + i, source, byte_count);
415 }
416 void put_bytes_nc(const nsize_t i, const uint8_t *source, const nsize_t byte_count) noexcept {
417 std::memcpy(data() + i, source, byte_count);
418 }
419
420 void memmove(const nsize_t i, const uint8_t *source, const nsize_t byte_count) {
421 check_range(i, byte_count, E_FILE_LINE);
422 std::memmove(data() + i, source, byte_count);
423 }
424 void memmove_nc(const nsize_t i, const uint8_t *source, const nsize_t byte_count) noexcept {
425 std::memmove(data() + i, source, byte_count);
426 }
427
428 void memset(const nsize_t i, const uint8_t c, const nsize_t byte_count) {
429 check_range(i, byte_count, E_FILE_LINE);
430 std::memset(data() + i, c, byte_count);
431 }
432 void memset_nc(const nsize_t i, const uint8_t c, const nsize_t byte_count) noexcept {
433 std::memset(data() + i, c, byte_count);
434 }
435 void bzero(const nsize_t i, const nsize_t byte_count) {
436 check_range(i, byte_count, E_FILE_LINE);
437 ::bzero(data() + i, byte_count);
438 }
439 void bzero_nc(const nsize_t i, const nsize_t byte_count) noexcept {
440 ::bzero(data() + i, byte_count);
441 }
442 void bzero() noexcept {
443 if( size() > 0 ) {
444 ::bzero(data(), size());
445 }
446 }
447
448 void put_string(const nsize_t i, const std::string & v, const nsize_t max_len, const bool includeEOS) {
449 const nsize_t size1 = v.size() + ( includeEOS ? 1 : 0 );
450 const nsize_t size = std::min(size1, max_len);
452 std::memcpy(data() + i, v.c_str(), size);
453 if( size < size1 && includeEOS ) {
454 *(data() + i + size - 1) = 0; // ensure EOS
455 }
456 }
457 void put_string_nc(const nsize_t i, const std::string & v, const nsize_t max_len, const bool includeEOS) noexcept {
458 const nsize_t size1 = v.size() + ( includeEOS ? 1 : 0 );
459 const nsize_t size = std::min(size1, max_len);
460 std::memcpy(data() + i, v.c_str(), size);
461 if( size < size1 && includeEOS ) {
462 *(data() + i + size - 1) = 0; // ensure EOS
463 }
464 }
465
466 void put_uuid(const nsize_t i, const uuid_t & v) {
468 v.put(data() + i, byte_order());
469 }
470 void put_uuid_nc(const nsize_t i, const uuid_t & v) noexcept {
471 v.put(data() + i, byte_order());
472 }
473
474 inline uint8_t * get_wptr() noexcept { return data(); }
475
476 uint8_t * get_wptr(const nsize_t i) {
478 return data() + i;
479 }
480 inline uint8_t * get_wptr_nc(const nsize_t i) noexcept {
481 return data() + i;
482 }
483
484 std::string toString() const noexcept {
485 return "size "+std::to_string(size())+", rw: "+bytesHexString(get_ptr(), 0, size(), true /* lsbFirst */);
486 }
487 };
488
489 /**
490 * Transient endian aware octet data slice, i.e. a view of an TOctet.
491 *
492 * Endian byte order is defined by its parent TOctet.
493 */
495 {
496 private:
497 const TOctets & _parent;
498 nsize_t const _offset;
499 nsize_t const _size;
500
501 public:
502 /**
503 * Creates a view of a given TOctet with the specified offset_ and size_.
504 *
505 * @param buffer_ the parent TOctet buffer
506 * @param offset_ offset to the parent TOctet buffer
507 * @param size_ size of this view, starting at offset_
508 * @throws IndexOutOfBoundsException if offset_ + size_ > parent buffer_.size()
509 */
510 TOctetSlice(const TOctets &buffer_, const nsize_t offset_, const nsize_t size_)
511 : _parent(buffer_), _offset(offset_), _size(size_)
512 {
513 if( offset_+_size > buffer_.size() ) {
514 throw IndexOutOfBoundsException(offset_, _size, buffer_.size(), E_FILE_LINE);
515 }
516 }
517
518 /** Returns byte order of this octet store. */
519 constexpr lb_endian_t byte_order() const noexcept { return _parent.byte_order(); }
520
521 constexpr nsize_t size() const noexcept { return _size; }
522 constexpr nsize_t offset() const noexcept { return _offset; }
523 constexpr const TOctets& parent() const noexcept { return _parent; }
524
525 uint8_t get_uint8(const nsize_t i) const {
526 return _parent.get_uint8(_offset+i);
527 }
528 constexpr uint8_t get_uint8_nc(const nsize_t i) const noexcept {
529 return _parent.get_uint8_nc(_offset+i);
530 }
531
532 uint16_t get_uint16(const nsize_t i) const {
533 return _parent.get_uint16(_offset+i);
534 }
535 constexpr uint16_t get_uint16_nc(const nsize_t i) const noexcept {
536 return _parent.get_uint16_nc(_offset+i);
537 }
538
539 uint8_t const * get_ptr(const nsize_t i) const {
540 return _parent.get_ptr(_offset+i);
541 }
542 constexpr uint8_t const * get_ptr_nc(const nsize_t i) const noexcept {
543 return _parent.get_ptr_nc(_offset+i);
544 }
545
546 std::string toString() const noexcept {
547 return "offset "+std::to_string(_offset)+", size "+std::to_string(_size)+": "+bytesHexString(_parent.get_ptr(), _offset, _size, true /* lsbFirst */);
548 }
549 };
550
551 /**
552 * Persistent endian aware octet data, i.e. owned memory allocation.
553 *
554 * Endian byte order is passed at construction.
555 *
556 * Constructor and assignment operations are **not** completely `noexcept` and may throw exceptions.
557 * This is a design choice based on dynamic resource allocation performed by this class.
558 */
559 class POctets : public TOctets
560 {
561 private:
562 nsize_t _capacity;
563
564 void freeData() {
565 uint8_t * ptr = data();
566 if( nullptr != ptr ) {
567 JAU_TRACE_OCTETS_PRINT("POctets release: %p", ptr);
568 free(ptr);
569 } // else: zero sized POctets w/ nullptr are supported
570 }
571
572 /**
573 * Allocate a memory chunk.
574 * @param size
575 * @return
576 * @throws OutOfMemoryError if running out of memory
577 */
578 static uint8_t * allocData(const nsize_t size) {
579 if( size <= 0 ) {
580 return nullptr;
581 }
582 uint8_t * m = static_cast<uint8_t*>( std::malloc(size) );
583 if( nullptr == m ) {
584 throw OutOfMemoryError("allocData size "+std::to_string(size)+" -> nullptr", E_FILE_LINE);
585 }
586 return m;
587 }
588
589 public:
590 /** Returns the memory capacity, never zero, greater or equal size(). */
591 constexpr nsize_t capacity() const noexcept { return _capacity; }
592
593 /** Returns the remaining octets for put left, i.e. capacity() - size(). */
594 constexpr nsize_t remaining() const noexcept { return _capacity - size(); }
595
596 /**
597 * Zero sized POctets instance.
598 *
599 * Will not throw an OutOfMemoryError exception due to no allocation.
600 *
601 * @param byte_order lb_endian::little or lb_endian::big byte order, one may pass lb_endian::native.
602 */
604 : TOctets(nullptr, 0, byte_order), _capacity(0)
605 {
606 JAU_TRACE_OCTETS_PRINT("POctets ctor0: zero-sized");
607 }
608
609 /**
610 * Takes ownership (malloc(size) and copy, free) ..
611 *
612 * Capacity and size will be of given source size.
613 *
614 * @param source_ source data to be copied into this new instance
615 * @param size_ length of source data
616 * @param byte_order lb_endian::little or lb_endian::big byte order, one may pass lb_endian::native.
617 * @throws IllegalArgumentException if source_ is nullptr and size_ > 0
618 * @throws OutOfMemoryError if allocation fails
619 */
620 POctets(const uint8_t *source_, const nsize_t size_, const lb_endian_t byte_order)
621 : TOctets( allocData(size_), size_, byte_order),
622 _capacity( size_ )
623 {
624 if( 0 < size_ ) {
625 if( nullptr == source_ ) {
626 throw IllegalArgumentException("source nullptr with size "+std::to_string(size_)+" > 0", E_FILE_LINE);
627 }
628 std::memcpy(data(), source_, size_);
629 }
630 JAU_TRACE_OCTETS_PRINT("POctets ctor1: %p", data());
631 }
632
633 /**
634 * Takes ownership (malloc(size) and copy, free) ..
635 *
636 * Capacity and size will be of given source size.
637 *
638 * @param sourcelist source initializer list data to be copied into this new instance with implied size
639 * @param byte_order lb_endian::little or lb_endian::big byte order, one may pass lb_endian::native.
640 * @throws IllegalArgumentException if source_ is nullptr and size_ > 0
641 * @throws OutOfMemoryError if allocation fails
642 */
643 POctets(std::initializer_list<uint8_t> sourcelist, const lb_endian_t byte_order)
644 : TOctets( allocData(sourcelist.size()), sourcelist.size(), byte_order),
645 _capacity( sourcelist.size() )
646 {
647 if( 0 < _capacity ) {
648 std::memcpy(data(), sourcelist.begin(), _capacity);
649 }
650 JAU_TRACE_OCTETS_PRINT("POctets ctor1: %p", data());
651 }
652
653 /**
654 * New buffer (malloc(capacity), free)
655 *
656 * @param capacity_ new capacity
657 * @param size_ new size with size <= capacity
658 * @param byte_order lb_endian::little or lb_endian::big byte order, one may pass lb_endian::native.
659 * @throws IllegalArgumentException if capacity_ < size_
660 * @throws OutOfMemoryError if allocation fails
661 */
662 POctets(const nsize_t capacity_, const nsize_t size_, const lb_endian_t byte_order)
663 : TOctets( allocData( capacity_ ), size_, byte_order ),
664 _capacity( capacity_ )
665 {
666 if( capacity() < size() ) {
668 }
669 JAU_TRACE_OCTETS_PRINT("POctets ctor2: %p", data());
670 }
671
672 /**
673 * New buffer (malloc, free)
674 *
675 * @param size new size and capacity
676 * @param byte_order lb_endian::little or lb_endian::big byte order, one may pass lb_endian::native.
677 * @throws OutOfMemoryError if allocation fails
678 */
681 {
682 JAU_TRACE_OCTETS_PRINT("POctets ctor3: %p", data());
683 }
684
685 /**
686 * Copy constructor
687 *
688 * Capacity of this new instance will be of source.size() only.
689 *
690 * @param source POctet source to be copied
691 * @throws OutOfMemoryError if allocation fails
692 */
693 POctets(const POctets &source)
694 : TOctets( allocData(source.size()), source.size(), source.byte_order() ),
695 _capacity( source.size() )
696 {
697 std::memcpy(data(), source.get_ptr(), source.size());
698 JAU_TRACE_OCTETS_PRINT("POctets ctor-cpy0: %p -> %p", source.get_ptr(), data());
699 }
700
701 /**
702 * Copy constructor (explicit), allowing to set a higher capacity
703 * than source.size() in contrast to the copy-constructor.
704 *
705 * @param source POctet source to be copied
706 * @param capacity_ used to determine new capacity `std::max(capacity_, source.size())`
707 * @throws OutOfMemoryError if allocation fails
708 */
709 explicit POctets(const POctets &source, const nsize_t capacity_)
710 : TOctets( allocData(source.size()), source.size(), source.byte_order() ),
711 _capacity( std::max(capacity_, source.size()) )
712 {
713 std::memcpy(data(), source.get_ptr(), source.size());
714 JAU_TRACE_OCTETS_PRINT("POctets ctor-cpy-extra1: %p -> %p", source.get_ptr(), data());
715 }
716
717 /**
718 * Move constructor
719 * @param o POctet source to be taken over
720 */
721 POctets(POctets &&o) noexcept
722 : TOctets( o.data(), o.size(), o.byte_order() ),
723 _capacity( o.capacity() )
724 {
725 // moved origin data references
726 // purge origin
727 o.setData(nullptr, 0, o.byte_order());
728 o._capacity = 0;
729 JAU_TRACE_OCTETS_PRINT("POctets ctor-move0: %p", data());
730 }
731
732 /**
733 * Assignment operator
734 * @param _source POctet source to be copied
735 * @return
736 * @throws OutOfMemoryError if allocation fails
737 */
738 POctets& operator=(const POctets &_source) {
739 if( this == &_source ) {
740 return *this;
741 }
742 freeData();
743 setData(allocData(_source.size()), _source.size(), _source.byte_order());
744 _capacity = _source.size();
745 std::memcpy(data(), _source.get_ptr(), _source.size());
746 JAU_TRACE_OCTETS_PRINT("POctets assign0: %p", data());
747 return *this;
748 }
749
750 /**
751 * Move assignment operator
752 * @param o POctet source to be taken over
753 * @return
754 */
755 POctets& operator=(POctets &&o) noexcept {
756 // move origin data references
757 setData(o.data(), o.size(), o.byte_order());
758 _capacity = o._capacity;
759 // purge origin
760 o.setData(nullptr, 0, o.byte_order());
761 o._capacity = 0;
762 JAU_TRACE_OCTETS_PRINT("POctets assign-move0: %p", data());
763 return *this;
764 }
765
766 ~POctets() noexcept override {
767 freeData();
768 setData(nullptr, 0, byte_order());
769 _capacity=0;
770 }
771
772 /**
773 * Makes a persistent POctets by copying the data from TROOctets.
774 * @param _source TROOctets to be copied
775 * @throws OutOfMemoryError if allocation fails
776 */
777 POctets(const TROOctets & _source)
778 : TOctets( allocData(_source.size()), _source.size(), _source.byte_order() ),
779 _capacity( _source.size() )
780 {
781 std::memcpy(data(), _source.get_ptr(), _source.size());
782 JAU_TRACE_OCTETS_PRINT("POctets ctor-cpy1: %p", data());
783 }
784
785 /**
786 * Assignment operator for TROOctets
787 * @param _source TROOctets to be copied
788 * @return
789 * @throws OutOfMemoryError if allocation fails
790 */
791 POctets& operator=(const TROOctets &_source) {
792 if( static_cast<TROOctets *>(this) == &_source ) {
793 return *this;
794 }
795 freeData();
796 setData(allocData(_source.size()), _source.size(), _source.byte_order());
797 _capacity = _source.size();
798 std::memcpy(data(), _source.get_ptr(), _source.size());
799 JAU_TRACE_OCTETS_PRINT("POctets assign1: %p", data());
800 return *this;
801 }
802
803 /**
804 * Makes a persistent POctets by copying the data from TOctetSlice.
805 * @param _source TROOctetSlice to be copied
806 * @throws OutOfMemoryError if allocation fails
807 */
808 POctets(const TOctetSlice & _source)
809 : TOctets( allocData(_source.size()), _source.size(), _source.byte_order() ),
810 _capacity( _source.size() )
811 {
812 std::memcpy(data(), _source.parent().get_ptr() + _source.offset(), _source.size());
813 JAU_TRACE_OCTETS_PRINT("POctets ctor-cpy2: %p", data());
814 }
815
816 /**
817 * Assignment operator for TOctetSlice
818 * @param _source TOctetSlice to be copied
819 * @return
820 * @throws OutOfMemoryError if allocation fails
821 */
822 POctets& operator=(const TOctetSlice &_source) {
823 freeData();
824 setData(allocData(_source.size()), _source.size(), _source.byte_order());
825 _capacity = _source.size();
826 std::memcpy(data(), _source.get_ptr(0), _source.size());
827 JAU_TRACE_OCTETS_PRINT("POctets assign2: %p", data());
828 return *this;
829 }
830
831 /**
832 * Resizes this instance, including its capacity
833 * @param newCapacity new capacity, must be >= newSize
834 * @param newSize new size, must be < newCapacity
835 * @return
836 * @throws OutOfMemoryError if allocation fails
837 * @throws IllegalArgumentException if newCapacity < newSize
838 */
839 POctets & resize(const nsize_t newCapacity, const nsize_t newSize) {
840 if( newCapacity < newSize ) {
841 throw IllegalArgumentException("newCapacity "+std::to_string(newCapacity)+" < newSize "+std::to_string(newSize), E_FILE_LINE);
842 }
843 if( newCapacity != _capacity ) {
844 if( newSize > size() ) {
845 recapacity(newCapacity);
846 setSize(newSize);
847 } else {
848 setSize(newSize);
849 recapacity(newCapacity);
850 }
851 } else {
852 setSize(newSize);
853 }
854 return *this;
855 }
856
857 /**
858 * Sets a new size for this instance.
859 * @param newSize new size, must be <= current capacity()
860 * @return
861 * @throws IllegalArgumentException if newSize > current capacity()
862 */
863 POctets & resize(const nsize_t newSize) {
864 if( _capacity < newSize ) {
865 throw IllegalArgumentException("capacity "+std::to_string(_capacity)+" < newSize "+std::to_string(newSize), E_FILE_LINE);
866 }
867 setSize(newSize);
868 return *this;
869 }
870
871 /**
872 * Changes the capacity.
873 *
874 * @param newCapacity new capacity, must be >= size()
875 * @return
876 * @throws OutOfMemoryError if allocation fails
877 * @throws IllegalArgumentException if newCapacity < size()
878 */
879 POctets & recapacity(const nsize_t newCapacity) {
880 if( newCapacity < size() ) {
881 throw IllegalArgumentException("newCapacity "+std::to_string(newCapacity)+" < size "+std::to_string(size()), E_FILE_LINE);
882 }
883 if( newCapacity == _capacity ) {
884 return *this;
885 }
886 uint8_t* data2 = allocData(newCapacity);
887 if( size() > 0 ) {
888 memcpy(data2, get_ptr(), size());
889 }
890 JAU_TRACE_OCTETS_PRINT("POctets recapacity: %p -> %p", data(), data2);
891 free(data());
892 setData(data2, size(), byte_order());
893 _capacity = newCapacity;
894 return *this;
895 }
896
897 /**
898 * Append and assign operator
899 * @param b
900 * @return
901 * @throws OutOfMemoryError if allocation due to potential recapacity() fails
902 */
904 if( 0 < b.size() ) {
905 const nsize_t newSize = size() + b.size();
906 if( _capacity < newSize ) {
907 recapacity( newSize );
908 }
909 memcpy(data()+size(), b.get_ptr(), b.size());
910 setSize(newSize);
911 }
912 return *this;
913 }
914 /**
915 * Append and assign operator
916 * @param b
917 * @return
918 * @throws OutOfMemoryError if allocation due to potential recapacity() fails
919 */
921 if( 0 < b.size() ) {
922 const nsize_t newSize = size() + b.size();
923 if( _capacity < newSize ) {
924 recapacity( newSize );
925 }
926 memcpy(data()+size(), b.parent().get_ptr()+b.offset(), b.size());
927 setSize(newSize);
928 }
929 return *this;
930 }
931
932 std::string toString() const {
933 return "size "+std::to_string(size())+", capacity "+std::to_string(capacity())+", "+bytesHexString(get_ptr(), 0, size(), true /* lsbFirst */);
934 }
935 };
936
937 /**@}*/
938
939} /* namespace jau */
940
941
942#endif /* JAU_OCTETS_HPP_ */
#define E_FILE_LINE
Persistent endian aware octet data, i.e.
Definition: octets.hpp:560
POctets & operator=(const TROOctets &_source)
Assignment operator for TROOctets.
Definition: octets.hpp:791
POctets(POctets &&o) noexcept
Move constructor.
Definition: octets.hpp:721
POctets & operator=(POctets &&o) noexcept
Move assignment operator.
Definition: octets.hpp:755
std::string toString() const
Definition: octets.hpp:932
POctets(const nsize_t capacity_, const nsize_t size_, const lb_endian_t byte_order)
New buffer (malloc(capacity), free)
Definition: octets.hpp:662
POctets(const POctets &source)
Copy constructor.
Definition: octets.hpp:693
POctets & operator=(const POctets &_source)
Assignment operator.
Definition: octets.hpp:738
POctets(const nsize_t size, const lb_endian_t byte_order)
New buffer (malloc, free)
Definition: octets.hpp:679
POctets(const TROOctets &_source)
Makes a persistent POctets by copying the data from TROOctets.
Definition: octets.hpp:777
~POctets() noexcept override
Definition: octets.hpp:766
POctets & resize(const nsize_t newCapacity, const nsize_t newSize)
Resizes this instance, including its capacity.
Definition: octets.hpp:839
POctets & operator=(const TOctetSlice &_source)
Assignment operator for TOctetSlice.
Definition: octets.hpp:822
POctets & operator+=(const TOctetSlice &b)
Append and assign operator.
Definition: octets.hpp:920
constexpr nsize_t remaining() const noexcept
Returns the remaining octets for put left, i.e.
Definition: octets.hpp:594
POctets(const POctets &source, const nsize_t capacity_)
Copy constructor (explicit), allowing to set a higher capacity than source.size() in contrast to the ...
Definition: octets.hpp:709
POctets & recapacity(const nsize_t newCapacity)
Changes the capacity.
Definition: octets.hpp:879
constexpr nsize_t capacity() const noexcept
Returns the memory capacity, never zero, greater or equal size().
Definition: octets.hpp:591
POctets(std::initializer_list< uint8_t > sourcelist, const lb_endian_t byte_order)
Takes ownership (malloc(size) and copy, free) .
Definition: octets.hpp:643
POctets & resize(const nsize_t newSize)
Sets a new size for this instance.
Definition: octets.hpp:863
POctets(const lb_endian_t byte_order) noexcept
Zero sized POctets instance.
Definition: octets.hpp:603
POctets & operator+=(const TROOctets &b)
Append and assign operator.
Definition: octets.hpp:903
POctets(const TOctetSlice &_source)
Makes a persistent POctets by copying the data from TOctetSlice.
Definition: octets.hpp:808
POctets(const uint8_t *source_, const nsize_t size_, const lb_endian_t byte_order)
Takes ownership (malloc(size) and copy, free) .
Definition: octets.hpp:620
Transient endian aware octet data slice, i.e.
Definition: octets.hpp:495
std::string toString() const noexcept
Definition: octets.hpp:546
uint8_t get_uint8(const nsize_t i) const
Definition: octets.hpp:525
constexpr lb_endian_t byte_order() const noexcept
Returns byte order of this octet store.
Definition: octets.hpp:519
constexpr nsize_t offset() const noexcept
Definition: octets.hpp:522
constexpr nsize_t size() const noexcept
Definition: octets.hpp:521
constexpr const TOctets & parent() const noexcept
Definition: octets.hpp:523
uint16_t get_uint16(const nsize_t i) const
Definition: octets.hpp:532
constexpr uint16_t get_uint16_nc(const nsize_t i) const noexcept
Definition: octets.hpp:535
constexpr uint8_t const * get_ptr_nc(const nsize_t i) const noexcept
Definition: octets.hpp:542
TOctetSlice(const TOctets &buffer_, const nsize_t offset_, const nsize_t size_)
Creates a view of a given TOctet with the specified offset_ and size_.
Definition: octets.hpp:510
uint8_t const * get_ptr(const nsize_t i) const
Definition: octets.hpp:539
constexpr uint8_t get_uint8_nc(const nsize_t i) const noexcept
Definition: octets.hpp:528
Transient endian aware octet data, i.e.
Definition: octets.hpp:302
constexpr void put_uint64_nc(const nsize_t i, const uint64_t &v) noexcept
Definition: octets.hpp:367
void put_uint128(const nsize_t i, const uint128dp_t &v)
Definition: octets.hpp:371
void put_octets_nc(const nsize_t i, const TROOctets &v, const nsize_t v_off, const nsize_t v_len) noexcept
Definition: octets.hpp:407
void memset(const nsize_t i, const uint8_t c, const nsize_t byte_count)
Definition: octets.hpp:428
void put_uint64(const nsize_t i, const uint64_t &v)
Definition: octets.hpp:363
TOctets(TOctets &&o) noexcept=default
TOctets(uint8_t *source, const nsize_t len, const lb_endian_t byte_order) noexcept
Transient passthrough r/w memory, w/o ownership .
Definition: octets.hpp:313
void memmove_nc(const nsize_t i, const uint8_t *source, const nsize_t byte_count) noexcept
Definition: octets.hpp:424
std::string toString() const noexcept
Definition: octets.hpp:484
TOctets & operator=(const TOctets &o) noexcept=default
constexpr void put_uint32_nc(const nsize_t i, const uint32_t v) noexcept
Definition: octets.hpp:351
void put_eui48(const nsize_t i, const EUI48 &v)
Definition: octets.hpp:355
void put_octets_nc(const nsize_t i, const TROOctets &v) noexcept
Definition: octets.hpp:399
void put_uint192(const nsize_t i, const uint192dp_t &v)
Definition: octets.hpp:379
void bzero_nc(const nsize_t i, const nsize_t byte_count) noexcept
Definition: octets.hpp:439
void put_bytes_nc(const nsize_t i, const uint8_t *source, const nsize_t byte_count) noexcept
Definition: octets.hpp:416
void put_string(const nsize_t i, const std::string &v, const nsize_t max_len, const bool includeEOS)
Definition: octets.hpp:448
void put_octets(const nsize_t i, const TROOctets &v)
Definition: octets.hpp:395
void bzero(const nsize_t i, const nsize_t byte_count)
Definition: octets.hpp:435
TOctets(const TOctets &o) noexcept=default
void put_uint256(const nsize_t i, const uint256dp_t &v)
Definition: octets.hpp:387
void bzero() noexcept
Definition: octets.hpp:442
constexpr void put_uint256_nc(const nsize_t i, const uint256dp_t &v) noexcept
Definition: octets.hpp:391
TOctets & operator=(TOctets &&o) noexcept=default
void put_eui48_nc(const nsize_t i, const EUI48 &v) noexcept
Definition: octets.hpp:359
constexpr void put_uint128_nc(const nsize_t i, const uint128dp_t &v) noexcept
Definition: octets.hpp:375
constexpr void put_uint16_nc(const nsize_t i, const uint16_t v) noexcept
Definition: octets.hpp:343
~TOctets() noexcept override=default
void put_octets(const nsize_t i, const TROOctets &v, const nsize_t v_off, const nsize_t v_len) noexcept
Definition: octets.hpp:402
constexpr void put_uint8_nc(const nsize_t i, const uint8_t v) noexcept
Definition: octets.hpp:335
uint8_t * get_wptr() noexcept
Definition: octets.hpp:474
void memset_nc(const nsize_t i, const uint8_t c, const nsize_t byte_count) noexcept
Definition: octets.hpp:432
void put_uint32(const nsize_t i, const uint32_t v)
Definition: octets.hpp:347
void put_string_nc(const nsize_t i, const std::string &v, const nsize_t max_len, const bool includeEOS) noexcept
Definition: octets.hpp:457
constexpr void put_int8_nc(const nsize_t i, const int8_t v) noexcept
Definition: octets.hpp:327
void memmove(const nsize_t i, const uint8_t *source, const nsize_t byte_count)
Definition: octets.hpp:420
uint8_t * get_wptr(const nsize_t i)
Definition: octets.hpp:476
void put_uint16(const nsize_t i, const uint16_t v)
Definition: octets.hpp:339
void put_uuid(const nsize_t i, const uuid_t &v)
Definition: octets.hpp:466
constexpr void put_uint192_nc(const nsize_t i, const uint192dp_t &v) noexcept
Definition: octets.hpp:383
void put_bytes(const nsize_t i, const uint8_t *source, const nsize_t byte_count)
Definition: octets.hpp:412
void put_uuid_nc(const nsize_t i, const uuid_t &v) noexcept
Definition: octets.hpp:470
uint8_t * get_wptr_nc(const nsize_t i) noexcept
Definition: octets.hpp:480
void put_int8(const nsize_t i, const int8_t v)
Definition: octets.hpp:323
void put_uint8(const nsize_t i, const uint8_t v)
Definition: octets.hpp:331
Transient read only and endian aware octet data, i.e.
Definition: octets.hpp:67
uint32_t get_uint32(const nsize_t i) const
Definition: octets.hpp:188
constexpr uint16_t get_uint16_nc(const nsize_t i) const noexcept
Definition: octets.hpp:184
TROOctets & operator=(const TROOctets &o) noexcept=default
std::unique_ptr< const uuid_t > get_uuid(const nsize_t i, const uuid_t::TypeSize tsize) const
Definition: octets.hpp:267
uuid128_t get_uuid128_nc(const nsize_t i) const noexcept
Definition: octets.hpp:263
constexpr uint128dp_t get_uint128_nc(const nsize_t i) const noexcept
Definition: octets.hpp:216
std::string toString() const noexcept
Definition: octets.hpp:288
constexpr lb_endian_t byte_order() const noexcept
Returns byte order of this octet store.
Definition: octets.hpp:159
uint128dp_t get_uint128(const nsize_t i) const
Definition: octets.hpp:212
std::string get_string(const nsize_t i) const
Assumes a null terminated string.
Definition: octets.hpp:237
TROOctets(TROOctets &&o) noexcept=default
TROOctets() noexcept
Default constructor with nullptr memory, zero size and lb_endian::native byte order.
Definition: octets.hpp:136
TROOctets(const uint8_t *source, const nsize_t len, const lb_endian_t byte_order_val) noexcept
Transient passthrough read-only memory, w/o ownership .
Definition: octets.hpp:123
constexpr nsize_t size() const noexcept
Returns the used memory size for read and write operations, may be zero.
Definition: octets.hpp:162
constexpr bool is_range_valid(const nsize_t i, const nsize_t count) const noexcept
Definition: octets.hpp:154
bool operator==(const TROOctets &rhs) const noexcept
Definition: octets.hpp:281
virtual ~TROOctets() noexcept=default
constexpr int8_t get_int8_nc(const nsize_t i) const noexcept
Definition: octets.hpp:176
bool operator!=(const TROOctets &rhs) const noexcept
Definition: octets.hpp:284
uuid16_t get_uuid16(const nsize_t i) const
Definition: octets.hpp:252
uuid16_t get_uuid16_nc(const nsize_t i) const noexcept
Definition: octets.hpp:255
static void checkPtr(uint8_t *data_, nsize_t size_) noexcept
Validates the given data_ and size_.
Definition: octets.hpp:85
TROOctets(const TROOctets &o) noexcept=default
uint8_t const * get_ptr(const nsize_t i) const
Definition: octets.hpp:273
uint16_t get_uint16(const nsize_t i) const
Definition: octets.hpp:180
EUI48 get_eui48_nc(const nsize_t i) const noexcept
Definition: octets.hpp:200
std::string get_string(const nsize_t i, const nsize_t length) const
Assumes a string with defined length, not necessarily null terminated.
Definition: octets.hpp:247
uint8_t get_uint8(const nsize_t i) const
Definition: octets.hpp:164
std::string get_string_nc(const nsize_t i) const noexcept
Assumes a null terminated string.
Definition: octets.hpp:242
void check_range(const nsize_t i, const nsize_t count, const char *file, int line) const
Definition: octets.hpp:148
TROOctets & operator=(TROOctets &&o) noexcept=default
void setData(uint8_t *data_, nsize_t size_, const lb_endian_t byte_order) noexcept
Internally sets the _size and _data fields after validation.
Definition: octets.hpp:103
constexpr uint192dp_t get_uint192_nc(const nsize_t i) const noexcept
Definition: octets.hpp:224
uint64_t get_uint64(const nsize_t i) const
Definition: octets.hpp:204
constexpr uint256dp_t get_uint256_nc(const nsize_t i) const noexcept
Definition: octets.hpp:232
int8_t get_int8(const nsize_t i) const
Definition: octets.hpp:172
constexpr uint8_t * data() noexcept
Definition: octets.hpp:92
uint256dp_t get_uint256(const nsize_t i) const
Definition: octets.hpp:228
uint192dp_t get_uint192(const nsize_t i) const
Definition: octets.hpp:220
constexpr uint32_t get_uint32_nc(const nsize_t i) const noexcept
Definition: octets.hpp:192
constexpr uint64_t get_uint64_nc(const nsize_t i) const noexcept
Definition: octets.hpp:208
constexpr uint8_t get_uint8_nc(const nsize_t i) const noexcept
Definition: octets.hpp:168
constexpr uint8_t const * get_ptr() const noexcept
Definition: octets.hpp:272
constexpr void setSize(nsize_t s) noexcept
Definition: octets.hpp:111
uuid128_t get_uuid128(const nsize_t i) const
Definition: octets.hpp:259
constexpr uint8_t const * get_ptr_nc(const nsize_t i) const noexcept
Definition: octets.hpp:277
EUI48 get_eui48(const nsize_t i) const
Definition: octets.hpp:196
static constexpr jau::nsize_t number(const TypeSize rhs) noexcept
Definition: uuid.hpp:63
virtual jau::nsize_t put(uint8_t *const buffer, lb_endian_t const le_or_be) const noexcept=0
TypeSize
Underlying integer value present octet count.
Definition: uuid.hpp:60
jau::nsize_t getTypeSizeInt() const noexcept
Definition: uuid.hpp:126
static std::unique_ptr< uuid_t > create(TypeSize const t, uint8_t const *const buffer, lb_endian_t const le_or_be)
Definition: uuid.cpp:56
#define ABORT(...)
Use for unconditional ::abort() call with given messages, prefix '[elapsed_time] ABORT @ file:line fu...
Definition: debug.hpp:101
constexpr uint192dp_t get_uint192(uint8_t const *buffer) noexcept
See get_uint16() for reference.
Definition: byte_util.hpp:798
constexpr uint128dp_t get_uint128(uint8_t const *buffer) noexcept
See get_uint16() for reference.
Definition: byte_util.hpp:765
constexpr void put_uint256(uint8_t *buffer, const uint256dp_t &v) noexcept
See put_uint16() for reference.
Definition: byte_util.hpp:815
constexpr uint16_t get_uint16(uint8_t const *buffer) noexcept
Returns a uint16_t value from the given byte address using packed_t to resolve a potential memory ali...
Definition: byte_util.hpp:661
constexpr uint32_t get_uint32(uint8_t const *buffer) noexcept
See get_uint16() for reference.
Definition: byte_util.hpp:699
constexpr void put_uint32(uint8_t *buffer, const uint32_t v) noexcept
See put_uint16() for reference.
Definition: byte_util.hpp:683
constexpr uint256dp_t get_uint256(uint8_t const *buffer) noexcept
See get_uint16() for reference.
Definition: byte_util.hpp:831
constexpr void put_uint192(uint8_t *buffer, const uint192dp_t &v) noexcept
See put_uint16() for reference.
Definition: byte_util.hpp:782
lb_endian_t
Simplified reduced endian type only covering little- and big-endian.
Definition: byte_util.hpp:227
std::string to_string(const endian_t v) noexcept
Return std::string representation of the given endian.
constexpr void put_uint64(uint8_t *buffer, const uint64_t &v) noexcept
See put_uint16() for reference.
Definition: byte_util.hpp:716
constexpr void put_uint16(uint8_t *buffer, const uint16_t v) noexcept
Put the given uint16_t value into the given byte address using packed_t to resolve a potential memory...
Definition: byte_util.hpp:638
constexpr void put_uint128(uint8_t *buffer, const uint128dp_t &v) noexcept
See put_uint16() for reference.
Definition: byte_util.hpp:749
constexpr uint64_t get_uint64(uint8_t const *buffer) noexcept
See get_uint16() for reference.
Definition: byte_util.hpp:732
constexpr int8_t get_int8(uint8_t const *buffer) noexcept
Definition: byte_util.hpp:615
std::string to_string(const alphabet &v) noexcept
Definition: base_codec.hpp:97
constexpr T min(const T x, const T y) noexcept
Returns the minimum of two integrals (w/ branching) in O(1)
Definition: base_math.hpp:177
uint_fast32_t nsize_t
Natural 'size_t' alternative using uint_fast32_t as its natural sized type.
Definition: int_types.hpp:53
constexpr T max(const T x, const T y) noexcept
Returns the maximum of two integrals (w/ branching) in O(1)
Definition: base_math.hpp:191
uuid128_t get_uuid128(uint8_t const *buffer) noexcept
Definition: uuid.hpp:258
std::string bytesHexString(const void *data, const nsize_t offset, const nsize_t length, const bool lsbFirst, const bool lowerCase=true) noexcept
Produce a hexadecimal string representation of the given byte values.
__pack(...): Produces MSVC, clang and gcc compatible lead-in and -out macros.
Definition: backtrace.hpp:32
STL namespace.
#define JAU_TRACE_OCTETS_PRINT(...)
Definition: octets.hpp:48
A packed 48 bit EUI-48 identifier, formerly known as MAC-48 or simply network device MAC address (Med...
Definition: eui48.hpp:324
uint8_t b[6]
Definition: eui48.hpp:324
jau::nsize_t put(uint8_t *const sink, const lb_endian_t byte_order) const noexcept
Definition: eui48.cpp:241
A 128-bit packed uint8_t data array.
Definition: int_types.hpp:114
A 196-bit packed uint8_t data array.
Definition: int_types.hpp:136
A 256-bit packed uint8_t data array.
Definition: int_types.hpp:158