Loading...
Searching...
No Matches
byte_stream.h
Go to the documentation of this 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 "algorithm.h"
#include "delegate.h"
#include "endianness.h"
#include "error_handler.h"
#include "exception.h"
#include "integral_limits.h"
#include "iterator.h"
#include "memory.h"
#include "optional.h"
#include "span.h"
#include "type_traits.h"
#include <stddef.h>
namespace etl
{
//***************************************************************************
//***************************************************************************
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;
//***************************************************************************
//***************************************************************************
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_)
{
}
//***************************************************************************
//***************************************************************************
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_)
{
}
//***************************************************************************
//***************************************************************************
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(static_cast<size_t>(etl::distance(reinterpret_cast<char*>(begin_), reinterpret_cast<char*>(end_))))
, stream_endianness(stream_endianness_)
, callback(callback_)
{
}
//***************************************************************************
//***************************************************************************
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_)
{
}
//***************************************************************************
//***************************************************************************
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_)
{
}
//***************************************************************************
//***************************************************************************
void write_unchecked(bool value)
{
*pcurrent++ = value ? 1 : 0;
}
//***************************************************************************
//***************************************************************************
bool write(bool value)
{
bool success = (available<bool>() > 0U);
if (success)
{
write_unchecked(value);
}
return success;
}
//***************************************************************************
//***************************************************************************
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);
}
//***************************************************************************
//***************************************************************************
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;
}
//***************************************************************************
//***************************************************************************
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;
}
}
//***************************************************************************
//***************************************************************************
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;
}
//***************************************************************************
//***************************************************************************
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;
}
}
//***************************************************************************
//***************************************************************************
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;
}
//***************************************************************************
//***************************************************************************
template <typename T>
bool skip(size_t n)
{
bool success = (available<T>() >= n);
if (success)
{
step(n * sizeof(T));
}
return success;
}
//***************************************************************************
//***************************************************************************
void restart(size_t n = 0U)
{
pcurrent = pdata + n;
}
//***************************************************************************
//***************************************************************************
iterator begin()
{
return pdata;
}
//***************************************************************************
//***************************************************************************
const_iterator begin() const
{
return pdata;
}
//***************************************************************************
//***************************************************************************
iterator end()
{
return pcurrent;
}
//***************************************************************************
//***************************************************************************
const_iterator end() const
{
return pcurrent;
}
//***************************************************************************
//***************************************************************************
const_iterator cbegin() const
{
return pdata;
}
//***************************************************************************
//***************************************************************************
const_iterator cend() const
{
return pcurrent;
}
//***************************************************************************
//***************************************************************************
etl::span<char> used_data()
{
return etl::span<char>(pdata, pcurrent);
}
//***************************************************************************
//***************************************************************************
etl::span<const char> used_data() const
{
return etl::span<const char>(pdata, pcurrent);
}
//***************************************************************************
//***************************************************************************
etl::span<char> free_data()
{
return etl::span<char>(pcurrent, pdata + stream_length);
}
//***************************************************************************
//***************************************************************************
etl::span<const char> free_data() const
{
return etl::span<const char>(pcurrent, pdata + stream_length);
}
//***************************************************************************
//***************************************************************************
etl::span<char> data()
{
return etl::span<char>(pdata, pdata + stream_length);
}
//***************************************************************************
//***************************************************************************
etl::span<const char> data() const
{
return etl::span<const char>(pdata, pdata + stream_length);
}
//***************************************************************************
//***************************************************************************
bool full() const
{
return size_bytes() == capacity();
}
//***************************************************************************
//***************************************************************************
bool empty() const
{
return size_bytes() == 0U;
}
//***************************************************************************
//***************************************************************************
size_t size_bytes() const
{
return static_cast<size_t>(etl::distance(pdata, pcurrent));
}
//***************************************************************************
//***************************************************************************
size_t capacity() const
{
return stream_length;
}
//***************************************************************************
//***************************************************************************
template <typename T>
size_t available() const
{
return (capacity() - size_bytes()) / sizeof(T);
}
//***************************************************************************
//***************************************************************************
size_t available_bytes() const
{
return available<char>();
}
//***************************************************************************
//***************************************************************************
void set_callback(callback_type callback_)
{
callback = callback_;
}
//***************************************************************************
//***************************************************************************
callback_type get_callback() const
{
return callback;
}
//***************************************************************************
//***************************************************************************
etl::endian get_endianness() const
{
return stream_endianness;
}
private:
//***************************************************************************
//***************************************************************************
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;
char* pcurrent;
const size_t stream_length;
const etl::endian stream_endianness;
callback_type callback;
};
//***************************************************************************
//***************************************************************************
class byte_stream_reader
{
public:
typedef char* iterator;
typedef const char* const_iterator;
//***************************************************************************
//***************************************************************************
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_)
{
}
//***************************************************************************
//***************************************************************************
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_)
{
}
//***************************************************************************
//***************************************************************************
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(static_cast<size_t>(etl::distance(reinterpret_cast<const char*>(begin_), reinterpret_cast<const char*>(end_))))
, stream_endianness(stream_endianness_)
{
}
//***************************************************************************
//***************************************************************************
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_)
{
}
//***************************************************************************
//***************************************************************************
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_)
{
}
//***************************************************************************
//***************************************************************************
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_)
{
}
//***************************************************************************
//***************************************************************************
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>();
}
//***************************************************************************
//***************************************************************************
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;
}
//***************************************************************************
//***************************************************************************
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;
}
//***************************************************************************
//***************************************************************************
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;
}
//***************************************************************************
//***************************************************************************
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());
}
//***************************************************************************
//***************************************************************************
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> >();
}
//***************************************************************************
//***************************************************************************
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);
}
//***************************************************************************
//***************************************************************************
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> >();
}
//***************************************************************************
//***************************************************************************
template <typename T>
bool skip(size_t n)
{
if (n <= available<T>())
{
pcurrent += (n * sizeof(T));
return true;
}
else
{
return false;
}
}
//***************************************************************************
//***************************************************************************
void restart(size_t n = 0U)
{
pcurrent = pdata + n;
}
//***************************************************************************
//***************************************************************************
const_iterator begin() const
{
return pdata;
}
//***************************************************************************
//***************************************************************************
const_iterator end() const
{
return pcurrent;
}
//***************************************************************************
//***************************************************************************
const_iterator cbegin() const
{
return pdata;
}
//***************************************************************************
//***************************************************************************
const_iterator cend() const
{
return pcurrent;
}
//***************************************************************************
//***************************************************************************
etl::span<const char> used_data() const
{
return etl::span<const char>(pdata, pcurrent);
}
//***************************************************************************
//***************************************************************************
etl::span<const char> free_data() const
{
return etl::span<const char>(pcurrent, pdata + stream_length);
}
//***************************************************************************
//***************************************************************************
etl::span<const char> data() const
{
return etl::span<const char>(pdata, pdata + stream_length);
}
//***************************************************************************
//***************************************************************************
bool empty() const
{
return available<char>() == 0U;
}
//***************************************************************************
//***************************************************************************
size_t size_bytes() const
{
return stream_length;
}
//***************************************************************************
//***************************************************************************
template <typename T>
size_t available() const
{
size_t used = static_cast<size_t>(etl::distance(pdata, pcurrent));
return (stream_length - used) / sizeof(T);
}
//***************************************************************************
//***************************************************************************
size_t available_bytes() const
{
return available<char>();
}
//***************************************************************************
//***************************************************************************
etl::endian get_endianness() const
{
return stream_endianness;
}
private:
//***************************************************************************
//***************************************************************************
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;
const char* pcurrent;
const size_t stream_length;
const etl::endian stream_endianness;
};
//***************************************************************************
//***************************************************************************
template <typename T>
void write_unchecked(etl::byte_stream_writer& stream, const T& value)
{
stream.write_unchecked(value);
}
//***************************************************************************
//***************************************************************************
template <typename T>
bool write(etl::byte_stream_writer& stream, const T& value)
{
return stream.write(value);
}
//***************************************************************************
//***************************************************************************
template <typename T>
T read_unchecked(etl::byte_stream_reader& stream)
{
return stream.read_unchecked<T>();
}
//***************************************************************************
//***************************************************************************
template <typename T>
etl::optional<T> read(etl::byte_stream_reader& stream)
{
return stream.read<T>();
}
} // namespace etl
#endif
algorithm.h
etl::byte_stream_reader
Definition byte_stream.h:483
etl::byte_stream_reader::cbegin
const_iterator cbegin() const
Returns start of the stream.
Definition byte_stream.h:728
etl::byte_stream_reader::byte_stream_reader
byte_stream_reader(etl::span< const char > span_, etl::endian stream_endianness_)
Construct from span.
Definition byte_stream.h:503
etl::byte_stream_reader::empty
bool empty() const
Returns true if the byte stream is empty.
Definition byte_stream.h:768
etl::byte_stream_reader::read
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::byte_stream_reader::read_unchecked
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::byte_stream_reader::read
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::byte_stream_reader::read_unchecked
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
etl::byte_stream_reader::byte_stream_reader
byte_stream_reader(const T(&begin_)[Size], etl::endian stream_endianness_)
Construct from const array.
Definition byte_stream.h:549
etl::byte_stream_reader::begin
const_iterator begin() const
Returns start of the stream.
Definition byte_stream.h:712
etl::byte_stream_reader::cend
const_iterator cend() const
Returns end of the stream.
Definition byte_stream.h:736
etl::byte_stream_reader::used_data
etl::span< const char > used_data() const
Returns a span of the used portion of the stream.
Definition byte_stream.h:744
etl::byte_stream_reader::available_bytes
size_t available_bytes() const
The number of bytes left in the stream.
Definition byte_stream.h:795
etl::byte_stream_reader::read
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
etl::byte_stream_reader::available
size_t available() const
The number of T left in the stream.
Definition byte_stream.h:785
etl::byte_stream_reader::byte_stream_reader
byte_stream_reader(etl::span< char > span_, etl::endian stream_endianness_)
Construct from span.
Definition byte_stream.h:492
etl::byte_stream_reader::size_bytes
size_t size_bytes() const
Returns the number of bytes used in the stream.
Definition byte_stream.h:776
etl::byte_stream_reader::read_unchecked
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::byte_stream_reader::read_unchecked
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::byte_stream_reader::data
etl::span< const char > data() const
Returns a span of whole the stream.
Definition byte_stream.h:760
etl::byte_stream_reader::free_data
etl::span< const char > free_data() const
Returns a span of the free portion of the stream.
Definition byte_stream.h:752
etl::byte_stream_reader::skip
bool skip(size_t n)
Definition byte_stream.h:688
etl::byte_stream_reader::restart
void restart(size_t n=0U)
Sets the index back to the position in the stream. Default = 0.
Definition byte_stream.h:704
etl::byte_stream_reader::byte_stream_reader
byte_stream_reader(const void *begin_, size_t length_, etl::endian stream_endianness_)
Construct from begin and length.
Definition byte_stream.h:525
etl::byte_stream_reader::byte_stream_reader
byte_stream_reader(T(&begin_)[Size], etl::endian stream_endianness_)
Construct from array.
Definition byte_stream.h:537
etl::byte_stream_reader::get_endianness
etl::endian get_endianness() const
Gets the endianness of the stream.
Definition byte_stream.h:803
etl::byte_stream_reader::end
const_iterator end() const
Returns end of the stream.
Definition byte_stream.h:720
etl::byte_stream_reader::read
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
etl::byte_stream_reader::byte_stream_reader
byte_stream_reader(const void *begin_, const void *end_, etl::endian stream_endianness_)
Construct from range.
Definition byte_stream.h:514
etl::byte_stream_writer
Encodes a byte stream.
Definition byte_stream.h:55
etl::byte_stream_writer::byte_stream_writer
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::byte_stream_writer::write_unchecked
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
etl::byte_stream_writer::cbegin
const_iterator cbegin() const
Returns start of the stream.
Definition byte_stream.h:293
etl::byte_stream_writer::data
etl::span< char > data()
Returns a span of whole the stream.
Definition byte_stream.h:341
etl::byte_stream_writer::end
const_iterator end() const
Returns end of the stream.
Definition byte_stream.h:285
etl::byte_stream_writer::free_data
etl::span< char > free_data()
Returns a span of the free portion of the stream.
Definition byte_stream.h:325
etl::byte_stream_writer::byte_stream_writer
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::byte_stream_writer::write
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
etl::byte_stream_writer::begin
iterator begin()
Returns start of the stream.
Definition byte_stream.h:261
etl::byte_stream_writer::byte_stream_writer
byte_stream_writer(T(&begin_)[Size], etl::endian stream_endianness_, callback_type callback_=callback_type())
Construct from array.
Definition byte_stream.h:115
etl::byte_stream_writer::restart
void restart(size_t n=0U)
Sets the index back to the position in the stream. Default = 0.
Definition byte_stream.h:253
etl::byte_stream_writer::byte_stream_writer
byte_stream_writer(void *begin_, void *end_, etl::endian stream_endianness_, callback_type callback_=callback_type())
Construct from range.
Definition byte_stream.h:90
etl::byte_stream_writer::write
bool write(bool value)
Writes a boolean to the stream.
Definition byte_stream.h:135
etl::byte_stream_writer::write_unchecked
void write_unchecked(bool value)
Writes a boolean to the stream.
Definition byte_stream.h:127
etl::byte_stream_writer::get_endianness
etl::endian get_endianness() const
Gets the endianness of the stream.
Definition byte_stream.h:422
etl::byte_stream_writer::set_callback
void set_callback(callback_type callback_)
Sets the function to call after every write.
Definition byte_stream.h:406
etl::byte_stream_writer::write_unchecked
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::byte_stream_writer::used_data
etl::span< char > used_data()
Returns a span of the used portion of the stream.
Definition byte_stream.h:309
etl::byte_stream_writer::end
iterator end()
Returns end of the stream.
Definition byte_stream.h:277
etl::byte_stream_writer::write
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
etl::byte_stream_writer::empty
bool empty() const
Returns true if the byte stream is empty.
Definition byte_stream.h:365
etl::byte_stream_writer::byte_stream_writer
byte_stream_writer(etl::span< char > span_, etl::endian stream_endianness_, callback_type callback_=callback_type())
Construct from span.
Definition byte_stream.h:66
etl::byte_stream_writer::cend
const_iterator cend() const
Returns end of the stream.
Definition byte_stream.h:301
etl::byte_stream_writer::skip
bool skip(size_t n)
Definition byte_stream.h:238
etl::byte_stream_writer::available_bytes
size_t available_bytes() const
The number of bytes left in the stream.
Definition byte_stream.h:398
etl::byte_stream_writer::write
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
etl::byte_stream_writer::available
size_t available() const
The number of T left in the stream.
Definition byte_stream.h:390
etl::byte_stream_writer::data
etl::span< const char > data() const
Returns a span of whole the stream.
Definition byte_stream.h:349
etl::byte_stream_writer::used_data
etl::span< const char > used_data() const
Returns a span of the used portion of the stream.
Definition byte_stream.h:317
etl::byte_stream_writer::get_callback
callback_type get_callback() const
Gets the function to call after every write.
Definition byte_stream.h:414
etl::byte_stream_writer::write_unchecked
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
etl::byte_stream_writer::capacity
size_t capacity() const
Returns the maximum number of bytes in the stream.
Definition byte_stream.h:381
etl::byte_stream_writer::free_data
etl::span< const char > free_data() const
Returns a span of the free portion of the stream.
Definition byte_stream.h:333
etl::byte_stream_writer::begin
const_iterator begin() const
Returns start of the stream.
Definition byte_stream.h:269
etl::byte_stream_writer::size_bytes
size_t size_bytes() const
Returns the number of bytes used in the stream.
Definition byte_stream.h:373
etl::byte_stream_writer::full
bool full() const
Returns true if the byte stream index has reached the end.
Definition byte_stream.h:357
etl::delegate
Declaration.
Definition delegate_cpp03.h:191
etl::span
Span - Fixed Extent.
Definition span.h:208
etl::span::begin
ETL_NODISCARD ETL_CONSTEXPR iterator begin() const ETL_NOEXCEPT
Returns an iterator to the beginning of the span.
Definition span.h:484
etl::span::size
ETL_NODISCARD ETL_CONSTEXPR size_t size() const ETL_NOEXCEPT
Returns the size of the span.
Definition span.h:564
etl::span::end
ETL_NODISCARD ETL_CONSTEXPR iterator end() const ETL_NOEXCEPT
Returns an iterator to the end of the span.
Definition span.h:508
delegate.h
endianness.h
error_handler.h
exception.h
etl::endian
Definition endianness.h:100
type
etl::optional
Definition optional.h:1238
integral_limits.h
iterator.h
memory.h
etl
Definition absolute.h:40
etl::read
etl::optional< T > read(etl::bit_stream_reader &stream)
Read a checked type from a stream.
Definition bit_stream.h:1430
etl::write_unchecked
void write_unchecked(etl::bit_stream_writer &stream, bool value)
Definition bit_stream.h:1026
etl::read_unchecked
T read_unchecked(etl::bit_stream_reader &stream)
Read an unchecked type from a stream.
Definition bit_stream.h:1415
etl::write
bool write(etl::bit_stream_writer &stream, bool value)
Definition bit_stream.h:1035
optional.h
platform.h
span.h
etl::type
type_traits.h