Public Member Functions | Protected Attributes
msp::ByteVector Class Reference

#include <ByteVector.hpp>

List of all members.

Public Member Functions

 ByteVector ()
 ByteVector constructor.
template<typename T1 >
 ByteVector (T1 arg1)
 ByteVector constructor.
template<typename T1 , typename T2 >
 ByteVector (T1 arg1, T2 arg2)
 ByteVector constructor.
bool consume (std::size_t count) const
 Manually consumes data, thus skipping the values.
template<typename T , typename std::enable_if< std::is_integral< T >::value, T >::type * = nullptr>
bool pack (const T &val)
 Packs integer types into the ByteVector. Ensures little endian packing.
template<typename T , typename std::enable_if< std::is_floating_point< T >::value, T >::type * = nullptr>
bool pack (const T &val)
 Packs floating point types into the ByteVector. Uses IEEE 754 format.
template<typename encoding_T , typename T1 , typename T2 , typename std::enable_if< std::is_arithmetic< T1 >::value, T1 >::type * = nullptr, typename std::enable_if< std::is_arithmetic< T2 >::value, T2 >::type * = nullptr>
bool pack (const T1 val, const T2 scale, const T2 offset=0)
 Packs scaled values (e.g. float to scaled int) as packed_val = (val+offset)*scale.
bool pack (const std::string &val, size_t max_len=std::numeric_limits< size_t >::max())
 Packs string data into the ByteVector.
bool pack (const ByteVector &data, size_t max_len=std::numeric_limits< size_t >::max())
 Packs another ByteVector into the ByteVector.
template<typename T , typename std::enable_if< std::is_base_of< Packable, T >::value, T >::type * = nullptr>
bool pack (const T &val)
 Packs an an object which inherits from type Packable into the ByteVector.
template<typename encoding_T , typename T1 , typename T2 , typename std::enable_if< std::is_arithmetic< T1 >::value, T1 >::type * = nullptr, typename std::enable_if< std::is_arithmetic< T2 >::value, T2 >::type * = nullptr>
bool pack (const Value< T1 > val, const T2 scale, const T2 offset=0)
 Packs scaled value types (e.g. value<float> to scaled int) as packed_val = (val+offset)*scale.
bool pack (const Value< ByteVector > &val, size_t max_len=std::numeric_limits< size_t >::max())
 Packs a Value<ByteVector> into the ByteVector.
bool pack (const Value< std::string > &val, size_t max_len=std::numeric_limits< size_t >::max())
 Packs a Value<std::string> into the ByteVector.
template<class T >
bool pack (const Value< T > &val)
 Packs the contents of a Value<T> into the ByteVector.
template<typename T , typename std::enable_if< std::is_integral< T >::value, T >::type * = nullptr>
bool unpack (T &val) const
 Extracts little endian integers from the ByteVector. Consumes a number of bytes matching sizeof(T). Fails if not enough bytes are available.
bool unpack (bool &val) const
 unpack Extracts a boolen from a single byte
template<typename T , typename std::enable_if< std::is_floating_point< T >::value, T >::type * = nullptr>
bool unpack (T &val) const
 Extracts floating point numbers from the ByteVector. Consumes a number of bytes matching sizeof(T). Fails if not enough bytes are available.
bool unpack (std::string &val, size_t count=std::numeric_limits< size_t >::max()) const
 Extracts data from the ByteVector and stores it in a std::string. Consumes all remaining data unless instructed otherwise.
bool unpack (ByteVector &val, size_t count=std::numeric_limits< size_t >::max()) const
 Extracts data from the ByteVector and stores it in a another ByteVector. Consumes all remaining data unless instructed otherwise.
template<typename encoding_T , typename T1 , typename T2 , typename std::enable_if< std::is_arithmetic< T1 >::value, T1 >::type * = nullptr, typename std::enable_if< std::is_arithmetic< T2 >::value, T2 >::type * = nullptr>
bool unpack (T1 &val, T2 scale, T2 offset=0) const
 Unpacks scaled value types (e.g. scaled int to floating point) as val = (packed_val/scale)-offset.
template<typename T , typename std::enable_if< std::is_base_of< Packable, T >::value, T >::type * = nullptr>
bool unpack (T &obj) const
 unpack Unpacks an an object which inherits from type Packable
template<class T >
bool unpack (Value< T > &val) const
 Unpacks Value types other than string and ByteVector specializations.
bool unpack (Value< std::string > &val, size_t count=std::numeric_limits< size_t >::max()) const
 Extracts data from the ByteVector and stores it in a Value<std::string>. Consumes all remaining data unless instructed otherwise.
