Embedded Template Library 1.0
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 "type_traits.h"
36#include "nullptr.h"
37#include "endianness.h"
38#include "integral_limits.h"
39#include "algorithm.h"
40#include "iterator.h"
41#include "memory.h"
42#include "span.h"
43#include "iterator.h"
44#include "optional.h"
45#include "delegate.h"
46#include "exception.h"
47#include "error_handler.h"
48
49#include <stdint.h>
50#include <limits.h>
51
52namespace etl
53{
54 //***************************************************************************
56 //***************************************************************************
58 {
59 public:
60
61 typedef char* iterator;
62 typedef const char* const_iterator;
65
66 //***************************************************************************
68 //***************************************************************************
70 : pdata(span_.begin())
71 , pcurrent(span_.begin())
72 , length(span_.size_bytes())
73 , stream_endianness(stream_endianness_)
74 , callback(callback_)
75 {
76 }
77
78 //***************************************************************************
80 //***************************************************************************
82 : pdata(reinterpret_cast<char*>(span_.begin()))
83 , pcurrent(reinterpret_cast<char*>(span_.begin()))
84 , length(span_.size_bytes())
85 , stream_endianness(stream_endianness_)
86 , callback(callback_)
87 {
88 }
89
90 //***************************************************************************
92 //***************************************************************************
93 byte_stream_writer(void* begin_, void* end_, etl::endian stream_endianness_, callback_type callback_ = callback_type())
94 : pdata(reinterpret_cast<char*>(begin_))
95 , pcurrent(reinterpret_cast<char*>(begin_))
96 , length(etl::distance(reinterpret_cast<char*>(begin_), reinterpret_cast<char*>(end_)))
97 , stream_endianness(stream_endianness_)
98 , callback(callback_)
99 {
100 }
101
102 //***************************************************************************
104 //***************************************************************************
105 byte_stream_writer(void* begin_, size_t length_, etl::endian stream_endianness_, callback_type callback_ = callback_type())
106 : pdata(reinterpret_cast<char*>(begin_))
107 , pcurrent(reinterpret_cast<char*>(begin_))
108 , length(length_)
109 , stream_endianness(stream_endianness_)
110 , callback(callback_)
111 {
112 }
113
114 //***************************************************************************
116 //***************************************************************************
117 template <typename T, size_t Size>
118 byte_stream_writer(T(&begin_)[Size], etl::endian stream_endianness_, callback_type callback_ = callback_type())
119 : pdata(begin_)
120 , pcurrent(begin_)
121 , length(begin_ + (Size * sizeof(T)))
122 , stream_endianness(stream_endianness_)
123 , callback(callback_)
124 {
125 }
126
127 //***************************************************************************
129 //***************************************************************************
130 void write_unchecked(bool value)
131 {
132 *pcurrent++ = value ? 1 : 0;
133 }
134
135 //***************************************************************************
137 //***************************************************************************
138 bool write(bool value)
139 {
140 bool success = (available<bool>() > 0U);
141
142 if (success)
143 {
144 write_unchecked(value);
145 }
146
147 return success;
148 }
149
150 //***************************************************************************
152 //***************************************************************************
153 template <typename T>
156 {
157 to_bytes<T>(value);
158 }
159
160 //***************************************************************************
162 //***************************************************************************
163 template <typename T>
165 write(T value)
166 {
167 bool success = (available<T>() > 0U);
168
169 if (success)
170 {
171 write_unchecked(value);
172 }
173
174 return success;
175 }
176
177 //***************************************************************************
179 //***************************************************************************
180 template <typename T>
183 {
184 typename etl::span<T>::iterator itr = range.begin();
185
186 while (itr != range.end())
187 {
188 to_bytes(*itr);
189 ++itr;
190 }
191 }
192
193 //***************************************************************************
195 //***************************************************************************
196 template <typename T>
198 write(const etl::span<T>& range)
199 {
200 bool success = (available<T>() >= range.size());
201
202 if (success)
203 {
204 write_unchecked(range);
205 }
206
207 return success;
208 }
209
210 //***************************************************************************
212 //***************************************************************************
213 template <typename T>
215 write_unchecked(const T* start, size_t length)
216 {
217 while (length-- != 0U)
218 {
219 to_bytes(*start);
220 ++start;
221 }
222 }
223
224 //***************************************************************************
226 //***************************************************************************
227 template <typename T>
229 write(const T* start, size_t length)
230 {
231 bool success = (available<T>() >= length);
232
233 if (success)
234 {
235 write_unchecked(start, length);
236 }
237
238 return success;
239 }
240
241 //***************************************************************************
245 //***************************************************************************
246 template <typename T>
247 bool skip(size_t n)
248 {
249 bool success = (available<T>() >= n);
250
251 if (success)
252 {
253 step(n * sizeof(T));
254 }
255
256 return success;
257 }
258
259 //***************************************************************************
261 //***************************************************************************
262 void restart(size_t n = 0U)
263 {
264 pcurrent = const_cast<char*>(pdata + n);
265 }
266
267 //***************************************************************************
269 //***************************************************************************
270 iterator begin()
271 {
272 return pdata;
273 }
274
275 //***************************************************************************
277 //***************************************************************************
278 const_iterator begin() const
279 {
280 return pdata;
281 }
282
283 //***************************************************************************
285 //***************************************************************************
286 iterator end()
287 {
288 return pcurrent;
289 }
290
291 //***************************************************************************
293 //***************************************************************************
294 const_iterator end() const
295 {
296 return pcurrent;
297 }
298
299 //***************************************************************************
301 //***************************************************************************
302 const_iterator cbegin() const
303 {
304 return pdata;
305 }
306
307 //***************************************************************************
309 //***************************************************************************
310 const_iterator cend() const
311 {
312 return pcurrent;
313 }
314
315 //***************************************************************************
317 //***************************************************************************
319 {
320 return etl::span<char>(pdata, pcurrent);
321 }
322
323 //***************************************************************************
325 //***************************************************************************
327 {
328 return etl::span<const char>(pdata, pcurrent);
329 }
330
331 //***************************************************************************
333 //***************************************************************************
335 {
336 return etl::span<char>(pcurrent, pdata + length);
337 }
338
339 //***************************************************************************
341 //***************************************************************************
343 {
344 return etl::span<const char>(pcurrent, pdata + length);
345 }
346
347 //***************************************************************************
349 //***************************************************************************
351 {
352 return etl::span<char>(pdata, pdata + length);
353 }
354
355 //***************************************************************************
357 //***************************************************************************
359 {
360 return etl::span<const char>(pdata, pdata + length);
361 }
362
363 //***************************************************************************
365 //***************************************************************************
366 bool full() const
367 {
368 return size_bytes() == capacity();
369 }
370
371 //***************************************************************************
373 //***************************************************************************
374 bool empty() const
375 {
376 return size_bytes() == 0U;
377 }
378
379 //***************************************************************************
381 //***************************************************************************
382 size_t size_bytes() const
383 {
384 return etl::distance(pdata, pcurrent);
385 }
386
387 //***************************************************************************
389 //***************************************************************************
390 size_t capacity() const
391 {
392 return length;
393 }
394
395 //***************************************************************************
397 //***************************************************************************
398 template <typename T>
399 size_t available() const
400 {
401 return (capacity() - size_bytes()) / sizeof(T);
402 }
403
404 //***************************************************************************
406 //***************************************************************************
407 size_t available_bytes() const
408 {
409 return available<char>();
410 }
411
412 //***************************************************************************
414 //***************************************************************************
416 {
417 callback = callback_;
418 }
419
420 //***************************************************************************
422 //***************************************************************************
424 {
425 return callback;
426 }
427
428 //***************************************************************************
430 //***************************************************************************
432 {
433 return stream_endianness;
434 }
435
436 private:
437
438 //***************************************************************************
440 //***************************************************************************
441 template <typename T>
442 typename etl::enable_if<sizeof(T) == 1U, void>::type
443 to_bytes(const T value)
444 {
445 *pcurrent = static_cast<char>(value);
446 step(1U);
447 }
448
449 //*********************************
450 template <typename T>
451 typename etl::enable_if<sizeof(T) != 1U, void>::type
452 to_bytes(const T value)
453 {
454 const char* pv = reinterpret_cast<const char*>(&value);
455 copy_value(pv, pcurrent, sizeof(T));
456 step(sizeof(T));
457 }
458
459 //*********************************
460 void step(size_t n)
461 {
462 callback.call_if(etl::span<char>(pcurrent, pcurrent + n));
463
464 pcurrent += n;
465 }
466
467 //*********************************
468 void copy_value(const char* source, char* destination, size_t length) const
469 {
470 const etl::endian platform_endianness = etl::endianness::value();
471
472 if (stream_endianness == platform_endianness)
473 {
474 etl::copy(source, source + length, destination);
475 }
476 else
477 {
478 etl::reverse_copy(source, source + length, destination);
479 }
480 }
481
482 char* const pdata;
483 char* pcurrent;
484 const size_t length;
485 const etl::endian stream_endianness;
486 callback_type callback;
487 };
488
489 //***************************************************************************
492 //***************************************************************************
494 {
495 public:
496
497 typedef char* iterator;
498 typedef const char* const_iterator;
499
500 //***************************************************************************
502 //***************************************************************************
504 : pdata(span_.begin())
505 , pcurrent(span_.begin())
506 , length(span_.size_bytes())
507 , stream_endianness(stream_endianness_)
508 {
509 }
510
511 //***************************************************************************
513 //***************************************************************************
515 : pdata(span_.begin())
516 , pcurrent(span_.begin())
517 , length(span_.size_bytes())
518 , stream_endianness(stream_endianness_)
519 {
520 }
521
522 //***************************************************************************
524 //***************************************************************************
525 byte_stream_reader(const void* begin_, const void* end_, etl::endian stream_endianness_)
526 : pdata(reinterpret_cast<const char*>(begin_))
527 , pcurrent(reinterpret_cast<const char*>(begin_))
528 , length(etl::distance(reinterpret_cast<const char*>(begin_), reinterpret_cast<const char*>(end_)))
529 , stream_endianness(stream_endianness_)
530 {
531 }
532
533 //***************************************************************************
535 //***************************************************************************
536 byte_stream_reader(const void* begin_, size_t length_, etl::endian stream_endianness_)
537 : pdata(reinterpret_cast<const char*>(begin_))
538 , pcurrent(reinterpret_cast<const char*>(begin_))
539 , length(length_)
540 , stream_endianness(stream_endianness_)
541 {
542 }
543
544 //***************************************************************************
546 //***************************************************************************
547 template <typename T, size_t Size>
548 byte_stream_reader(T(&begin_)[Size], etl::endian stream_endianness_)
549 : pdata(begin_)
550 , pcurrent(begin_)
551 , length(begin_ + (Size * sizeof(T)))
552 , stream_endianness(stream_endianness_)
553 {
554 }
555
556 //***************************************************************************
558 //***************************************************************************
559 template <typename T, size_t Size>
560 byte_stream_reader(const T(&begin_)[Size], etl::endian stream_endianness_)
561 : pdata(begin_)
562 , pcurrent(begin_)
563 , length(begin_ + (Size * sizeof(T)))
564 , stream_endianness(stream_endianness_)
565 {
566 }
567
568 //***************************************************************************
570 //***************************************************************************
571 template <typename T>
574 {
575 return from_bytes<T>();
576 }
577
578 //***************************************************************************
580 //***************************************************************************
581 template <typename T>
584 {
585 etl::optional<T> result;
586
587 // Do we have enough room?
588 if (available<T>() > 0U)
589 {
590 result = read_unchecked<T>();
591 }
592
593 return result;
594 }
595
596 //***************************************************************************
598 //***************************************************************************
599 template <typename T>
600 typename etl::enable_if<sizeof(T) == 1U, etl::span<const T> >::type
602 {
603 etl::span<const T> result;
604
605 const char* pend = pcurrent + (n * sizeof(T));
606
607 result = etl::span<const T>(reinterpret_cast<const T*>(pcurrent), reinterpret_cast<const T*>(pend));
608 pcurrent = pend;
609
610 return result;
611 }
612
613 //***************************************************************************
615 //***************************************************************************
616 template <typename T>
617 typename etl::enable_if<sizeof(T) == 1U, etl::optional<etl::span<const T> > >::type
618 read(size_t n)
619 {
621
622 // Do we have enough room?
623 if (available<T>() >= n)
624 {
625 result = read_unchecked<T>(n);
626 }
627
628 return result;
629 }
630
631 //***************************************************************************
633 //***************************************************************************
634 template <typename T>
637 {
638 typename etl::span<T>::iterator destination = range.begin();
639
640 while (destination != range.end())
641 {
642 *destination++ = from_bytes<T>();
643 }
644
645 return etl::span<const T>(range.begin(), range.end());
646 }
647
648 //***************************************************************************
650 //***************************************************************************
651 template <typename T>
654 {
655 // Do we have enough room?
656 if (available<T>() >= range.size())
657 {
658 return etl::optional<etl::span<const T> >(read_unchecked<T>(range));
659 }
660
662 }
663
664 //***************************************************************************
666 //***************************************************************************
667 template <typename T>
669 read_unchecked(T* start, size_t length)
670 {
671 T* destination = start;
672
673 for (size_t i = 0; i < length; ++i)
674 {
675 *destination++ = from_bytes<T>();
676 }
677
678 return etl::span<const T>(start, length);
679 }
680
681 //***************************************************************************
683 //***************************************************************************
684 template <typename T>
686 read(T* start, size_t length)
687 {
688 // Do we have enough room?
689 if (available<T>() >= length)
690 {
691 return etl::optional<etl::span<const T> >(read_unchecked<T>(start, length));
692 }
693
695 }
696
697 //***************************************************************************
701 //***************************************************************************
702 template <typename T>
703 bool skip(size_t n)
704 {
705 if (n <= available<T>())
706 {
707 pcurrent += (n * sizeof(T));
708 return true;
709 }
710 else
711 {
712 return false;
713 }
714 }
715
716 //***************************************************************************
718 //***************************************************************************
719 void restart(size_t n = 0U)
720 {
721 pcurrent = pdata + n;
722 }
723
724 //***************************************************************************
726 //***************************************************************************
727 const_iterator begin() const
728 {
729 return pdata;
730 }
731
732 //***************************************************************************
734 //***************************************************************************
735 const_iterator end() const
736 {
737 return pcurrent;
738 }
739
740 //***************************************************************************
742 //***************************************************************************
743 const_iterator cbegin() const
744 {
745 return pdata;
746 }
747
748 //***************************************************************************
750 //***************************************************************************
751 const_iterator cend() const
752 {
753 return pcurrent;
754 }
755
756 //***************************************************************************
758 //***************************************************************************
760 {
761 return etl::span<const char>(pdata, pcurrent);
762 }
763
764 //***************************************************************************
766 //***************************************************************************
768 {
769 return etl::span<const char>(pcurrent, pdata + length);
770 }
771
772 //***************************************************************************
774 //***************************************************************************
776 {
777 return etl::span<const char>(pdata, pdata + length);
778 }
779
780 //***************************************************************************
782 //***************************************************************************
783 bool empty() const
784 {
785 return available<char>() == 0U;
786 }
787
788 //***************************************************************************
790 //***************************************************************************
791 size_t size_bytes() const
792 {
793 return length;
794 }
795
796 //***************************************************************************
798 //***************************************************************************
799 template <typename T>
800 size_t available() const
801 {
802 size_t used = etl::distance(pdata, pcurrent);
803
804 return (length - used) / sizeof(T);
805 }
806
807 //***************************************************************************
809 //***************************************************************************
810 size_t available_bytes() const
811 {
812 return available<char>();
813 }
814
815 private:
816
817 //***************************************************************************
819 //***************************************************************************
820 template <typename T>
821 typename etl::enable_if<sizeof(T) == 1U, T>::type
822 from_bytes()
823 {
824 return static_cast<T>(*pcurrent++);
825 }
826
827 //*********************************
828 template <typename T>
829 typename etl::enable_if<sizeof(T) != 1U, T>::type
830 from_bytes()
831 {
832 T value;
833
834 char* pv = reinterpret_cast<char*>(&value);
835 copy_value(pcurrent, pv, sizeof(T));
836 pcurrent += sizeof(T);
837
838 return value;
839 }
840
841 //*********************************
842 void copy_value(const char* source, char* destination, size_t length) const
843 {
844 const etl::endian platform_endianness = etl::endianness::value();
845
846 if (stream_endianness == platform_endianness)
847 {
848 etl::copy(source, source + length, destination);
849 }
850 else
851 {
852 etl::reverse_copy(source, source + length, destination);
853 }
854 }
855
856 const char* const pdata;
857 const char* pcurrent;
858 const size_t length;
859 const etl::endian stream_endianness;
860 };
861
862 //***************************************************************************
866 //***************************************************************************
867 template <typename T>
868 void write_unchecked(etl::byte_stream_writer& stream, const T& value)
869 {
870 stream.write_unchecked(value);
871 }
872
873 //***************************************************************************
875 //***************************************************************************
876 template <typename T>
877 bool write(etl::byte_stream_writer& stream, const T& value)
878 {
879 return stream.write(value);
880 }
881
882 //***************************************************************************
886 //***************************************************************************
887 template <typename T>
889 {
890 return stream.read_unchecked<T>();
891 }
892
893 //***************************************************************************
895 //***************************************************************************
896 template <typename T>
898 {
899 return stream.read<T>();
900 }
901}
902
903#endif
Definition: byte_stream.h:494
const_iterator cbegin() const
Returns start of the stream.
Definition: byte_stream.h:743
byte_stream_reader(etl::span< const char > span_, etl::endian stream_endianness_)
Construct from span.
Definition: byte_stream.h:514
bool empty() const
Returns true if the byte stream is empty.
Definition: byte_stream.h:783
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:618
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:601
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:686
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:636
byte_stream_reader(const T(&begin_)[Size], etl::endian stream_endianness_)
Construct from const array.
Definition: byte_stream.h:560
const_iterator begin() const
Returns start of the stream.
Definition: byte_stream.h:727
const_iterator cend() const
Returns end of the stream.
Definition: byte_stream.h:751
etl::span< const char > used_data() const
Returns a span of the used portion of the stream.
Definition: byte_stream.h:759
size_t available_bytes() const
The number of bytes left in the stream.
Definition: byte_stream.h:810
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:653
size_t available() const
The number of T left in the stream.
Definition: byte_stream.h:800
byte_stream_reader(etl::span< char > span_, etl::endian stream_endianness_)
Construct from span.
Definition: byte_stream.h:503
size_t size_bytes() const
Returns the number of bytes used in the stream.
Definition: byte_stream.h:791
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:669
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:573
etl::span< const char > data() const
Returns a span of whole the stream.
Definition: byte_stream.h:775
etl::span< const char > free_data() const
Returns a span of the free portion of the stream.
Definition: byte_stream.h:767
bool skip(size_t n)
Definition: byte_stream.h:703
void restart(size_t n=0U)
Sets the index back to the position in the stream. Default = 0.
Definition: byte_stream.h:719
byte_stream_reader(const void *begin_, size_t length_, etl::endian stream_endianness_)
Construct from begin and length.
Definition: byte_stream.h:536
byte_stream_reader(T(&begin_)[Size], etl::endian stream_endianness_)
Construct from array.
Definition: byte_stream.h:548
const_iterator end() const
Returns end of the stream.
Definition: byte_stream.h:735
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:583
byte_stream_reader(const void *begin_, const void *end_, etl::endian stream_endianness_)
Construct from range.
Definition: byte_stream.h:525
Encodes a byte stream.
Definition: byte_stream.h:58
byte_stream_writer(etl::span< unsigned char > span_, etl::endian stream_endianness_, callback_type callback_=callback_type())
Construct from span.
Definition: byte_stream.h:81
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:215
const_iterator cbegin() const
Returns start of the stream.
Definition: byte_stream.h:302
etl::span< char > data()
Returns a span of whole the stream.
Definition: byte_stream.h:350
const_iterator end() const
Returns end of the stream.
Definition: byte_stream.h:294
etl::span< char > free_data()
Returns a span of the free portion of the stream.
Definition: byte_stream.h:334
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:105
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:198
iterator begin()
Returns start of the stream.
Definition: byte_stream.h:270
byte_stream_writer(T(&begin_)[Size], etl::endian stream_endianness_, callback_type callback_=callback_type())
Construct from array.
Definition: byte_stream.h:118
void restart(size_t n=0U)
Sets the index back to the position in the stream. Default = 0.
Definition: byte_stream.h:262
byte_stream_writer(void *begin_, void *end_, etl::endian stream_endianness_, callback_type callback_=callback_type())
Construct from range.
Definition: byte_stream.h:93
bool write(bool value)
Writes a boolean to the stream.
Definition: byte_stream.h:138
void write_unchecked(bool value)
Writes a boolean to the stream.
Definition: byte_stream.h:130
etl::endian get_endianness() const
Gets the endianness of the stream.
Definition: byte_stream.h:431
void set_callback(callback_type callback_)
Sets the function to call afer every write.
Definition: byte_stream.h:415
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:155
etl::span< char > used_data()
Returns a span of the used portion of the stream.
Definition: byte_stream.h:318
iterator end()
Returns end of the stream.
Definition: byte_stream.h:286
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:229
bool empty() const
Returns true if the byte stream is empty.
Definition: byte_stream.h:374
byte_stream_writer(etl::span< char > span_, etl::endian stream_endianness_, callback_type callback_=callback_type())
Construct from span.
Definition: byte_stream.h:69
const_iterator cend() const
Returns end of the stream.
Definition: byte_stream.h:310
bool skip(size_t n)
Definition: byte_stream.h:247
size_t available_bytes() const
The number of bytes left in the stream.
Definition: byte_stream.h:407
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:165
size_t available() const
The number of T left in the stream.
Definition: byte_stream.h:399
etl::span< const char > data() const
Returns a span of whole the stream.
Definition: byte_stream.h:358
etl::span< const char > used_data() const
Returns a span of the used portion of the stream.
Definition: byte_stream.h:326
callback_type get_callback() const
Gets the function to call afer every write.
Definition: byte_stream.h:423
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:182
size_t capacity() const
Returns the maximum number of bytes in the stream.
Definition: byte_stream.h:390
etl::span< const char > free_data() const
Returns a span of the free portion of the stream.
Definition: byte_stream.h:342
const_iterator begin() const
Returns start of the stream.
Definition: byte_stream.h:278
size_t size_bytes() const
Returns the number of bytes used in the stream.
Definition: byte_stream.h:382
bool full() const
Returns true if the byte stream index has reached the end.
Definition: byte_stream.h:366
Definition: callback.h:45
Declaration.
Definition: delegate_cpp03.h:175
Definition: optional.h:108
Span - Fixed Extent.
Definition: span.h:62
ETL_NODISCARD ETL_CONSTEXPR iterator begin() const ETL_NOEXCEPT
Returns an iterator to the beginning of the span.
Definition: span.h:256
ETL_NODISCARD ETL_CONSTEXPR size_t size() const ETL_NOEXCEPT
Returns the size of the span.
Definition: span.h:312
ETL_NODISCARD ETL_CONSTEXPR iterator end() const ETL_NOEXCEPT
Returns an iterator to the end of the span.
Definition: span.h:272
Definition: endianness.h:100
enable_if
Definition: type_traits_generator.h:1191
is_floating_point
Definition: type_traits_generator.h:1031
bitset_ext
Definition: absolute.h:38
etl::optional< T > read(etl::bit_stream_reader &stream)
Read a checked type from a stream.
Definition: bit_stream.h:1348
void write_unchecked(etl::bit_stream_writer &stream, bool value)
Definition: bit_stream.h:983
T read_unchecked(etl::bit_stream_reader &stream)
Read an unchecked type from a stream.
Definition: bit_stream.h:1333
bool write(etl::bit_stream_writer &stream, bool value)
Definition: bit_stream.h:992