Kagome
Polkadot Runtime Engine in C++17
kagome::common::SLBuffer< MaxSize > Class Template Reference

Class represents arbitrary (including empty) byte buffer. More...

#include <buffer.hpp>

Inheritance diagram for kagome::common::SLBuffer< MaxSize >:
Collaboration diagram for kagome::common::SLBuffer< MaxSize >:

Public Types

using Base = SLVector< uint8_t, MaxSize >
 
template<size_t OtherMaxSize>
using OtherSLBuffer = SLBuffer< OtherMaxSize >
 
using Base = BaseContainer
 

Public Member Functions

 SLBuffer ()=default
 
 SLBuffer (const typename Base::Base &other)
 lvalue construct buffer from a byte vector More...
 
 SLBuffer (typename Base::Base &&other)
 
template<size_t OtherMaxSize>
 SLBuffer (const OtherSLBuffer< OtherMaxSize > &other)
 
template<size_t OtherMaxSize>
 SLBuffer (OtherSLBuffer< OtherMaxSize > &&other)
 
 SLBuffer (const BufferView &s)
 
template<size_t N>
 SLBuffer (const std::array< typename Base::value_type, N > &other)
 
 SLBuffer (const uint8_t *begin, const uint8_t *end)
 
SLBufferreserve (size_t size)
 
SLBufferresize (size_t size)
 
SLBufferoperator+= (const BufferView &view) noexcept
 