bool unpack (Value< ByteVector > &val, size_t count=std::numeric_limits< size_t >::max()) const
 Extracts data from the ByteVector and stores it in a Value<ByteVector>. Consumes all remaining data unless instructed otherwise.
template<typename encoding_T , typename T1 , typename T2 , typename std::enable_if< std::is_arithmetic< T1 >::value, T1 >::type * = nullptr, typename std::enable_if< std::is_arithmetic< T2 >::value, T2 >::type * = nullptr>
bool unpack (Value< T1 > &val, T2 scale=1, T2 offset=0) const
 Unpacks scaled Value types (e.g. scaled int to floating point) as val = (packed_val/scale)-offset.
std::vector< uint8_t >::iterator unpacking_iterator ()
 Gives an iterator to the next element ready for unpacking.
std::vector< uint8_t >
::const_iterator 
unpacking_iterator () const
 Gives an iterator to the next element ready for unpacking.
std::size_t unpacking_offset () const
 Gives the number of bytes which have already been consumed by unpack operations.
std::size_t unpacking_remaining () const
 Returns the number of bytes still avialable for unpacking.

Protected Attributes

std::size_t offset

Detailed Description

Definition at line 15 of file ByteVector.hpp.


Constructor & Destructor Documentation

ByteVector constructor.

Definition at line 20 of file ByteVector.hpp.

template<typename T1 >
msp::ByteVector::ByteVector ( T1  arg1) [inline]

ByteVector constructor.

Parameters:
arg1Single argument passed to constructor of parent std::vector class

Definition at line 28 of file ByteVector.hpp.

template<typename T1 , typename T2 >
msp::ByteVector::ByteVector ( T1  arg1,
T2  arg2 
) [inline]

ByteVector constructor.

Parameters:
arg1First of two arguments passed to constructor of parent std::vector class
arg2Second of two arguments passed to constructor of parent std::vector class

Definition at line 38 of file ByteVector.hpp.


Member Function Documentation

bool msp::ByteVector::consume ( std::size_t  count) const [inline]

Manually consumes data, thus skipping the values.

Parameters:
countNumber of bytes to consume
Returns:
True if successful
False if there were not enough bytes to satisfy the request

Definition at line 436 of file ByteVector.hpp.

template<typename T , typename std::enable_if< std::is_integral< T >::value, T >::type * = nullptr>
bool msp::ByteVector::pack ( const T &  val) [inline]

Packs integer types into the ByteVector. Ensures little endian packing.

Template Parameters:
TUnderlying data type to be packed. Must be an integral type.
Parameters:
valValue to be packed
Returns:
true

Definition at line 51 of file ByteVector.hpp.

template<typename T , typename std::enable_if< std::is_floating_point< T >::value, T >::type * = nullptr>
bool msp::ByteVector::pack ( const T &  val) [inline]

Packs floating point types into the ByteVector. Uses IEEE 754 format.

Template Parameters:
TUnderlying data type to be packed. Must be a floating point type.
Parameters:
valValue to be packed
Returns:
True if successful

Definition at line 70 of file ByteVector.hpp.

template<typename encoding_T , typename T1 , typename T2 , typename std::enable_if< std::is_arithmetic< T1 >::value, T1 >::type * = nullptr, typename std::enable_if< std::is_arithmetic< T2 >::value, T2 >::type * = nullptr>
bool msp::ByteVector::pack ( const T1  val,
const T2  scale,
const T2  offset = 0 
) [inline]

Packs scaled values (e.g. float to scaled int) as packed_val = (val+offset)*scale.

Template Parameters:
encoding_TData type to use for the actual data packing (usually an integral type)
T1Type of input value (usually a floating point type)
T2Type of scale and offset coefficients
Parameters:
valValue to be packed
scaleValue of scaling to apply to the offset value
offsetValue of offset to apply to the input value (optional, defaults to 0)
Returns:
True if successful

Definition at line 94 of file ByteVector.hpp.

bool msp::ByteVector::pack ( const std::string &  val,
size_t  max_len = std::numeric_limits<size_t>::max() 
) [inline]

Packs string data into the ByteVector.

Parameters:
valString to be packed
max_lenOptional max number of characters to transfer into the ByteVector
Returns:
True if successful

Definition at line 110 of file ByteVector.hpp.

bool msp::ByteVector::pack ( const ByteVector data,
size_t  max_len = std::numeric_limits<size_t>::max() 
) [inline]

Packs another ByteVector into the ByteVector.

Parameters:
dataByteVector to be packed
max_lenOptional max number of characters to transfer into the ByteVector
Returns:
True if successful

Definition at line 130 of file ByteVector.hpp.

