bmv2
Designing your own switch target with bmv2
Public Member Functions | List of all members
bm::ByteContainer Class Reference

Public Member Functions

 ByteContainer (const size_t nbytes, const char c='\x00')
 Constructs the container with nbytes copies of elements with value c. More...
 
 ByteContainer (const std::vector< char > &bytes)
 Constructs the container by copying the bytes in vector bytes. More...
 
 ByteContainer (const char *bytes, size_t nbytes)
 Constructs the container by copying the bytes in this byte array. More...
 
 ByteContainer (const std::string &hexstring)
 
size_type size () const noexcept
 Returns the number of bytes in the container. More...
 
void clear ()
 Clears the contents of the container. More...
 
iterator begin ()
 NC. More...
 
const_iterator begin () const
 NC. More...
 
iterator end ()
 NC. More...
 
const_iterator end () const
 NC. More...
 
ByteContainerappend (const ByteContainer &other)
 
ByteContainerappend (const char *byte_array, size_t nbytes)
 Appends a byte array to this container. More...
 
ByteContainerappend (const std::string &other)
 Appends a binary string to this container. More...
 
void insert (iterator pos, const ByteContainer &other)
 Inserts another ByteContainer object into this container, before pos. More...
 
void push_back (char c)
 Appends a character at the end of the container. More...
 
reference operator[] (size_type n)
 
const_reference operator[] (size_type n) const
 
reference back ()
 
const_reference back () const
 
reference front ()
 
const_reference front () const
 
char * data () noexcept
 
const char * data () const noexcept
 
bool operator== (const ByteContainer &other) const
 Returns true is the contents of the containers are equal. More...
 
bool operator!= (const ByteContainer &other) const
 Returns true is the contents of the containers are not equal. More...
 
void reserve (size_t n)
 Increase the capacity of the container. More...
 
void resize (size_t n)
 Resizes the container to contain bytes. More...
 
void resize (size_t n, char c)
 
void apply_mask (const ByteContainer &mask)
 
std::string to_hex (size_t start, size_t s, bool upper_case=false) const
 
std::string to_hex (bool upper_case=false) const
 Returns the hexadecimal representation of the byte container as a string. More...
 

Detailed Description

This class is used everytime a vector of bytes is needed in bmv2. It is most notably used by the Field class (to store the byte representation of a field) as well as to store match keys in tables.

Constructor & Destructor Documentation

◆ ByteContainer() [1/4]

bm::ByteContainer::ByteContainer ( const size_t  nbytes,
const char  c = '\x00' 
)
inlineexplicit

Constructs the container with nbytes copies of elements with value c.

◆ ByteContainer() [2/4]

bm::ByteContainer::ByteContainer ( const std::vector< char > &  bytes)
inlineexplicit

Constructs the container by copying the bytes in vector bytes.

◆ ByteContainer() [3/4]

bm::ByteContainer::ByteContainer ( const char *  bytes,
size_t  nbytes 
)
inline

Constructs the container by copying the bytes in this byte array.

◆ ByteContainer() [4/4]

bm::ByteContainer::ByteContainer ( const std::string &  hexstring)
inlineexplicit

Constructs the container from a hexadecimal string. Parameter hexstring can optionally include the 0x prefix.

Member Function Documentation

◆ append() [1/3]

ByteContainer& bm::ByteContainer::append ( const ByteContainer other)
inline

Appends another ByteContainer to this container. other has to be different from *this.

◆ append() [2/3]

ByteContainer& bm::ByteContainer::append ( const char *  byte_array,
size_t  nbytes 
)
inline

Appends a byte array to this container.

◆ append() [3/3]

ByteContainer& bm::ByteContainer::append ( const std::string &  other)
inline

Appends a binary string to this container.

◆ apply_mask()

void bm::ByteContainer::apply_mask ( const ByteContainer mask)
inline

Perform a byte-by-byte masking of the container. Will assert if size() != mask.size().

◆ back() [1/2]

reference bm::ByteContainer::back ( )
inline

Access the last byte of the container. Undefined if the container is empty.

◆ back() [2/2]

const_reference bm::ByteContainer::back ( ) const
inline

Access the last byte of the container. Undefined if the container is empty.

◆ begin() [1/2]

iterator bm::ByteContainer::begin ( )
inline

NC.

◆ begin() [2/2]

const_iterator bm::ByteContainer::begin ( ) const
inline

NC.

◆ clear()

void bm::ByteContainer::clear ( )
inline

Clears the contents of the container.

◆ data() [1/2]

const char* bm::ByteContainer::data ( ) const
inlinenoexcept

Returns pointer to the underlying array serving as element storage. The pointer is such that range [data(); data() + size()) is always a valid range, even if the container is empty.

◆ data() [2/2]

char* bm::ByteContainer::data ( )
inlinenoexcept

Returns pointer to the underlying array serving as element storage. The pointer is such that range [data(); data() + size()) is always a valid range, even if the container is empty.

◆ end() [1/2]

iterator bm::ByteContainer::end ( )
inline

NC.

◆ end() [2/2]

const_iterator bm::ByteContainer::end ( ) const
inline

NC.

◆ front() [1/2]

reference bm::ByteContainer::front ( )
inline

Access the first byte of the container. Undefined if the container is empty.

◆ front() [2/2]

const_reference bm::ByteContainer::front ( ) const
inline

Access the first byte of the container. Undefined if the container is empty.

◆ insert()

void bm::ByteContainer::insert ( iterator  pos,
const ByteContainer other 
)
inline

Inserts another ByteContainer object into this container, before pos.

◆ operator!=()

bool bm::ByteContainer::operator!= ( const ByteContainer other) const
inline

Returns true is the contents of the containers are not equal.

◆ operator==()

bool bm::ByteContainer::operator== ( const ByteContainer other) const
inline

Returns true is the contents of the containers are equal.

◆ operator[]() [1/2]

reference bm::ByteContainer::operator[] ( size_type  n)
inline

Access the character at position n. Will assert if n is greater or equal than the number of elements in the container.

◆ operator[]() [2/2]

const_reference bm::ByteContainer::operator[] ( size_type  n) const
inline

Access the character at position n. Will assert if n is greater or equal than the number of elements in the container.

◆ push_back()

void bm::ByteContainer::push_back ( char  c)
inline

Appends a character at the end of the container.

◆ reserve()

void bm::ByteContainer::reserve ( size_t  n)
inline

Increase the capacity of the container.

◆ resize() [1/2]

void bm::ByteContainer::resize ( size_t  n)
inline

Resizes the container to contain bytes.

◆ resize() [2/2]

void bm::ByteContainer::resize ( size_t  n,
char  c 
)
inline

Resizes the container to contain bytes, initializing the new bytes to c

◆ size()

size_type bm::ByteContainer::size ( ) const
inlinenoexcept

Returns the number of bytes in the container.

◆ to_hex() [1/2]

std::string bm::ByteContainer::to_hex ( bool  upper_case = false) const
inline

Returns the hexadecimal representation of the byte container as a string.

◆ to_hex() [2/2]

std::string bm::ByteContainer::to_hex ( size_t  start,
size_t  s,
bool  upper_case = false 
) const

Returns the hexadecimal representation of the bytes with a position in the range [start, start + s) as a string


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