libptpmgmt  1.4
libptpmgmt library that provides the functionality of linuxptp pmc
Public Member Functions | Static Public Member Functions | List of all members
Binary Class Reference

Hold octets. More...

#include <bin.h>

Public Member Functions

 Binary (const Binary &rhs)
 
 Binary (const void *buf, const size_t length)
 
 Binary (const size_t length, uint8_t set=0)
 
 Binary (const std::string &string)
 
Binaryoperator= (const Binary &rhs)
 
size_t length () const
 
size_t size () const
 
bool empty () const
 
const uint8_t * get () const
 
std::string getBinString () const
 
BinarysetBin (const void *buf, const size_t length)
 
BinarysetBin (const Binary &rhs)
 
BinarysetBin (const std::string &string)
 
BinarysetBin (const size_t position, const uint8_t value)
 
const uint8_t getBin (const size_t position) const
 
uint8_t & operator[] (const size_t position)
 
Binaryresize (const size_t length)
 
Binaryclear ()
 
void copy (uint8_t *target) const
 
Binaryoperator+= (const uint8_t octet)
 
Binaryappend (const uint8_t octet)
 
Binaryoperator+= (const Binary &rhs)
 
Binaryappend (const Binary &rhs)
 
std::string toIp () const
 
bool fromIp (const std::string &string)
 
bool fromIp (const std::string &string, int domain)
 
std::string toId (const std::string &sep=":") const
 
bool fromId (const std::string &string)
 
bool fromMac (const std::string &string)
 
bool isMacLen () const
 
bool eui48ToEui64 ()
 
bool fromHex (const std::string &hex)
 
std::string toHex () const
 
bool fromBase64 (const std::string &bin64, bool pad=false)
 
std::string toBase64 (bool pad=true, char v62='+', char v63='/')
 
bool operator== (const Binary &rhs) const
 
bool eq (const Binary &rhs) const
 
bool operator< (const Binary &rhs) const
 
bool less (const Binary &rhs) const
 

Static Public Member Functions

static std::string bufToId (const uint8_t *id, size_t length)
 
static std::string bufToId (const uint8_t *id, size_t length, const std::string &sep)
 
static std::string bufToHex (const uint8_t *bin, size_t length)
 

Detailed Description

Hold octets.

Note
functions returning std::string for readable strings

Constructor & Destructor Documentation

◆ Binary() [1/4]

Binary::Binary ( const Binary rhs)

Copy constructor

Parameters
[in]rhsobject

◆ Binary() [2/4]

Binary::Binary ( const void *  buf,
const size_t  length 
)

Constructor from buffer

Parameters
[in]bufpointer to Binary octets
[in]length

◆ Binary() [3/4]

Binary::Binary ( const size_t  length,
uint8_t  set = 0 
)

Constructor buffer with fixed length

Parameters
[in]lengthof buffer
[in]setvalue to set all octests

◆ Binary() [4/4]

Binary::Binary ( const std::string &  string)

Constructor from binary based string

Parameters
[in]stringstring with octets content

Member Function Documentation

◆ append() [1/2]

Binary& Binary::append ( const Binary rhs)

append octets

Parameters
[in]rhsBinary to add
Returns
reference to itself

◆ append() [2/2]

Binary& Binary::append ( const uint8_t  octet)

Append single octet

Parameters
[in]octetto add
Returns
reference to itself

◆ bufToHex()

static std::string Binary::bufToHex ( const uint8_t *  bin,
size_t  length 
)
static

Convert Binary to hex string

Parameters
[in]binpointer to memory buffer
[in]lengthof memory buffer
Returns
hex string

◆ bufToId() [1/2]

static std::string Binary::bufToId ( const uint8_t *  id,
size_t  length 
)
static

Convert Binary ID to string

Parameters
[in]idpointer to memory buffer
[in]lengthof memory buffer
Returns
address
Note
Support MAC addresses
Remarks
keep for ABI backward compatibility.

◆ bufToId() [2/2]

static std::string Binary::bufToId ( const uint8_t *  id,
size_t  length,
const std::string &  sep 
)
static

Convert Binary ID to string with a selected seperator

Parameters
[in]idpointer to memory buffer
[in]lengthof memory buffer
[in]sepseperator to use
Returns
address
Note
Support MAC addresses

◆ clear()

Binary& Binary::clear ( )

Resize to size 0

◆ copy()

void Binary::copy ( uint8_t *  target) const

Copy Binary to target memory block

Parameters
[in,out]targetmemory block

◆ empty()

bool Binary::empty ( ) const
inline

Return if Binary is empty

Returns
true if empty

◆ eq()

bool Binary::eq ( const Binary rhs) const

Compare binaries

Parameters
[in]rhsBinary to compare
Returns
true if binaries are identical

◆ eui48ToEui64()

bool Binary::eui48ToEui64 ( )

Convert ID from EUI48 to EUI64 using 0xfffe padding

Returns
true if ID is EUI64 after conversion

◆ fromBase64()

bool Binary::fromBase64 ( const std::string &  bin64,
bool  pad = false 
)

Convert from Base64 string

Parameters
[in]bin64Base64 string
[in]padis mandatory
Returns
true if conversion pass
Note
support RFC 4648, with or without padding. Both standard and "URL and filename safe". And IMAP mailbox names from RFC 3501 The function probe the characters for value 62, 63 to match to one of the standards.