template<typename T , typename std::enable_if< std::is_base_of< Packable, T >::value, T >::type * = nullptr>
bool msp::ByteVector::pack ( const T &  val) [inline]

Packs an an object which inherits from type Packable into the ByteVector.

Parameters:
valReference to object to be packed
Returns:
True if successful

Definition at line 149 of file ByteVector.hpp.

template<typename encoding_T , typename T1 , typename T2 , typename std::enable_if< std::is_arithmetic< T1 >::value, T1 >::type * = nullptr, typename std::enable_if< std::is_arithmetic< T2 >::value, T2 >::type * = nullptr>
bool msp::ByteVector::pack ( const Value< T1 >  val,
const T2  scale,
const T2  offset = 0 
) [inline]

Packs scaled value types (e.g. value<float> to scaled int) as packed_val = (val+offset)*scale.

Template Parameters:
encoding_TData type to use for the actual data packing (usually an integral type)
T1Type of input value (usually a floating point type)
T2Type of scale and offset coefficients
Parameters:
valValue to be packed
scaleValue of scaling to apply to the offset value
offsetValue of offset to apply to the input value (optional, defaults to 0)
Returns:
True if successful

Definition at line 171 of file ByteVector.hpp.

bool msp::ByteVector::pack ( const Value< ByteVector > &  val,
size_t  max_len = std::numeric_limits<size_t>::max() 
) [inline]

Packs a Value<ByteVector> into the ByteVector.

Parameters:
valThe Value<ByteVector> to be packed
max_lenOptional max number of characters to transfer into the ByteVector
Returns:
True if successful

Definition at line 183 of file ByteVector.hpp.

bool msp::ByteVector::pack ( const Value< std::string > &  val,
size_t  max_len = std::numeric_limits<size_t>::max() 
) [inline]

Packs a Value<std::string> into the ByteVector.

Parameters:
valThe Value<std::string> to be packed
max_lenOptional max number of characters to transfer into the ByteVector
Returns:
True if successful

Definition at line 196 of file ByteVector.hpp.

template<class T >
bool msp::ByteVector::pack ( const Value< T > &  val) [inline]

Packs the contents of a Value<T> into the ByteVector.

Template Parameters:
TType of the Value<T> being packed. May be automatically deduced from arguments
Parameters:
valThe Value<T> to be packed
Returns:
True if successful

Definition at line 209 of file ByteVector.hpp.

template<typename T , typename std::enable_if< std::is_integral< T >::value, T >::type * = nullptr>
bool msp::ByteVector::unpack ( T &  val) const [inline]

Extracts little endian integers from the ByteVector. Consumes a number of bytes matching sizeof(T). Fails if not enough bytes are available.

Template Parameters:
TUnderlying data type to be extracted. Must be an integral type.
Parameters:
valDestination of unpack operation.
Returns:
True on successful unpack

Definition at line 224 of file ByteVector.hpp.

bool msp::ByteVector::unpack ( bool &  val) const [inline]

unpack Extracts a boolen from a single byte

Parameters:
valDestination of unpack operation.
Returns:
True on successful unpack

Definition at line 238 of file ByteVector.hpp.

template<typename T , typename std::enable_if< std::is_floating_point< T >::value, T >::type * = nullptr>
bool msp::ByteVector::unpack ( T &  val) const [inline]

Extracts floating point numbers from the ByteVector. Consumes a number of bytes matching sizeof(T). Fails if not enough bytes are available.

Template Parameters:
TUnderlying data type to be extracted. Must be a floating point type.
Parameters:
valDestination of unpack operation.
Returns:
True on successful unpack

Definition at line 256 of file ByteVector.hpp.

bool msp::ByteVector::unpack ( std::string &  val,
size_t  count = std::numeric_limits<size_t>::max() 
) const [inline]

Extracts data from the ByteVector and stores it in a std::string. Consumes all remaining data unless instructed otherwise.

Parameters:
valDestination of unpack operation.
countMax number of bytes to extract. Optional, if unset, all remaining bytes will be consumed.
Returns:
True on successful unpack

Definition at line 271 of file ByteVector.hpp.

bool msp::ByteVector::unpack ( ByteVector val,
size_t  count = std::numeric_limits<size_t>::max() 
) const [inline]

Extracts data from the ByteVector and stores it in a another ByteVector. Consumes all remaining data unless instructed otherwise.

Parameters:
valDestination of unpack operation.
countMax number of bytes to extract. Optional, if unset, all remaining bytes will be consumed.
Returns:
True on successful unpack

Definition at line 295 of file ByteVector.hpp.

