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