◆ fromHex()

bool Binary::fromHex ( const std::string &  hex)

Convert Hex to Binary with optional separators

Parameters
[in]hexstring
Returns
true if hex is proper

◆ fromId()

bool Binary::fromId ( const std::string &  string)

Convert ID address string to Binary

Parameters
[in]stringaddress
Returns
true if valid ID address
Note
Support MAC addresses

◆ fromIp() [1/2]

bool Binary::fromIp ( const std::string &  string)

Convert IP address string to Binary

Parameters
[in]stringaddress
Returns
true if valid IP address version 4 or 6
Note
this function will toss old value

◆ fromIp() [2/2]

bool Binary::fromIp ( const std::string &  string,
int  domain 
)

Convert IP address string to Binary

Parameters
[in]stringaddress
[in]domainof IP to use
Returns
true if valid IP address version 4 or 6
Note
this function will toss old value

◆ fromMac()

bool Binary::fromMac ( const std::string &  string)
inline

Convert MAC address string to Binary

Parameters
[in]stringaddress
Returns
true if MAC address

◆ get()

const uint8_t* Binary::get ( ) const
inline

Get pointer to Binary

Returns
pointer to octets

◆ getBin()

const uint8_t Binary::getBin ( const size_t  position) const

Get octet in position

Parameters
[in]positionin Binary octets
Returns
octet value or zero if out of range

◆ getBinString()

std::string Binary::getBinString ( ) const
inline

Get binary content in a string

Returns
string with binary content
Note
for scripts, to use unpacking assignment and split octets into array or list

◆ isMacLen()

bool Binary::isMacLen ( ) const
inline

Check if ID length is a valid MAC address

Returns
true if ID length is valid MAC length

◆ length()

size_t Binary::length ( ) const
inline

Get Binary length

Returns
Binary length

◆ less()

bool Binary::less ( const Binary rhs) const

Compare binaries

Parameters
[in]rhsBinary to compare
Returns
true if binary is smaller

◆ operator+=() [1/2]

Binary& Binary::operator+= ( const Binary rhs)
inline

append octets using operator +=

Parameters
[in]rhsBinary to add
Returns
reference to itself
Note
script can use the append() function.

◆ operator+=() [2/2]

Binary& Binary::operator+= ( const uint8_t  octet)
inline

Append single octet using operator +=

Parameters
[in]octetto add
Returns
reference to itself
Note
script can use the append() function.

◆ operator<()

bool Binary::operator< ( const Binary rhs) const
inline

Compare binaries

Parameters
[in]rhsBinary to compare
Returns
true if binary is smaller

◆ operator=()

Binary& Binary::operator= ( const Binary rhs)

Copy value from another object

Parameters
[in]rhsBinary to assign
Returns
reference to itself

◆ operator==()

bool Binary::operator== ( const Binary rhs) const
inline

Compare binaries

Parameters
[in]rhsBinary to compare
Returns
true if binaries are identical

◆ operator[]()

uint8_t& Binary::operator[] ( const size_t  position)

Get octet in position Caller can change value using

bin[pos] = new_value
Parameters
[in]positionin Binary octets
Returns
octet value or zero if out of range

◆ resize()

Binary& Binary::resize ( const size_t  length)

Resize buffer

Parameters
[in]lengthnew length

◆ setBin() [1/4]

Binary& Binary::setBin ( const Binary rhs)

Set new value from binary based string

Parameters
[in]rhsBinary to assign
Returns
reference to itself
Note
for scripts, to use packing assignment and create a string from array or list of octets

◆ setBin() [2/4]

Binary& Binary::setBin ( const size_t  position,
const uint8_t  value 
)

Set value in position

Parameters
[in]positionin Binary octets
[in]valueto set in positions
Returns
reference to itself
Note
resize the Binary as needed

◆ setBin() [3/4]

Binary& Binary::setBin ( const std::string &  string)

Set new value from binary based string

Parameters
[in]stringstring with octets content
Returns
reference to itself
Note
for scripts, to use packing assignment and create a string from array or list of octets

◆ setBin() [4/4]

Binary& Binary::setBin ( const void *  buf,
const size_t  length 
)

Set new value

Parameters
[in]bufpointer to Binary octets
[in]length
Returns
reference to itself

◆ size()

size_t Binary::size ( ) const
inline

Get Binary length

Returns
Binary length

◆ toBase64()

std::string Binary::toBase64 ( bool  pad = true,
char  v62 = '+',
char  v63 = '/' 
)

Convert to Base64 string

Parameters
[in]padwith or without
[in]v62character to use for value 62
[in]v63character to use for value 63
Returns
base64 string
Note
default values for 62 and 63 follow the standard from RFC 4648.
Attention
The function do not verify proper characters for values 62, 63. The caller should use proper characters.

◆ toHex()

std::string Binary::toHex ( ) const
inline

Convert Binary to hex string

Returns
hex string

◆ toId()

std::string Binary::toId ( const std::string &  sep = ":") const
inline

Convert ID address to string

Parameters
[in]sepseperator to use
Returns
address
Note
Support MAC addresses

◆ toIp()

std::string Binary::toIp ( ) const

Convert IP address to string

Returns
Ip address
Note
Support both IP version 4 and 6
the user should use with Binary IP address the class does not verify

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