Embedded Template Library 1.0
Loading...
Searching...
No Matches
byte_stream.h
Go to the documentation of this file.
1
2
3/******************************************************************************
4The MIT License(MIT)
5
6Embedded Template Library.
7https://github.com/ETLCPP/etl
8https://www.etlcpp.com
9
10Copyright(c) 2021 John Wellbelove
11
12Permission is hereby granted, free of charge, to any person obtaining a copy
13of this software and associated documentation files(the "Software"), to deal
14in the Software without restriction, including without limitation the rights
15to use, copy, modify, merge, publish, distribute, sublicense, and / or sell
16copies of the Software, and to permit persons to whom the Software is
17furnished to do so, subject to the following conditions :
18
19The above copyright notice and this permission notice shall be included in all
20copies or substantial portions of the Software.
21
22THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
23IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
24FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE
25AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
26LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
27OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
28SOFTWARE.
29******************************************************************************/
30
31#ifndef ETL_BYTE_STREAM_INCLUDED
32#define ETL_BYTE_STREAM_INCLUDED
33
34#include "platform.h"
35#include "algorithm.h"
36#include "delegate.h"
37#include "endianness.h"
38#include "error_handler.h"
39#include "exception.h"
40#include "integral_limits.h"
41#include "iterator.h"
42#include "memory.h"
43#include "optional.h"
44#include "span.h"
45#include "type_traits.h"
46
47#include <stddef.h>
48
49namespace etl
50{
51 //***************************************************************************
53 //***************************************************************************
55 {
56 public:
57
58 typedef char* iterator;
59 typedef const char* const_iterator;
60 typedef etl::span<char> callback_parameter_type;
61 typedef etl::delegate<void(callback_parameter_type)> callback_type;
62
63 //***************************************************************************
65 //***************************************************************************
66 byte_stream_writer(etl::span<char> span_, etl::endian stream_endianness_, callback_type callback_ = callback_type())
67 : pdata(span_.begin())
68 , pcurrent(span_.begin())
69 , stream_length(span_.size_bytes())
70 , stream_endianness(stream_endianness_)
71 , callback(callback_)
72 {
73 }
74
75 //***************************************************************************
77 //***************************************************************************
78 byte_stream_writer(etl::span<unsigned char> span_, etl::endian stream_endianness_, callback_type callback_ = callback_type())
79 : pdata(reinterpret_cast<char*>(span_.begin()))
80 , pcurrent(reinterpret_cast<char*>(span_.begin()))
81 , stream_length(span_.size_bytes())
82 , stream_endianness(stream_endianness_)
83 , callback(callback_)
84 {
85 }
86
87 //***************************************************************************
89 //***************************************************************************
90 byte_stream_writer(void* begin_, void* end_, etl::endian stream_endianness_, callback_type callback_ = callback_type())
91 : pdata(reinterpret_cast<char*>(begin_))
92 , pcurrent(reinterpret_cast<char*>(begin_))
93 , stream_length(static_cast<size_t>(etl::distance(reinterpret_cast<char*>(begin_), reinterpret_cast<char*>(end_))))
94 , stream_endianness(stream_endianness_)
95 , callback(callback_)
96 {
97 }
98
99 //***************************************************************************
101 //***************************************************************************
102 byte_stream_writer(void* begin_, size_t length_, etl::endian stream_endianness_, callback_type callback_ = callback_type())
103 : pdata(reinterpret_cast<char*>(begin_))
104 , pcurrent(reinterpret_cast<char*>(begin_))
105 , stream_length(length_)
106 , stream_endianness(stream_endianness_)
107 , callback(callback_)
108 {
109 }
110
111 //***************************************************************************
113 //***************************************************************************
114 template <typename T, size_t Size>
115 byte_stream_writer(T (&begin_)[Size], etl::endian stream_endianness_, callback_type callback_ = callback_type())
116 : pdata(begin_)
117 , pcurrent(begin_)
118 , stream_length(begin_ + (Size * sizeof(T)))
119 , stream_endianness(stream_endianness_)
120 , callback(callback_)
121 {
122 }
123
124 //***************************************************************************
126 //***************************************************************************
127 void write_unchecked(bool value)
128 {
129 *pcurrent++ = value ? 1 : 0;
130 }
131
132 //***************************************************************************
134 //***************************************************************************
135 bool write(bool value)
136 {
137 bool success = (available<bool>() > 0U);
138
139 if (success)
140 {
141 write_unchecked(value);
142 }
143
144 return success;
145 }
146
147 //***************************************************************************
149 //***************************************************************************
150 template <typename T>
151 typename etl::enable_if<etl::is_integral<T>::value || etl::is_floating_point<T>::value, void>::type write_unchecked(T value)
152 {
153 to_bytes<T>(value);
154 }
155
156 //***************************************************************************
158 //***************************************************************************
159 template <typename T>
160 typename etl::enable_if<etl::is_integral<T>::value || etl::is_floating_point<T>::value, bool>::type write(T value)
161 {
162 bool success = (available<T>() > 0U);
163
164 if (success)
165 {
166 write_unchecked(value);
167 }
168
169 return success;
170 }
171
172 //***************************************************************************
174 //***************************************************************************
175 template <typename T>
176 typename etl::enable_if<etl::is_integral<T>::value || etl::is_floating_point<T>::value, void>::type write_unchecked(const etl::span<T>& range)
177 {
178 typename etl::span<T>::iterator itr = range.begin();
179
180 while (itr != range.end())
181 {
182 to_bytes(*itr);
183 ++itr;
184 }
185 }
186
187 //***************************************************************************
189 //***************************************************************************
190 template <typename T>
191 typename etl::enable_if<etl::is_integral<T>::value || etl::is_floating_point<T>::value, bool>::type write(const etl::span<T>& range)
192 {
193 bool success = (available<T>() >= range.size());
194
195 if (success)
196 {
197 write_unchecked(range);
198 }
199
200 return success;
201 }
202
203 //***************************************************************************
205 //***************************************************************************
206 template <typename T>
207 typename etl::enable_if<etl::is_integral<T>::value || etl::is_floating_point<T>::value, void>::type write_unchecked(const T* start, size_t length)
208 {
209 while (length-- != 0U)
210 {
211 to_bytes(*start);
212 ++start;
213 }
214 }
215
216 //***************************************************************************
218 //***************************************************************************
219 template <typename T>
220 typename etl::enable_if<etl::is_integral<T>::value || etl::is_floating_point<T>::value, bool>::type write(const T* start, size_t length)
221 {
222 bool success = (available<T>() >= length);
223
224 if (success)
225 {
226 write_unchecked(start, length);
227 }
228
229 return success;
230 }
231
232 //***************************************************************************
236 //***************************************************************************
237 template <typename T>
238 bool skip(size_t n)
239 {
240 bool success = (available<T>() >= n);
241
242 if (success)
243 {
244 step(n * sizeof(T));
245 }
246
247 return success;
248 }
249
250 //***************************************************************************
252 //***************************************************************************
253 void restart(size_t n = 0U)
254 {
255 pcurrent = pdata + n;
256 }
257
258 //***************************************************************************
260 //***************************************************************************
261 iterator begin()
262 {
263 return pdata;
264 }
265
266 //***************************************************************************
268 //***************************************************************************
269 const_iterator begin() const
270 {
271 return pdata;
272 }
273
274 //***************************************************************************
276 //***************************************************************************
277 iterator end()
278 {
279 return pcurrent;
280 }
281
282 //***************************************************************************
284 //***************************************************************************
285 const_iterator end() const
286 {
287 return pcurrent;
288 }
289
290 //***************************************************************************
292 //***************************************************************************
293 const_iterator cbegin() const
294 {
295 return pdata;
296 }
297
298 //***************************************************************************
300 //***************************************************************************
301 const_iterator cend() const
302 {
303 return pcurrent;
304 }
305
306 //***************************************************************************
308 //***************************************************************************
310 {
311 return etl::span<char>(pdata, pcurrent);
312 }
313
314 //***************************************************************************
316 //***************************************************************************
318 {
319 return etl::span<const char>(pdata, pcurrent);
320 }
321
322 //***************************************************************************
324 //***************************************************************************
326 {
327 return etl::span<char>(pcurrent, pdata + stream_length);
328 }
329
330 //***************************************************************************
332 //***************************************************************************
334 {
335 return etl::span<const char>(pcurrent, pdata + stream_length);
336 }
337
338 //***************************************************************************
340 //***************************************************************************
342 {
343 return etl::span<char>(pdata, pdata + stream_length);
344 }
345
346 //***************************************************************************
348 //***************************************************************************
350 {
351 return etl::span<const char>(pdata, pdata + stream_length);
352 }
353
354 //***************************************************************************
356 //***************************************************************************
357 bool full() const
358 {
359 return size_bytes() == capacity();
360 }
361
362 //***************************************************************************
364 //***************************************************************************
365 bool empty() const
366 {
367 return size_bytes() == 0U;
368 }
369
370 //***************************************************************************
372 //***************************************************************************
373 size_t size_bytes() const
374 {
375 return static_cast<size_t>(etl::distance(pdata, pcurrent));
376 }
377
378 //***************************************************************************
380 //***************************************************************************
381 size_t capacity() const
382 {
383 return stream_length;
384 }
385
386 //***************************************************************************
388 //***************************************************************************
389 template <typename T>
390 size_t available() const
391 {
392 return (capacity() - size_bytes()) / sizeof(T);
393 }
394
395 //***************************************************************************
397 //***************************************************************************
398 size_t available_bytes() const
399 {
400 return available<char>();
401 }
402
403 //***************************************************************************
405 //***************************************************************************
406 void set_callback(callback_type callback_)
407 {
408 callback = callback_;
409 }
410
411 //***************************************************************************
413 //***************************************************************************
414 callback_type get_callback() const
415 {
416 return callback;
417 }
418
419 //***************************************************************************
421 //***************************************************************************
423 {
424 return stream_endianness;
425 }
426
427 private:
428
429 //***************************************************************************
431 //***************************************************************************
432 template <typename T>
433 typename etl::enable_if<sizeof(T) == 1U, void>::type to_bytes(const T value)
434 {
435 *pcurrent = static_cast<char>(value);
436 step(1U);
437 }
438
439 //*********************************
440 template <typename T>
441 typename etl::enable_if<sizeof(T) != 1U, void>::type to_bytes(const T value)
442 {
443 const char* pv = reinterpret_cast<const char*>(&value);
444 copy_value(pv, pcurrent, sizeof(T));
445 step(sizeof(T));
446 }
447
448 //*********************************
449 void step(size_t n)
450 {
451 callback.call_if(etl::span<char>(pcurrent, pcurrent + n));
452
453 pcurrent += n;
454 }
455
456 //*********************************
457 void copy_value(const char* source, char* destination, size_t length) const
458 {
459 const etl::endian platform_endianness = etl::endianness::value();
460
461 if (stream_endianness == platform_endianness)
462 {
463 etl::copy(source, source + length, destination);
464 }
465 else
466 {
467 etl::reverse_copy(source, source + length, destination);
468 }
469 }
470
471 char* const pdata;
472 char* pcurrent;
473 const size_t stream_length;
474 const etl::endian stream_endianness;
475 callback_type callback;
476 };
477
478 //***************************************************************************
481 //***************************************************************************
483 {
484 public:
485
486 typedef char* iterator;
487 typedef const char* const_iterator;
488
489 //***************************************************************************
491 //***************************************************************************
493 : pdata(span_.begin())
494 , pcurrent(span_.begin())
495 , stream_length(span_.size_bytes())
496 , stream_endianness(stream_endianness_)
497 {
498 }
499
500 //***************************************************************************
502 //***************************************************************************
504 : pdata(span_.begin())
505 , pcurrent(span_.begin())
506 , stream_length(span_.size_bytes())
507 , stream_endianness(stream_endianness_)
508 {
509 }
510
511 //***************************************************************************
513 //***************************************************************************
514 byte_stream_reader(const void* begin_, const void* end_, etl::endian stream_endianness_)
515 : pdata(reinterpret_cast<const char*>(begin_))
516 , pcurrent(reinterpret_cast<const char*>(begin_))
517 , stream_length(static_cast<size_t>(etl::distance(reinterpret_cast<const char*>(begin_), reinterpret_cast<const char*>(end_))))
518 , stream_endianness(stream_endianness_)
519 {
520 }
521
522 //***************************************************************************
524 //***************************************************************************
525 byte_stream_reader(const void* begin_, size_t length_, etl::endian stream_endianness_)
526 : pdata(reinterpret_cast<const char*>(begin_))
527 , pcurrent(reinterpret_cast<const char*>(begin_))
528 , stream_length(length_)
529 , stream_endianness(stream_endianness_)
530 {
531 }
532
533 //***************************************************************************
535 //***************************************************************************
536 template <typename T, size_t Size>
537 byte_stream_reader(T (&begin_)[Size], etl::endian stream_endianness_)
538 : pdata(begin_)
539 , pcurrent(begin_)
540 , stream_length(begin_ + (Size * sizeof(T)))
541 , stream_endianness(stream_endianness_)
542 {
543 }
544
545 //***************************************************************************
547 //***************************************************************************
548 template <typename T, size_t Size>
549 byte_stream_reader(const T (&begin_)[Size], etl::endian stream_endianness_)
550 : pdata(begin_)
551 , pcurrent(begin_)
552 , stream_length(begin_ + (Size * sizeof(T)))
553 , stream_endianness(stream_endianness_)
554 {
555 }
556
557 //***************************************************************************
559 //***************************************************************************
560 template <typename T>
561 typename etl::enable_if< etl::is_integral<T>::value || etl::is_floating_point<T>::value, T>::type read_unchecked()
562 {
563 return from_bytes<T>();
564 }
565
566 //***************************************************************************
568 //***************************************************************************
569 template <typename T>
570 typename etl::enable_if<etl::is_integral<T>::value || etl::is_floating_point<T>::value, etl::optional<T> >::type read()
571 {
572 etl::optional<T> result;
573
574 // Do we have enough room?
575 if (available<T>() > 0U)
576 {
577 result = read_unchecked<T>();
578 }
579
580 return result;
581 }
582
583 //***************************************************************************
585 //***************************************************************************
586 template <typename T>
587 typename etl::enable_if<sizeof(T) == 1U, etl::span<const T> >::type read_unchecked(size_t n)
588 {
589 etl::span<const T> result;
590
591 const char* pend = pcurrent + (n * sizeof(T));
592
593 result = etl::span<const T>(reinterpret_cast<const T*>(pcurrent), reinterpret_cast<const T*>(pend));
594 pcurrent = pend;
595
596 return result;
597 }
598
599 //***************************************************************************
601 //***************************************************************************
602 template <typename T>
603 typename etl::enable_if<sizeof(T) == 1U, etl::optional<etl::span<const T> > >::type read(size_t n)
604 {
606
607 // Do we have enough room?
608 if (available<T>() >= n)
609 {
610 result = read_unchecked<T>(n);
611 }
612
613 return result;
614 }
615
616 //***************************************************************************
618 //***************************************************************************
619 template <typename T>
620 typename etl::enable_if<etl::is_integral<T>::value || etl::is_floating_point<T>::value, etl::span<const T> >::type
622 {
623 typename etl::span<T>::iterator destination = range.begin();
624
625 while (destination != range.end())
626 {
627 *destination++ = from_bytes<T>();
628 }
629
630 return etl::span<const T>(range.begin(), range.end());
631 }
632
633 //***************************************************************************
635 //***************************************************************************
636 template <typename T>
637 typename etl::enable_if<etl::is_integral<T>::value || etl::is_floating_point<T>::value, etl::optional<etl::span<const T> > >::type
639 {
640 // Do we have enough room?
641 if (available<T>() >= range.size())
642 {
644 }
645
647 }
648
649 //***************************************************************************
651 //***************************************************************************
652 template <typename T>
653 typename etl::enable_if<etl::is_integral<T>::value || etl::is_floating_point<T>::value, etl::span<const T> >::type read_unchecked(T* start,
654 size_t length)
655 {
656 T* destination = start;
657
658 for (size_t i = 0; i < length; ++i)
659 {
660 *destination++ = from_bytes<T>();
661 }
662
663 return etl::span<const T>(start, length);
664 }
665
666 //***************************************************************************
668 //***************************************************************************
669 template <typename T>
670 typename etl::enable_if<etl::is_integral<T>::value || etl::is_floating_point<T>::value, etl::optional<etl::span<const T> > >::type
671 read(T* start, size_t length)
672 {
673 // Do we have enough room?
674 if (available<T>() >= length)
675 {
677 }
678
680 }
681
682 //***************************************************************************
686 //***************************************************************************
687 template <typename T>
688 bool skip(size_t n)
689 {
690 if (n <= available<T>())
691 {
692 pcurrent += (n * sizeof(T));
693 return true;
694 }
695 else
696 {
697 return false;
698 }
699 }
700
701 //***************************************************************************
703 //***************************************************************************
704 void restart(size_t n = 0U)
705 {
706 pcurrent = pdata + n;
707 }
708
709 //***************************************************************************
711 //***************************************************************************
712 const_iterator begin() const
713 {
714 return pdata;
715 }
716
717 //***************************************************************************
719 //***************************************************************************
720 const_iterator end() const
721 {
722 return pcurrent;
723 }
724
725 //***************************************************************************
727 //***************************************************************************
728 const_iterator cbegin() const
729 {
730 return pdata;
731 }
732
733 //***************************************************************************
735 //***************************************************************************
736 const_iterator cend() const
737 {
738 return pcurrent;
739 }
740
741 //***************************************************************************
743 //***************************************************************************
745 {
746 return etl::span<const char>(pdata, pcurrent);
747 }
748
749 //***************************************************************************
751 //***************************************************************************
753 {
754 return etl::span<const char>(pcurrent, pdata + stream_length);
755 }
756
757 //***************************************************************************
759 //***************************************************************************
761 {
762 return etl::span<const char>(pdata, pdata + stream_length);
763 }
764
765 //***************************************************************************
767 //***************************************************************************
768 bool empty() const
769 {
770 return available<char>() == 0U;
771 }
772
773 //***************************************************************************
775 //***************************************************************************
776 size_t size_bytes() const
777 {
778 return stream_length;
779 }
780
781 //***************************************************************************
783 //***************************************************************************
784 template <typename T>
785 size_t available() const
786 {
787 size_t used = static_cast<size_t>(etl::distance(pdata, pcurrent));
788
789 return (stream_length - used) / sizeof(T);
790 }
791
792 //***************************************************************************
794 //***************************************************************************
795 size_t available_bytes() const
796 {
797 return available<char>();
798 }
799
800 //***************************************************************************
802 //***************************************************************************
804 {
805 return stream_endianness;
806 }
807
808 private:
809
810 //***************************************************************************
812 //***************************************************************************
813 template <typename T>
814 typename etl::enable_if<sizeof(T) == 1U, T>::type from_bytes()
815 {
816 return static_cast<T>(*pcurrent++);
817 }
818
819 //*********************************
820 template <typename T>
821 typename etl::enable_if<sizeof(T) != 1U, T>::type from_bytes()
822 {
823 T value;
824
825 char* pv = reinterpret_cast<char*>(&value);
826 copy_value(pcurrent, pv, sizeof(T));
827 pcurrent += sizeof(T);
828
829 return value;
830 }
831
832 //*********************************
833 void copy_value(const char* source, char* destination, size_t length) const
834 {
835 const etl::endian platform_endianness = etl::endianness::value();
836
837 if (stream_endianness == platform_endianness)
838 {
839 etl::copy(source, source + length, destination);
840 }
841 else
842 {
843 etl::reverse_copy(source, source + length, destination);
844 }
845 }
846
847 const char* const pdata;
848 const char* pcurrent;
849 const size_t stream_length;
850 const etl::endian stream_endianness;
851 };
852
853 //***************************************************************************
857 //***************************************************************************
858 template <typename T>
859 void write_unchecked(etl::byte_stream_writer& stream, const T& value)
860 {
861 stream.write_unchecked(value);
862 }
863
864 //***************************************************************************
866 //***************************************************************************
867 template <typename T>
868 bool write(etl::byte_stream_writer& stream, const T& value)
869 {
870 return stream.write(value);
871 }
872
873 //***************************************************************************
877 //***************************************************************************
878 template <typename T>
880 {
881 return stream.read_unchecked<T>();
882 }
883
884 //***************************************************************************
886 //***************************************************************************
887 template <typename T>
889 {
890 return stream.read<T>();
891 }
892} // namespace etl
893
894#endif
Definition byte_stream.h:483
const_iterator cbegin() const
Returns start of the stream.
Definition byte_stream.h:728
byte_stream_reader(etl::span< const char > span_, etl::endian stream_endianness_)
Construct from span.
Definition byte_stream.h:503
bool empty() const
Returns true if the byte stream is empty.
Definition byte_stream.h:768
etl::enable_if< sizeof(T)==1U, etl::optional< etl::span< constT > > >::type read(size_t n)
Read a byte range from the stream.
Definition byte_stream.h:603
etl::enable_if< sizeof(T)==1U, etl::span< constT > >::type read_unchecked(size_t n)
Read a byte range from the stream.
Definition byte_stream.h:587
etl::enable_if< etl::is_integral< T >::value||etl::is_floating_point< T >::value, etl::optional< etl::span< constT > > >::type read(T *start, size_t length)
Read a range of T from the stream.
Definition byte_stream.h:671
etl::enable_if< etl::is_integral< T >::value||etl::is_floating_point< T >::value, etl::span< constT > >::type read_unchecked(etl::span< T > range)
Read a range of T from the stream.
Definition byte_stream.h:621
byte_stream_reader(const T(&begin_)[Size], etl::endian stream_endianness_)
Construct from const array.
Definition byte_stream.h:549
const_iterator begin() const
Returns start of the stream.
Definition byte_stream.h:712
const_iterator cend() const
Returns end of the stream.
Definition byte_stream.h:736
etl::span< const char > used_data() const
Returns a span of the used portion of the stream.
Definition byte_stream.h:744
size_t available_bytes() const
The number of bytes left in the stream.
Definition byte_stream.h:795
etl::enable_if< etl::is_integral< T >::value||etl::is_floating_point< T >::value, etl::optional< etl::span< constT > > >::type read(etl::span< T > range)
Read a range of T from the stream.
Definition byte_stream.h:638
size_t available() const
The number of T left in the stream.
Definition byte_stream.h:785
byte_stream_reader(etl::span< char > span_, etl::endian stream_endianness_)
Construct from span.
Definition byte_stream.h:492
size_t size_bytes() const
Returns the number of bytes used in the stream.
Definition byte_stream.h:776
etl::enable_if< etl::is_integral< T >::value||etl::is_floating_point< T >::value, etl::span< constT > >::type read_unchecked(T *start, size_t length)
Read a range of T from the stream.
Definition byte_stream.h:653
etl::enable_if< etl::is_integral< T >::value||etl::is_floating_point< T >::value, T >::type read_unchecked()
Read a value from the stream.
Definition byte_stream.h:561
etl::span< const char > data() const
Returns a span of whole the stream.
Definition byte_stream.h:760
etl::span< const char > free_data() const
Returns a span of the free portion of the stream.
Definition byte_stream.h:752
bool skip(size_t n)
Definition byte_stream.h:688
void restart(size_t n=0U)
Sets the index back to the position in the stream. Default = 0.
Definition byte_stream.h:704
byte_stream_reader(const void *begin_, size_t length_, etl::endian stream_endianness_)
Construct from begin and length.
Definition byte_stream.h:525
byte_stream_reader(T(&begin_)[Size], etl::endian stream_endianness_)
Construct from array.
Definition byte_stream.h:537
etl::endian get_endianness() const
Gets the endianness of the stream.
Definition byte_stream.h:803
const_iterator end() const
Returns end of the stream.
Definition byte_stream.h:720
etl::enable_if< etl::is_integral< T >::value||etl::is_floating_point< T >::value, etl::optional< T > >::type read()
Read a value from the stream.
Definition byte_stream.h:570
byte_stream_reader(const void *begin_, const void *end_, etl::endian stream_endianness_)
Construct from range.
Definition byte_stream.h:514
Encodes a byte stream.
Definition byte_stream.h:55
byte_stream_writer(etl::span< unsigned char > span_, etl::endian stream_endianness_, callback_type callback_=callback_type())
Construct from span.
Definition byte_stream.h:78
etl::enable_if< etl::is_integral< T >::value||etl::is_floating_point< T >::value, void >::type write_unchecked(const T *start, size_t length)
Write a range of T to the stream.
Definition byte_stream.h:207
const_iterator cbegin() const
Returns start of the stream.
Definition byte_stream.h:293
etl::span< char > data()
Returns a span of whole the stream.
Definition byte_stream.h:341
const_iterator end() const
Returns end of the stream.
Definition byte_stream.h:285
etl::span< char > free_data()
Returns a span of the free portion of the stream.
Definition byte_stream.h:325
byte_stream_writer(void *begin_, size_t length_, etl::endian stream_endianness_, callback_type callback_=callback_type())
Construct from begin and length.
Definition byte_stream.h:102
etl::enable_if< etl::is_integral< T >::value||etl::is_floating_point< T >::value, bool >::type write(const etl::span< T > &range)
Write a range of T to the stream.
Definition byte_stream.h:191
iterator begin()
Returns start of the stream.
Definition byte_stream.h:261
byte_stream_writer(T(&begin_)[Size], etl::endian stream_endianness_, callback_type callback_=callback_type())
Construct from array.
Definition byte_stream.h:115
void restart(size_t n=0U)
Sets the index back to the position in the stream. Default = 0.
Definition byte_stream.h:253
byte_stream_writer(void *begin_, void *end_, etl::endian stream_endianness_, callback_type callback_=callback_type())
Construct from range.
Definition byte_stream.h:90
bool write(bool value)
Writes a boolean to the stream.
Definition byte_stream.h:135
void write_unchecked(bool value)
Writes a boolean to the stream.
Definition byte_stream.h:127
etl::endian get_endianness() const
Gets the endianness of the stream.
Definition byte_stream.h:422
void set_callback(callback_type callback_)
Sets the function to call after every write.
Definition byte_stream.h:406
etl::enable_if< etl::is_integral< T >::value||etl::is_floating_point< T >::value, void >::type write_unchecked(T value)
Write a value to the stream.
Definition byte_stream.h:151
etl::span< char > used_data()
Returns a span of the used portion of the stream.
Definition byte_stream.h:309
iterator end()
Returns end of the stream.
Definition byte_stream.h:277
etl::enable_if< etl::is_integral< T >::value||etl::is_floating_point< T >::value, bool >::type write(const T *start, size_t length)
Write a range of T to the stream.
Definition byte_stream.h:220
bool empty() const
Returns true if the byte stream is empty.
Definition byte_stream.h:365
byte_stream_writer(etl::span< char > span_, etl::endian stream_endianness_, callback_type callback_=callback_type())
Construct from span.
Definition byte_stream.h:66
const_iterator cend() const
Returns end of the stream.
Definition byte_stream.h:301
bool skip(size_t n)
Definition byte_stream.h:238
size_t available_bytes() const
The number of bytes left in the stream.
Definition byte_stream.h:398
etl::enable_if< etl::is_integral< T >::value||etl::is_floating_point< T >::value, bool >::type write(T value)
Write a value to the stream.
Definition byte_stream.h:160
size_t available() const
The number of T left in the stream.
Definition byte_stream.h:390
etl::span< const char > data() const
Returns a span of whole the stream.
Definition byte_stream.h:349
etl::span< const char > used_data() const
Returns a span of the used portion of the stream.
Definition byte_stream.h:317
callback_type get_callback() const
Gets the function to call after every write.
Definition byte_stream.h:414
etl::enable_if< etl::is_integral< T >::value||etl::is_floating_point< T >::value, void >::type write_unchecked(const etl::span< T > &range)
Write a range of T to the stream.
Definition byte_stream.h:176
size_t capacity() const
Returns the maximum number of bytes in the stream.
Definition byte_stream.h:381
etl::span< const char > free_data() const
Returns a span of the free portion of the stream.
Definition byte_stream.h:333
const_iterator begin() const
Returns start of the stream.
Definition byte_stream.h:269
size_t size_bytes() const
Returns the number of bytes used in the stream.
Definition byte_stream.h:373
bool full() const
Returns true if the byte stream index has reached the end.
Definition byte_stream.h:357
Declaration.
Definition delegate_cpp03.h:191
Span - Fixed Extent.
Definition span.h:208
ETL_NODISCARD ETL_CONSTEXPR iterator begin() const ETL_NOEXCEPT
Returns an iterator to the beginning of the span.
Definition span.h:484
ETL_NODISCARD ETL_CONSTEXPR size_t size() const ETL_NOEXCEPT
Returns the size of the span.
Definition span.h:564
ETL_NODISCARD ETL_CONSTEXPR iterator end() const ETL_NOEXCEPT
Returns an iterator to the end of the span.
Definition span.h:508
Definition endianness.h:100
Definition optional.h:1238
Definition absolute.h:40
etl::optional< T > read(etl::bit_stream_reader &stream)
Read a checked type from a stream.
Definition bit_stream.h:1430
void write_unchecked(etl::bit_stream_writer &stream, bool value)
Definition bit_stream.h:1026
T read_unchecked(etl::bit_stream_reader &stream)
Read an unchecked type from a stream.
Definition bit_stream.h:1415
bool write(etl::bit_stream_writer &stream, bool value)
Definition bit_stream.h:1035