SLBufferputUint8 (uint8_t n)
 Put a 8-bit {. More...
 
SLBufferputUint32 (uint32_t n)
 Put a 32-bit {. More...
 
SLBufferputUint64 (uint64_t n)
 Put a 64-bit {. More...
 
SLBufferput (std::string_view view)
 Put a string into byte buffer. More...
 
SLBufferput (const BufferView &view)
 Put a sequence of bytes as view into byte buffer. More...
 
const std::vector< uint8_t > & asVector () const
 getter for vector of bytes More...
 
std::vector< uint8_t > & asVector ()
 
std::vector< uint8_t > toVector ()&
 
std::vector< uint8_t > toVector ()&&
 
SLBuffer subbuffer (size_t offset=0, size_t length=-1) const
 
BufferView view (size_t offset=0, size_t length=-1) const
 
std::string toHex () const
 encode bytearray as hex More...
 
std::string toString () const
 return content of bytearray as string More...
 
std::string_view asString () const
 return content of bytearray as a string copy data More...
 
bool operator== (const BufferView &other) const noexcept
 
template<size_t N>
bool operator== (const std::array< typename Base::value_type, N > &other) const noexcept
 
bool operator< (const BufferView &other) const noexcept
 
template<size_t N>
bool operator< (const std::array< typename Base::value_type, N > &other) const noexcept
 
- Public Member Functions inherited from kagome::common::SizeLimitedContainer< BaseContainer, MaxSize >
constexpr Base::size_type max_size ()
 
 SizeLimitedContainer ()=default
 
 SizeLimitedContainer (size_t size)
 
 SizeLimitedContainer (size_t size, const typename Base::value_type &value)
 
 SizeLimitedContainer (const Base &other)
 
 SizeLimitedContainer (Base &&other)
 
template<typename Iter , typename = std::enable_if_t<std::is_base_of_v< std::input_iterator_tag, typename std::iterator_traits<Iter>::iterator_category>>>
 SizeLimitedContainer (Iter begin, Iter end)
 
 SizeLimitedContainer (std::initializer_list< typename Base::value_type > list)
 
SizeLimitedContaineroperator= (const Base &other)
 
SizeLimitedContaineroperator= (Base &&other)
 
SizeLimitedContaineroperator= (std::initializer_list< typename Base::value_type > list)
 
void assign (typename Base::size_type size, const typename Base::value_type &value)
 
template<typename Iter , typename = std::enable_if_t<std::is_base_of_v< std::input_iterator_tag, typename std::iterator_traits<Iter>::iterator_category>>>
void assign (Iter begin, Iter end)
 
void assign (std::initializer_list< typename Base::value_type > list)
 
template<typename... Args>
Base::reference & emplace_back (Args &&...args)
 
template<typename Iter , typename... Args, bool isIter = std::is_same_v<Iter, typename Base::iterator>, bool isConstIter = std::is_same_v<Iter, typename Base::const_iterator>, typename = std::enable_if_t<isIter or isConstIter>>
Base::iterator emplace (Iter pos, Args &&...args)
 
template<typename Iter , bool isIter = std::is_same_v<Iter, typename Base::iterator>, bool isConstIter = std::is_same_v<Iter, typename Base::const_iterator>, typename = std::enable_if_t<isIter or isConstIter>>
Base::iterator insert (Iter pos, const typename Base::value_type &value)
 
template<typename Iter , bool isIter = std::is_same_v<Iter, typename Base::iterator>, bool isConstIter = std::is_same_v<Iter, typename Base::const_iterator>, typename = std::enable_if_t<isIter or isConstIter>>
Base::iterator insert (Iter pos, typename Base::size_type size, const typename Base::value_type &value)
 
template<typename OutIt , typename InIt , bool isIter = std::is_same_v<OutIt, typename Base::iterator>, bool isConstIter = std::is_same_v<OutIt, typename Base::const_iterator>, typename = std::enable_if_t<isIter or isConstIter>, typename = std::enable_if_t<std::is_base_of_v< std::input_iterator_tag, typename std::iterator_traits<InIt>::iterator_category>>>
Base::iterator insert (OutIt pos, InIt begin, InIt end)
 
template<typename Iter , bool isIter = std::is_same_v<Iter, typename Base::iterator>, bool isConstIter = std::is_same_v<Iter, typename Base::const_iterator>, typename = std::enable_if_t<isIter or isConstIter>>
Base::iterator insert (Iter pos, std::initializer_list< typename Base::value_type > &&list)
 
template<typename V >
void push_back (V &&value)
 
void reserve (typename Base::size_type size)
 
void resize (typename Base::size_type size)
 
void resize (typename Base::size_type size, const typename Base::value_type &value)
 
bool operator== (const Base &other) const noexcept
 
bool operator== (const Span &other) const noexcept
 
bool operator!= (const Base &other) const noexcept
 
bool operator!= (const Span &other) const noexcept
 
bool operator< (const Base &other) const noexcept
 
bool operator< (const Span &other) const noexcept
 

Static Public Member Functions

static outcome::result< SLBufferfromHex (std::string_view hex)
 Construct SLBuffer from hex string. More...
 
static SLBuffer fromString (const std::string_view &src)
 stores content of a string to byte array More...
 

Additional Inherited Members

- Static Public Attributes inherited from kagome::common::SizeLimitedContainer< BaseContainer, MaxSize >
static constexpr bool is_static_collection = false
 
- Protected Types inherited from kagome::common::SizeLimitedContainer< BaseContainer, MaxSize >
using Base = BaseContainer
 
using Span = gsl::span< typename Base::value_type >
 
- Static Protected Attributes inherited from kagome::common::SizeLimitedContainer< BaseContainer, MaxSize >
static constexpr bool size_check_is_enabled
 

Detailed Description

template<size_t MaxSize>
class kagome::common::SLBuffer< MaxSize >

Class represents arbitrary (including empty) byte buffer.

Definition at line 29 of file buffer.hpp.

Member Typedef Documentation

template<size_t MaxSize>
using kagome::common::SLBuffer< MaxSize >::Base = SLVector<uint8_t, MaxSize>

Definition at line 31 of file buffer.hpp.

template<size_t MaxSize>
using kagome::common::SizeLimitedContainer< BaseContainer, MaxSize >::Base = BaseContainer

Definition at line 37 of file size_limited_containers.hpp.

template<size_t MaxSize>
template<size_t OtherMaxSize>
using kagome::common::SLBuffer< MaxSize >::OtherSLBuffer = SLBuffer<OtherMaxSize>

Definition at line 34 of file buffer.hpp.

Constructor & Destructor Documentation

template<size_t MaxSize>
kagome::common::SLBuffer< MaxSize >::SLBuffer ( )
default
template<size_t MaxSize>
kagome::common::SLBuffer< MaxSize >::SLBuffer ( const typename Base::Base other)
inlineexplicit

lvalue construct buffer from a byte vector

Definition at line 41 of file buffer.hpp.

template<size_t MaxSize>
kagome::common::SLBuffer< MaxSize >::SLBuffer ( typename Base::Base &&  other)
inlineexplicit

Definition at line 42 of file buffer.hpp.

template<size_t MaxSize>
template<size_t OtherMaxSize>
kagome::common::SLBuffer< MaxSize >::SLBuffer ( const OtherSLBuffer< OtherMaxSize > &  other)
inline

Definition at line 45 of file buffer.hpp.

template<size_t MaxSize>
template<size_t OtherMaxSize>
kagome::common::SLBuffer< MaxSize >::SLBuffer ( OtherSLBuffer< OtherMaxSize > &&  other)
inline

Definition at line 48 of file buffer.hpp.

template<size_t MaxSize>
kagome::common::SLBuffer< MaxSize >::SLBuffer ( const BufferView s)
inline

Definition at line 50 of file buffer.hpp.

template<size_t MaxSize>
template<size_t N>
kagome::common::SLBuffer< MaxSize >::SLBuffer ( const std::array< typename Base::value_type, N > &  other)
inline

Definition at line 53 of file buffer.hpp.

template<size_t MaxSize>
kagome::common::SLBuffer< MaxSize >::SLBuffer ( const uint8_t *  begin,
const uint8_t *  end 
)
inline

Definition at line 56 of file buffer.hpp.

Member Function Documentation

template<size_t MaxSize>
std::string_view kagome::common::SLBuffer< MaxSize >::asString ( ) const
inline

return content of bytearray as a string copy data

Note
Does not ensure correct encoding
Returns
string

Definition at line 196 of file buffer.hpp.

template<size_t MaxSize>
const std::vector<uint8_t>& kagome::common::SLBuffer< MaxSize >::asVector ( ) const
inline

getter for vector of bytes

Definition at line 135 of file buffer.hpp.

template<size_t MaxSize>
std::vector<uint8_t>& kagome::common::SLBuffer< MaxSize >::asVector ( )
inline

Definition at line 139 of file buffer.hpp.

template<size_t MaxSize>
static outcome::result<SLBuffer> kagome::common::SLBuffer< MaxSize >::fromHex ( std::string_view  hex)
inlinestatic

Construct SLBuffer from hex string.

Parameters
hexhex-encoded string
Returns
result containing constructed buffer if input string is hex-encoded string.

Definition at line 177 of file buffer.hpp.

template<size_t MaxSize>
static SLBuffer kagome::common::SLBuffer< MaxSize >::fromString ( const std::string_view &  src)
inlinestatic

stores content of a string to byte array

Definition at line 205 of file buffer.hpp.

template<size_t MaxSize>
SLBuffer& kagome::common::SLBuffer< MaxSize >::operator+= ( const BufferView view)
inlinenoexcept

Definition at line 71 of file buffer.hpp.

template<size_t MaxSize>
bool kagome::common::SLBuffer< MaxSize >::operator< ( const BufferView other) const
inlinenoexcept

Definition at line 225 of file buffer.hpp.

template<size_t MaxSize>
template<size_t N>
bool kagome::common::SLBuffer< MaxSize >::operator< ( const std::array< typename Base::value_type, N > &  other) const
inlinenoexcept

Definition at line 231 of file buffer.hpp.

template<size_t MaxSize>
bool kagome::common::SLBuffer< MaxSize >::operator== ( const BufferView other) const
inlinenoexcept

Definition at line 211 of file buffer.hpp.

template<size_t MaxSize>
template<size_t N>
bool kagome::common::SLBuffer< MaxSize >::operator== ( const std::array< typename Base::value_type, N > &  other) const
inlinenoexcept

Definition at line 217 of file buffer.hpp.

template<size_t MaxSize>
SLBuffer& kagome::common::SLBuffer< MaxSize >::put ( std::string_view  view)
inline

Put a string into byte buffer.

Parameters
sarbitrary string
Returns
this buffer, suitable for chaining.

Definition at line 117 of file buffer.hpp.

template<size_t MaxSize>
SLBuffer& kagome::common::SLBuffer< MaxSize >::put ( const BufferView view)
inline

Put a sequence of bytes as view into byte buffer.

Parameters
viewarbitrary span of bytes
Returns
this buffer, suitable for chaining.

Definition at line 127 of file buffer.hpp.

template<size_t MaxSize>
SLBuffer& kagome::common::SLBuffer< MaxSize >::putUint32 ( uint32_t  n)
inline

Put a 32-bit {.

Parameters
n}number in this buffer. Will be serialized as big-endian number.
Returns
this buffer, suitable for chaining.

Definition at line 89 of file buffer.hpp.

template<size_t MaxSize>
SLBuffer& kagome::common::SLBuffer< MaxSize >::putUint64 ( uint64_t  n)
inline

Put a 64-bit {.

Parameters
n}number in this buffer. Will be serialized as big-endian number.
Returns
this buffer, suitable for chaining.

Definition at line 103 of file buffer.hpp.

template<size_t MaxSize>
SLBuffer& kagome::common::SLBuffer< MaxSize >::putUint8 ( uint8_t  n)
inline

Put a 8-bit {.

Parameters
n}in this buffer.
Returns
this buffer, suitable for chaining.

Definition at line 79 of file buffer.hpp.

template<size_t MaxSize>
SLBuffer& kagome::common::SLBuffer< MaxSize >::reserve ( size_t  size)
inline

Definition at line 61 of file buffer.hpp.

template<size_t MaxSize>
SLBuffer& kagome::common::SLBuffer< MaxSize >::resize ( size_t  size)
inline

Definition at line 66 of file buffer.hpp.

template<size_t MaxSize>
SLBuffer kagome::common::SLBuffer< MaxSize >::subbuffer ( size_t  offset = 0,
size_t  length = -1 
) const
inline

Returns a copy of a part of the buffer Works alike subspan() of gsl::span

Definition at line 155 of file buffer.hpp.

template<size_t MaxSize>
std::string kagome::common::SLBuffer< MaxSize >::toHex ( ) const
inline

encode bytearray as hex

Returns
hex-encoded string

Definition at line 167 of file buffer.hpp.

template<size_t MaxSize>
std::string kagome::common::SLBuffer< MaxSize >::toString ( ) const
inline

return content of bytearray as string

Note
Does not ensure correct encoding
Returns
string

Definition at line 187 of file buffer.hpp.

template<size_t MaxSize>
std::vector<uint8_t> kagome::common::SLBuffer< MaxSize >::toVector ( )
inline

Definition at line 143 of file buffer.hpp.

template<size_t MaxSize>
std::vector<uint8_t> kagome::common::SLBuffer< MaxSize >::toVector ( )
inline

Definition at line 147 of file buffer.hpp.

template<size_t MaxSize>
BufferView kagome::common::SLBuffer< MaxSize >::view ( size_t  offset = 0,
size_t  length = -1 
) const
inline

Definition at line 159 of file buffer.hpp.


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