template<typename encoding_T , typename T1 , typename T2 , typename std::enable_if< std::is_arithmetic< T1 >::value, T1 >::type * = nullptr, typename std::enable_if< std::is_arithmetic< T2 >::value, T2 >::type * = nullptr>
bool msp::ByteVector::unpack ( T1 &  val,
T2  scale,
T2  offset = 0 
) const [inline]

Unpacks scaled value types (e.g. scaled int to floating point) as val = (packed_val/scale)-offset.

Template Parameters:
encoding_Tdata type used to store the scaled value (usually an integral type)
T1type of output value (usually a floating point type)
T2type of scale and offset coefficients
Parameters:
valDestination of unpack operation
scaleValue of scaling to apply to the offset value
offsetValue of offset to apply to the input value (optional, defaults to 0)
Returns:
True if successful

Definition at line 324 of file ByteVector.hpp.

template<typename T , typename std::enable_if< std::is_base_of< Packable, T >::value, T >::type * = nullptr>
bool msp::ByteVector::unpack ( T &  obj) const [inline]

unpack Unpacks an an object which inherits from type Packable

Parameters:
valReference to object to be unpacked
Returns:
True if successful

Definition at line 341 of file ByteVector.hpp.

template<class T >
bool msp::ByteVector::unpack ( Value< T > &  val) const [inline]

Unpacks Value types other than string and ByteVector specializations.

Template Parameters:
TType of the Value<T> being packed. May be automatically deduced from arguments
Parameters:
valThe destination of the unpack operation
Returns:
true on success

Definition at line 353 of file ByteVector.hpp.

bool msp::ByteVector::unpack ( Value< std::string > &  val,
size_t  count = std::numeric_limits<size_t>::max() 
) const [inline]

Extracts data from the ByteVector and stores it in a Value<std::string>. Consumes all remaining data unless instructed otherwise.

Parameters:
valDestination of unpack operation.
countMax number of bytes to extract. Optional, if unset, all remaining bytes will be consumed.
Returns:
True on successful unpack

Definition at line 366 of file ByteVector.hpp.

bool msp::ByteVector::unpack ( Value< ByteVector > &  val,
size_t  count = std::numeric_limits<size_t>::max() 
) const [inline]

Extracts data from the ByteVector and stores it in a Value<ByteVector>. Consumes all remaining data unless instructed otherwise.

Parameters:
valDestination of unpack operation.
countMax number of bytes to extract. Optional, if unset, all remaining bytes will be consumed.
Returns:
True on successful unpack

Definition at line 380 of file ByteVector.hpp.

template<typename encoding_T , typename T1 , typename T2 , typename std::enable_if< std::is_arithmetic< T1 >::value, T1 >::type * = nullptr, typename std::enable_if< std::is_arithmetic< T2 >::value, T2 >::type * = nullptr>
bool msp::ByteVector::unpack ( Value< T1 > &  val,
T2  scale = 1,
T2  offset = 0 
) const [inline]

Unpacks scaled Value types (e.g. scaled int to floating point) as val = (packed_val/scale)-offset.

Template Parameters:
encoding_Tdata type used to store the scaled Value (usually an integral type)
T1type of output Value (usually a floating point type)
T2type of scale and offset coefficients
Parameters:
valDestination of unpack operation
scaleValue of scaling to apply to the offset value
offsetValue of offset to apply to the input value (optional, defaults to 0)
Returns:
True if successful

Definition at line 403 of file ByteVector.hpp.

std::vector<uint8_t>::iterator msp::ByteVector::unpacking_iterator ( ) [inline]

Gives an iterator to the next element ready for unpacking.

Returns:
iterator to the next byte for unpacking

Definition at line 418 of file ByteVector.hpp.

std::vector<uint8_t>::const_iterator msp::ByteVector::unpacking_iterator ( ) const [inline]

Gives an iterator to the next element ready for unpacking.

Returns:
iterator to the next byte for unpacking

Definition at line 426 of file ByteVector.hpp.

std::size_t msp::ByteVector::unpacking_offset ( ) const [inline]

Gives the number of bytes which have already been consumed by unpack operations.

Returns:
Number of bytes already consumed

Definition at line 412 of file ByteVector.hpp.

std::size_t msp::ByteVector::unpacking_remaining ( ) const [inline]

Returns the number of bytes still avialable for unpacking.

Returns:
Number of bytes remaining

Definition at line 448 of file ByteVector.hpp.


Member Data Documentation

std::size_t msp::ByteVector::offset [mutable, protected]

Definition at line 451 of file ByteVector.hpp.


The documentation for this class was generated from the following file:


msp
Author(s): Christian Rauch
autogenerated on Thu Jun 20 2019 19:40:38