reSIProcate
SIP stack, Dialog Usage Manager and related libraries
Loading...
Searching...
No Matches
resip::Data Class Reference

An alternative to std::string, encapsulates an arbitrary buffer of bytes. More...

#include <Data.hxx>

Classes

class  PreallocateType
 

Public Types

enum  DoubleDigitPrecision {
  ZeroDigitPrecision = 0 , OneDigitPrecision , TwoDigitPrecision , ThreeDigitPrecision ,
  FourDigitPrecision , FiveDigitPrecision , SixDigitPrecision , SevenDigitPrecision ,
  EightDigitPrecision , NineDigitPrecision , TenDigitPrecision , MaxDigitPrecision
}
 
enum  ShareEnum { Borrow =0 , Share =1 , Take =2 }
 The various memory management behaviors. More...
 
enum  EncodingType { BINARY , BASE64 , HEX }
 
typedef size_t size_type
 

Public Member Functions

 RESIP_HeapCount (Data)
 
 Data ()
 
 Data (size_type capacity, const PreallocateType &)
 Creates a data with a specified initial capacity.
 
 Data (const char *str)
 Creates a data with a copy of the contents of the null-terminated string.
 
 Data (const char *buffer, size_type length)
 Creates a data with the contents of the buffer.
 
 Data (const unsigned char *buffer, size_type length)
 Creates a data with the contents of the buffer.
 
 Data (const Data &data)
 
 Data (Data &&data) noexcept
 
 Data (const std::string &str)
 Creates a data with the contents of the string.
 
 Data (int32_t value)
 Converts the passed in value into ascii-decimal representation, and then creates a "Data" containing that value.
 
 Data (uint32_t value)
 Converts the passed in value into ascii-decimal representation, and then creates a "Data" containing that value.
 
 Data (uint64_t value)
 Converts the passed in value into ascii-decimal representation, and then creates a "Data" containing that value.
 
 Data (double value, Data::DoubleDigitPrecision precision=FourDigitPrecision)
 Converts the passed in value into ascii-decimal representation, and then creates a "Data" containing that value.
 
 Data (bool value)
 Creates a buffer containing "true" or "false", depending on the value of "value".
 
 Data (char c)
 Creates a buffer containing a single character.
 
 Data (ShareEnum, const char *buffer, size_type length)
 Creates a Data from the passed-in buffer.
 
 Data (ShareEnum, const char *buffer, size_type length, size_type capacity)
 Creates a Data from the passed-in buffer.
 
 Data (ShareEnum, const char *buffer)
 Takes a null-terminated string and creates a buffer.
 
 Data (ShareEnum, const Data &staticData)
 Lazily creates a Data from the passed-in Data.
 
 ~Data ()
 
Data & setBuf (ShareEnum se, const char *buf, size_type length)
 Set the Data to hold {buf} using share type {se}, which may be any of Share (read-only, no-free), Borrow (read-write, no-free) or Take (read-write, yes-free).
 
Data & setBuf (ShareEnum se, const char *str)
 Convience function to call setBuf() with a NULL-terminated string.
 
Data & takeBuf (Data &other) noexcept
 Take the data from {other}.
 
Data & duplicate (const Data &other)
 Functional equivalent of: *this = Data(buf, length) and Data& copy(const char *buf, size_type length) but avoids an actual copy of the data if {other} is Shared or Borrowed.
 
Data & copy (const char *buf, size_type length)
 Functional equivalent of: *this = Data(buf, length) but avoids the intermediate allocation and free.
 
char * getBuf (size_type length)
 Set size to be exactly {length}, extending buffer if needed.
 
Data & operator= (const Data &data)
 
Data & operator= (Data &&data) noexcept
 
 operator std::string () const
 
Data & operator= (const char *str)
 Assigns a null-terminated string to the buffer.
 
Data & operator= (const std::string &str)
 
Data operator+ (const Data &rhs) const
 Concatenates two Data objects.
 
Data operator+ (const char *str) const
 Concatenates a null-terminated string after the Data object.
 
Data operator+ (char c) const
 Concatenates a single byte after Data object.
 
Data & operator+= (const Data &rhs)
 Appends a data object to this one.
 
Data & operator+= (const char *str)
 Appends a null-terminated string to the end of the Data object.
 
Data & operator+= (char c)
 Appends a single byte to the Data object.
 
Data & operator^= (const Data &rhs)
 Performs an in-place exclusive-or of this buffer buffer with the specified buffer.
 
char & operator[] (size_type p)
 Returns the character at the specified position.
 
char operator[] (size_type p) const
 Returns the character at the specified position.
 
char & at (size_type p)
 Returns the character at the specified position.
 
void reserve (size_type capacity)
 Guarantees that the underlying buffer used by the Data is at least the number of bytes specified.
 
Data & append (const char *str, size_type len)
 Appends the specified number of bytes to the end of this Data.
 
size_type truncate (size_type len)
 Shortens the size of this Data.
 
Data & truncate2 (size_type len)
 Shortens the size of this Data so length is at most of {len}.
 
bool empty () const noexcept
 Checks whether the Data is empty.
 
size_type size () const noexcept
 Returns the number of bytes in this Data.
 
const char * data () const noexcept
 Returns a pointer to the contents of this Data.
 
const char * c_str () const
 Returns a null-terminated string representing.
 
std::string toString () const
 Convert to a C++ string.
 
const char * begin () const noexcept
 Returns a pointer to the beginning of the buffer used by the Data.
 
const char * end () const noexcept
 Returns a pointer to the end of the buffer used by the Data.
 
Data md5 (EncodingType type=HEX) const
 Computes the MD5 hash of the current data.
 
Data & lowercase ()
 Converts this Data to lowercase.
 
Data & uppercase ()
 Converts this Data to uppercase.
 
Data & schemeLowercase ()
 Converts this Data to lowercase, assuming this Data only consists of scheme characters.
 
Data hex () const
 Returns a hexadecimal representation of the contents of this Data.
 
Data fromHex () const
 Returns the binary form of the hexadecimal string in this Data.
 
Data escaped () const
 Returns a representation of the contents of the data with any non-printable characters escaped.
 
Data charEncoded () const
 Performs RFC 3261 escaping of SIP URIs.
 
Data charUnencoded () const
 Performs RFC 3261 un-escaping of SIP URIs.
 
Data urlEncoded () const
 Performs in-place HTTP URL escaping of a Data.
 
Data urlDecoded () const
 Performs in-place HTTP URL un-escaping of a Data.
 
EncodeStream & urlEncode (EncodeStream &s) const
 Escapes a Data to a stream according to HTTP URL encoding rules.
 
EncodeStream & urlDecode (EncodeStream &s) const
 Un-escapes a Data to a stream according to HTTP URL encoding rules.
 
Data xmlCharDataEncode () const
 Performs in-place XML Character Data escaping of a Data.
 
Data xmlCharDataDecode () const
 Performs in-place XML Character Data un-escaping of a Data.
 
EncodeStream & xmlCharDataEncode (EncodeStream &s) const
 Escapes a Data to a stream according to XML Character Data encoding rules.
 
EncodeStream & xmlCharDataDecode (EncodeStream &s) const
 Un-escapes a Data to a stream according to XML Character Data encoding rules.
 
Data trunc (size_type trunc) const
 Shortens the size of this Data.
 
Data & clear ()
 Clears the contents of this Data.
 
int convertInt () const
 Takes the contents of the Data and converts them to an integer.
 
unsigned long convertUnsignedLong () const
 
size_t convertSize () const
 Takes the contents of the Data and converts them to a size_t.
 
double convertDouble () const
 Takes the contents of the Data and converts them to a double precision floating point value.
 
uint64_t convertUInt64 () const
 Takes the contents of the Data and converts them to an unsigned 64-bit integer.
 
bool prefix (const Data &pre) const noexcept
 Returns true if this Data starts with the bytes indicated by the passed-in Data.
 
bool prefixNoCase (const Data &pre) const noexcept
 
bool postfix (const Data &post) const noexcept
 Returns true if this Data ends with the bytes indicated by the passed-in Data.
 
bool postfixNoCase (const Data &post) const noexcept
 
Data substr (size_type first, size_type count=Data::npos) const
 Copies a portion of this Data into a new Data.
 
size_type find (const Data &match, size_type start=0) const
 Finds a specified sequence of bytes in this Data.
 
int replace (const Data &match, const Data &target, int max=INT_MAX)
 Replaces up to max occurrences of the bytes match with target.
 
Data base64decode () const
 Performs RFC 3548 Base 64 decoding of the contents of this data.
 
Data base64encode (bool useUrlSafe=false) const
 Performs RFC 3548 Base 64 encoding of the contents of this data.
 
size_t hash () const
 Creates a 32-bit hash based on the contents of this Data.
 
size_t caseInsensitivehash () const
 Creates a 32-bit hash based on the contents of this Data, after normalizing any alphabetic characters to lowercase.
 
size_t caseInsensitiveTokenHash () const
 A faster version of caseInsensitiveHash that has the same collision properties if this Data is made up of RFC 3261 token characters.
 
size_t keyedHash () const
 Creates a keyed hash based on the contents of this Data.
 
size_t keyedCaseInsensitiveHash () const
 Creates a keyed hash based on the contents of this Data, after normalizing ASCII alphabetic characters to lowercase.
 
bool caseInsensitiveTokenCompare (const Data &rhs) const
 
bool sizeEqualCaseInsensitiveTokenCompare (const Data &rhs) const
 
template<class Predicate >
EncodeStream & escapeToStream (EncodeStream &str, Predicate shouldEscape) const
 Performs escaping of this Data according to the indicated Predicate.
 
std::ostream & escapeToStream (std::ostream &str, const std::bitset< 256 > &shouldEscape) const
 Performs escaping of this Data according to a bitset.
 

Static Public Member Functions

template<class T >
static Data from (const T &x)
 Converts from arbitrary other type to Data.
 
static bool init (DataLocalSize< RESIP_DATA_LOCAL_SIZE > arg)
 Initializes Data class.
 
static size_t rawHash (const unsigned char *c, size_t size)
 Creates a 32-bit hash based on the contents of the indicated buffer.
 
static size_t rawCaseInsensitiveHash (const unsigned char *c, size_t size)
 Creates a 32-bit hash based on the contents of the indicated buffer, after normalizing any alphabetic characters to lowercase.
 
static size_t rawCaseInsensitiveTokenHash (const unsigned char *c, size_t size)
 A faster version of rawCaseInsensitiveHash that has the same collision properties if this Data is made up of RFC 3261 token characters.
 
static size_t rawKeyedHash (const unsigned char *c, size_t size)
 Creates a hash based on the contents of the indicated buffer, using SipHash-1-3 with a key chosen randomly once per process.
 
static size_t rawKeyedCaseInsensitiveHash (const unsigned char *c, size_t size)
 As rawKeyedHash, after normalizing ASCII alphabetic characters to lowercase; consistent with isEqualNoCase.
 
static std::bitset< 256 > toBitset (const resip::Data &chars)
 Creates a bitset reflecting the contents of this data (as a set) ie.
 
static Data fromFile (const Data &filename)
 

Static Public Attributes

static const PreallocateType Preallocate
 used only to disambiguate constructors
 
static const Data Empty
 Constant that represents a zero-length data.
 
static const size_type npos = std::string::npos
 Represents an impossible position; returned to indicate failure to find.
 

Friends

class ParseBuffer
 
class DataBuffer
 
class DataStream
 
class oDataStream
 
class ::TestData
 
class MD5Buffer
 
bool operator== (const Data &lhs, const Data &rhs)
 
bool operator== (const Data &lhs, const char *rhs)
 
bool operator== (const Data &lhs, const std::string &rhs) noexcept
 
bool operator< (const Data &lhs, const Data &rhs)
 
bool operator< (const Data &lhs, const char *rhs)
 
bool operator< (const char *lhs, const Data &rhs)
 
bool operator< (const Data &lhs, const std::string &rhs) noexcept
 
bool operator< (const std::string &lhs, const Data &rhs) noexcept
 
std::ostream & operator<< (std::ostream &strm, const Data &d)
 
EncodeStream & operator<< (EncodeStream &strm, const Data &d)
 

Detailed Description

An alternative to std::string, encapsulates an arbitrary buffer of bytes.

It has a variety of memory management styles that can be established at contruction time and changed later via setBuf().

Three modes of allocation are currently available:

  • 'Borrow' - The Data instance is borrowing the memory from the passed in buffer. It will modify its contents as necessary, but will not deallocate it.
  • 'Share' - The Data instance will use the buffer in a read-only mode. If any attempt is made to modify the contents of the Data, it will copy the buffer and modify it.
  • 'Take' - The Data instance takes complete ownership of the buffer. The buffer is deallocated using delete[].

Additionally, Data has a small locally-allocated buffer (member buffer) that it will use to hold small amounts of data. By default, this buffer can contain 16 bytes, meaning that Data will not use the heap unless it needs more than 16 bytes of space. The tradeoff here, of course, is that instances of Data will be larger than instances of std::string. Generally speaking, if you expect to need more than 16 bytes of room, and you cannot make good use of the flexible memory management offered by Data, you may want to use a std::string instead.

See also
RESIP_HeapCount
Todo:
It might be worthwhile examining the heap usage of this class in the context of using realloc everywhere appropriate. (realloc is defined in ANSI C, SVID, and the OpenGroup "Single Unix Specification").

Definition at line 89 of file Data.hxx.

Member Typedef Documentation

◆ size_type

typedef size_t resip::Data::size_type

Definition at line 94 of file Data.hxx.

Member Enumeration Documentation

◆ DoubleDigitPrecision

Enumerator
ZeroDigitPrecision 
OneDigitPrecision 
TwoDigitPrecision 
ThreeDigitPrecision 
FourDigitPrecision 
FiveDigitPrecision 
SixDigitPrecision 
SevenDigitPrecision 
EightDigitPrecision 
NineDigitPrecision 
TenDigitPrecision 
MaxDigitPrecision 

Definition at line 217 of file Data.hxx.

◆ EncodingType

Enumerator
BINARY 
BASE64 
HEX 

Definition at line 655 of file Data.hxx.

◆ ShareEnum

The various memory management behaviors.

Enumerator
Borrow 

The Data instance is borrowing the memory from the passed in buffer.

It will modify its contents as necessary, but will not deallocate it.

Share 

The Data instance will use the buffer in a read-only mode.

If any attempt is made to modify the contents of the Data, it will copy the buffer and modify it.

Take 

The Data instance takes complete ownership of the buffer.

The buffer must have been allocate using "new char[]" so that it can be freed with "delete char[]".

Definition at line 254 of file Data.hxx.

Constructor & Destructor Documentation

◆ Data() [1/18]

resip::Data::Data ( )
inline

Definition at line 96 of file Data.hxx.

◆ Data() [2/18]

Data::Data ( size_type  capacity,
const PreallocateType &   
)

Creates a data with a specified initial capacity.

Parameters
capacityThe initial capacity of the buffer
fooThis parameter is ignored; it is merely used to disambiguate this constructor from the constructor that takes a single int. Always pass Data::Preallocate.

Definition at line 220 of file Data.cxx.

◆ Data() [3/18]

Data::Data ( const char *  str)

Creates a data with a copy of the contents of the null-terminated string.

Warning
Passing a non-null-terminated string to this method would be a Really Bad Thing.

Definition at line 347 of file Data.cxx.

◆ Data() [4/18]

Data::Data ( const char *  buffer,
size_type  length 
)

Creates a data with the contents of the buffer.

Parameters
lengthNumber of bytes in the buffer

Definition at line 252 of file Data.cxx.

◆ Data() [5/18]

Data::Data ( const unsigned char *  buffer,
size_type  length 
)

Creates a data with the contents of the buffer.

Parameters
lengthNumber of bytes in the buffer

Definition at line 257 of file Data.cxx.

◆ Data() [6/18]

Data::Data ( const Data &  data)

Definition at line 367 of file Data.cxx.

◆ Data() [7/18]

Data::Data ( Data &&  data)
noexcept

Definition at line 372 of file Data.cxx.

◆ Data() [8/18]

Data::Data ( const std::string &  str)

Creates a data with the contents of the string.

Definition at line 352 of file Data.cxx.

◆ Data() [9/18]

Data::Data ( int32_t  value)
explicit

Converts the passed in value into ascii-decimal representation, and then creates a "Data" containing that value.

(E.g. "Data(75)" will create a Data with length=2, and contents of 0x37 0x35).

Definition at line 384 of file Data.cxx.

◆ Data() [10/18]

Data::Data ( uint32_t  value)
explicit

Converts the passed in value into ascii-decimal representation, and then creates a "Data" containing that value.

(E.g. "Data(75)" will create a Data with length=2, and contents of 0x37 0x35).

Definition at line 528 of file Data.cxx.

◆ Data() [11/18]

Data::Data ( uint64_t  value)
explicit

Converts the passed in value into ascii-decimal representation, and then creates a "Data" containing that value.

(E.g. "Data(75)" will create a Data with length=2, and contents of 0x37 0x35).

Definition at line 566 of file Data.cxx.

◆ Data() [12/18]

Data::Data ( double  value,
Data::DoubleDigitPrecision  precision = FourDigitPrecision 
)
explicit

Converts the passed in value into ascii-decimal representation, and then creates a "Data" containing that value.

(E.g. "Data(75.4,2)" will create a Data with length=4, and contents of 0x37 0x35 0x2E 0x34).

Parameters
precisionNumber of digits after the decimal point. Trailing zeros will be removed.

Definition at line 441 of file Data.cxx.

◆ Data() [13/18]

Data::Data ( bool  value)
explicit

Creates a buffer containing "true" or "false", depending on the value of "value".

Definition at line 619 of file Data.cxx.

◆ Data() [14/18]

Data::Data ( char  c)
explicit

Creates a buffer containing a single character.

Is this silly? Maybe. Perhaps it can be removed.

Definition at line 605 of file Data.cxx.

◆ Data() [15/18]

Data::Data ( ShareEnum  se,
const char *  buffer,
size_type  length 
)

Creates a Data from the passed-in buffer.

See also
ShareEnum

Definition at line 307 of file Data.cxx.

◆ Data() [16/18]

Data::Data ( ShareEnum  se,
const char *  buffer,
size_type  length,
size_type  capacity 
)

Creates a Data from the passed-in buffer.

See also
ShareEnum

Definition at line 316 of file Data.cxx.

◆ Data() [17/18]

Data::Data ( ShareEnum  se,
const char *  buffer 
)

Takes a null-terminated string and creates a buffer.

See also
ShareEnum
Warning
Passing a non-null-terminated string to this method would be a Really Bad Thing.

Definition at line 325 of file Data.cxx.

◆ Data() [18/18]

Data::Data ( ShareEnum  se,
const Data &  staticData 
)

Lazily creates a Data from the passed-in Data.

See also
ShareEnum
Warning
Calling this with "Take" or "Borrow" is invalid and will cause an assertion or crash.
Todo:
This implementation has some confusing and conflicting comments. (e.g. is Borrow actually okay? Can there be some way to use it with Take as long as you play with mShareEnum correctly?)

Definition at line 334 of file Data.cxx.

◆ ~Data()

resip::Data::~Data ( )
inline

Definition at line 316 of file Data.hxx.

Member Function Documentation

◆ append()

Data & Data::append ( const char *  str,
size_type  len 
)

Appends the specified number of bytes to the end of this Data.

Definition at line 1058 of file Data.cxx.

◆ at()

char & Data::at ( size_type  p)

Returns the character at the specified position.

Definition at line 988 of file Data.cxx.

◆ base64decode()

Data Data::base64decode ( ) const

Performs RFC 3548 Base 64 decoding of the contents of this data.

Returns
A new buffer containing the unencoded representation

Definition at line 2607 of file Data.cxx.

◆ base64encode()

Data Data::base64encode ( bool  useUrlSafe = false) const

Performs RFC 3548 Base 64 encoding of the contents of this data.

Returns
A new buffer containing the base64 representation

Definition at line 2682 of file Data.cxx.

◆ begin()

const char * resip::Data::begin ( ) const
inlinenoexcept

Returns a pointer to the beginning of the buffer used by the Data.

Definition at line 642 of file Data.hxx.

◆ c_str()

const char * Data::c_str ( ) const

Returns a null-terminated string representing.

Note
Depending on the memory management scheme being used, this method often copies the contents of the Data; consequently, this method is rather expensive and should be avoided when possible.
Warning
Calling this method is a pretty bad idea if the contents of Data are binary (i.e. may contain a null in the middle of the Data).

Definition at line 1097 of file Data.cxx.

◆ caseInsensitivehash()

size_t Data::caseInsensitivehash ( ) const

Creates a 32-bit hash based on the contents of this Data, after normalizing any alphabetic characters to lowercase.

Definition at line 2361 of file Data.cxx.

◆ caseInsensitiveTokenCompare()

bool resip::Data::caseInsensitiveTokenCompare ( const Data &  rhs) const
inline

Definition at line 997 of file Data.hxx.

◆ caseInsensitiveTokenHash()

size_t Data::caseInsensitiveTokenHash ( ) const

A faster version of caseInsensitiveHash that has the same collision properties if this Data is made up of RFC 3261 token characters.

Note
This is not guaranteed to return the same value as rawCaseInsensitiveHash.

Definition at line 2367 of file Data.cxx.

◆ charEncoded()

Data Data::charEncoded ( ) const

Performs RFC 3261 escaping of SIP URIs.

Note
This method is relatively inefficient
Deprecated:
Use escapeToStream instead
Todo:
This method should be removed
See also
escapeToStream

Definition at line 1243 of file Data.cxx.

◆ charUnencoded()

Data Data::charUnencoded ( ) const

Performs RFC 3261 un-escaping of SIP URIs.

Note
This method is relatively inefficient
Bug:
This method can assert if a "%00" comes in off the wire. That's really bad form.
Deprecated:
Use something more in the spirit of escapeToStream instead
Todo:
This method should be removed
See also
escapeToStream

Definition at line 1289 of file Data.cxx.

◆ clear()

Data & resip::Data::clear ( )
inline

Clears the contents of this Data.

This call does not modify the capacity of the Data. It does not write terminating NULL, and thus is safe to use with external buffers.

Definition at line 800 of file Data.hxx.

◆ convertDouble()

double Data::convertDouble ( ) const

Takes the contents of the Data and converts them to a double precision floating point value.

Will strip leading whitespace. This method stops upon encountering the first non-decimal digit (with exceptions made for decimal points and leading negative signs).

Definition at line 1827 of file Data.cxx.

◆ convertInt()

int Data::convertInt ( ) const

Takes the contents of the Data and converts them to an integer.

Will strip leading whitespace. This method stops upon encountering the first non-decimal digit (with exceptions made for leading negative signs).

Definition at line 1684 of file Data.cxx.

◆ convertSize()

size_t Data::convertSize ( ) const

Takes the contents of the Data and converts them to a size_t.

Will strip leading whitespace. This method stops upon encountering the first non-decimal digit.

Definition at line 1792 of file Data.cxx.

◆ convertUInt64()

uint64_t Data::convertUInt64 ( ) const

Takes the contents of the Data and converts them to an unsigned 64-bit integer.

Will strip leading whitespace. This method stops upon encountering the first non-decimal digit.

Definition at line 1758 of file Data.cxx.

◆ convertUnsignedLong()

unsigned long Data::convertUnsignedLong ( ) const

Definition at line 1724 of file Data.cxx.

◆ copy()

Data & Data::copy ( const char *  buf,
size_type  length 
)

Functional equivalent of: *this = Data(buf, length) but avoids the intermediate allocation and free.

Also, will never decrease capacity. Safe to call even if {buf} is part of {this}.

Note
The result is always NULL terminated. Unfortunately, this requires a buffer allocation even if capacity exactly equals length.

Definition at line 701 of file Data.cxx.

◆ data()

const char * resip::Data::data ( ) const
inlinenoexcept

Returns a pointer to the contents of this Data.

This is the preferred mechanism for accessing the bytes inside the Data.

Note
The value returned is NOT necessarily null-terminated.

Definition at line 608 of file Data.hxx.

◆ duplicate()

Data & Data::duplicate ( const Data &  other)

Functional equivalent of: *this = Data(buf, length) and Data& copy(const char *buf, size_type length) but avoids an actual copy of the data if {other} is Shared or Borrowed.

Will have the same storage mode as {other}.

Definition at line 675 of file Data.cxx.

◆ empty()

bool resip::Data::empty ( ) const
inlinenoexcept

Checks whether the Data is empty.

Definition at line 591 of file Data.hxx.

◆ end()

const char * resip::Data::end ( ) const
inlinenoexcept

Returns a pointer to the end of the buffer used by the Data.

Definition at line 650 of file Data.hxx.

◆ escaped()

Data Data::escaped ( ) const

Returns a representation of the contents of the data with any non-printable characters escaped.

Warning
This is extremely slow, and should not be called except for debugging purposes.

Definition at line 1199 of file Data.cxx.

◆ escapeToStream() [1/2]

template<class Predicate >
EncodeStream & resip::Data::escapeToStream ( EncodeStream &  str,
Predicate  shouldEscape 
) const

Performs escaping of this Data according to the indicated Predicate.

Parameters
strA stream to which the escaped representation should be added.
shouldEscapeA functor which takes a single character as a parameter, and returns true if the character should be escaped, false if it should not.
Deprecated:
dlb – pass a 256 array of bits rather than a function.

Definition at line 1147 of file Data.hxx.

◆ escapeToStream() [2/2]

std::ostream & Data::escapeToStream ( std::ostream &  str,
const std::bitset< 256 > &  shouldEscape 
) const

Performs escaping of this Data according to a bitset.

Parameters
strA stream to which the escaped representation should be added.
shouldEscapeA bitset representing which chars should be escaped.

Definition at line 2489 of file Data.cxx.

◆ find()

Data::size_type Data::find ( const Data &  match,
size_type  start = 0 
) const

Finds a specified sequence of bytes in this Data.

Parameters
matchThe bytes to be found
startOffset into this Data to start the search
Returns
An index to the start of the found bytes.

Definition at line 1947 of file Data.cxx.

◆ from()

template<class T >
static Data resip::Data::from ( const T &  x)
inlinestatic

Converts from arbitrary other type to Data.

Requires the other type to have an operator<<.

Definition at line 398 of file Data.hxx.

◆ fromFile()

Data Data::fromFile ( const Data &  filename)
static

Definition at line 2539 of file Data.cxx.

◆ fromHex()

Data Data::fromHex ( ) const

Returns the binary form of the hexadecimal string in this Data.

Definition at line 1599 of file Data.cxx.

◆ getBuf()

char * Data::getBuf ( size_type  length)

Set size to be exactly {length}, extending buffer if needed.

Also, reallocate buffer if needed so that it is writable. Buffer contents is NOT initialized, and existing contents may or may not be preserved.

Note
Purpose of this function is to provide a working buffer of fixed size that the application fills in after this call.
If you want just the buffer without changing the size, use data() and cast-away the const-ness.
The result may or may not be NULL terminated. The buffer is NULL terminated only when safe to do so without extra reallocation.

Definition at line 723 of file Data.cxx.

◆ hash()

size_t Data::hash ( ) const

Creates a 32-bit hash based on the contents of this Data.

This is the default std::hash<Data> used by HashMap<Data, ...>.

Note
Fixed and predictable: don't use it for containers keyed by data a remote party chooses, as they can make all keys collide. See KeyedDataHash.

Definition at line 2355 of file Data.cxx.

◆ hex()

Data Data::hex ( ) const

Returns a hexadecimal representation of the contents of this Data.

Definition at line 1577 of file Data.cxx.

◆ init()

bool Data::init ( DataLocalSize< RESIP_DATA_LOCAL_SIZE >  arg)
static

Initializes Data class.

Note
This method is a link time constraint. Don't remove it.

Definition at line 215 of file Data.cxx.

◆ keyedCaseInsensitiveHash()

size_t Data::keyedCaseInsensitiveHash ( ) const

Creates a keyed hash based on the contents of this Data, after normalizing ASCII alphabetic characters to lowercase.

See also
rawKeyedCaseInsensitiveHash

Definition at line 2379 of file Data.cxx.

◆ keyedHash()

size_t Data::keyedHash ( ) const

Creates a keyed hash based on the contents of this Data.

See also
rawKeyedHash

Definition at line 2373 of file Data.cxx.

◆ lowercase()

Data & Data::lowercase ( )

Converts this Data to lowercase.

Note
This is silly unless the contents are ASCII.

Definition at line 1635 of file Data.cxx.

◆ md5()

Data Data::md5 ( EncodingType  type = HEX) const

Computes the MD5 hash of the current data.

Parameters
typeThe encoding of the return (default is HEX)
Returns
The MD5 hash, in the encoding specified by type.

Definition at line 1174 of file Data.cxx.

◆ operator std::string()

resip::Data::operator std::string ( ) const
inline

Definition at line 434 of file Data.hxx.

◆ operator+() [1/3]

Data Data::operator+ ( char  c) const

Concatenates a single byte after Data object.

Definition at line 1084 of file Data.cxx.

◆ operator+() [2/3]

Data Data::operator+ ( const char *  str) const

Concatenates a null-terminated string after the Data object.

Warning
Passing a non-null-terminated string to this method would be a Really Bad Thing.

Definition at line 1035 of file Data.cxx.

◆ operator+() [3/3]

Data Data::operator+ ( const Data &  rhs) const

Concatenates two Data objects.

Definition at line 951 of file Data.cxx.

◆ operator+=() [1/3]

Data & resip::Data::operator+= ( char  c)
inline

Appends a single byte to the Data object.

Definition at line 514 of file Data.hxx.

◆ operator+=() [2/3]

Data & resip::Data::operator+= ( const char *  str)
inline

Appends a null-terminated string to the end of the Data object.

Warning
Passing a non-null-terminated string to this method would be a Really Bad Thing.

Definition at line 504 of file Data.hxx.

◆ operator+=() [3/3]

Data & resip::Data::operator+= ( const Data &  rhs)
inline

Appends a data object to this one.

Definition at line 492 of file Data.hxx.

◆ operator=() [1/4]

Data & resip::Data::operator= ( const char *  str)
inline

Assigns a null-terminated string to the buffer.

Warning
Passing a non-null-terminated string to this method would be a Really Bad Thing. The strlen() inlined to take advantages of cases where the compiler knows the length statically.

Definition at line 447 of file Data.hxx.

◆ operator=() [2/4]

Data & resip::Data::operator= ( const Data &  data)
inline

Definition at line 425 of file Data.hxx.

◆ operator=() [3/4]

Data & resip::Data::operator= ( const std::string &  str)
inline

Definition at line 453 of file Data.hxx.

◆ operator=() [4/4]

Data & Data::operator= ( Data &&  data)
noexcept

Definition at line 918 of file Data.cxx.

◆ operator[]() [1/2]

char & resip::Data::operator[] ( size_type  p)
inline

Returns the character at the specified position.

Ensures that ownership of the buffer is taken, since the character could be modified by the caller.

Definition at line 532 of file Data.hxx.

◆ operator[]() [2/2]

char resip::Data::operator[] ( size_type  p) const
inline

Returns the character at the specified position.

Definition at line 542 of file Data.hxx.

◆ operator^=()

Data & Data::operator^= ( const Data &  rhs)

Performs an in-place exclusive-or of this buffer buffer with the specified buffer.

If the specifed buffer is longer than this buffer, then this buffer will first be expanded and zero-padded.

Definition at line 964 of file Data.cxx.

◆ postfix()

bool Data::postfix ( const Data &  post) const
noexcept

Returns true if this Data ends with the bytes indicated by the passed-in Data.

For example, if this Data is "abc", then postfix(Data("bc")) would be true; however, postfix(Data("ab")) would be false.

Definition at line 1910 of file Data.cxx.

◆ postfixNoCase()

bool Data::postfixNoCase ( const Data &  post) const
noexcept

Definition at line 1921 of file Data.cxx.

◆ prefix()

bool Data::prefix ( const Data &  pre) const
noexcept

Returns true if this Data starts with the bytes indicated by the passed-in Data.

For example, if this Data is "abc", then prefix(Data("ab")) would be true; however, prefix(Data("abcd")) would be false.

Definition at line 1888 of file Data.cxx.

◆ prefixNoCase()

bool Data::prefixNoCase ( const Data &  pre) const
noexcept

Definition at line 1899 of file Data.cxx.

◆ rawCaseInsensitiveHash()

size_t Data::rawCaseInsensitiveHash ( const unsigned char *  c,
size_t  size 
)
static

Creates a 32-bit hash based on the contents of the indicated buffer, after normalizing any alphabetic characters to lowercase.

Parameters
cPointer to the buffer to hash
sizeNumber of bytes to be hashed

Definition at line 2058 of file Data.cxx.

◆ rawCaseInsensitiveTokenHash()

size_t Data::rawCaseInsensitiveTokenHash ( const unsigned char *  c,
size_t  size 
)
static

A faster version of rawCaseInsensitiveHash that has the same collision properties if this Data is made up of RFC 3261 token characters.

Parameters
cPointer to the buffer to hash
sizeNumber of bytes to be hashed
Note
This is not guaranteed to return the same value as rawCaseInsensitiveHash.

Definition at line 2251 of file Data.cxx.

◆ rawHash()

size_t Data::rawHash ( const unsigned char *  c,
size_t  size 
)
static

Creates a 32-bit hash based on the contents of the indicated buffer.

Parameters
cPointer to the buffer to hash
sizeNumber of bytes to be hashed

Definition at line 2027 of file Data.cxx.

◆ rawKeyedCaseInsensitiveHash()

size_t Data::rawKeyedCaseInsensitiveHash ( const unsigned char *  c,
size_t  size 
)
static

As rawKeyedHash, after normalizing ASCII alphabetic characters to lowercase; consistent with isEqualNoCase.

Parameters
cPointer to the buffer to hash
sizeNumber of bytes to be hashed

Definition at line 2202 of file Data.cxx.

◆ rawKeyedHash()

size_t Data::rawKeyedHash ( const unsigned char *  c,
size_t  size 
)
static

Creates a hash based on the contents of the indicated buffer, using SipHash-1-3 with a key chosen randomly once per process.

Unlike rawHash, colliding inputs cannot be precomputed, so use this for hash containers keyed by data received from the network (see KeyedDataHash). Values differ from one process run to the next, so never store them or send them to another process.

Parameters
cPointer to the buffer to hash
sizeNumber of bytes to be hashed

Definition at line 2196 of file Data.cxx.

◆ replace()

int Data::replace ( const Data &  match,
const Data &  target,
int  max = INT_MAX 
)

Replaces up to max occurrences of the bytes match with target.

Returns the number of matches.

Definition at line 1964 of file Data.cxx.

◆ reserve()

void Data::reserve ( size_type  capacity)

Guarantees that the underlying buffer used by the Data is at least the number of bytes specified.

May cause reallocation of the buffer.

Definition at line 1049 of file Data.cxx.

◆ RESIP_HeapCount()

resip::Data::RESIP_HeapCount ( Data  )

◆ schemeLowercase()

Data & Data::schemeLowercase ( )

Converts this Data to lowercase, assuming this Data only consists of scheme characters.

Note
Assuming scheme contents allows the use of a bitmask instead of tolower(), which is faster. Why, you ask? A bitmask is sufficient to perform a lowercase operation on alphabetical data, since 'a' and 'A' only differ on bit 6; it is set for 'a', but not for 'A'. Digits always have bit 6 set, so setting it is a no-op. The last three characters in the scheme character set are '+', '-', and '.'; all of these have bit 6 set as well. Note that there is no corresponding efficient uppercase function; clearing bit 6 on either a digit or the the three remaining characters (+=.) will change them.

Definition at line 1661 of file Data.cxx.

◆ setBuf() [1/2]

Data & Data::setBuf ( ShareEnum  se,
const char *  buf,
size_type  length 
)

Set the Data to hold {buf} using share type {se}, which may be any of Share (read-only, no-free), Borrow (read-write, no-free) or Take (read-write, yes-free).

Both the capacity and current length are set to {length}; you can call truncate2() afterwords to shorten. The provided buffer (and its current contents) will be used going forward; any currently owned buffer will be released. NOTE: The {buf} param is declared const to support Share type; for Borrow and Take the buffer may be written (e.g., treated non-const).

Definition at line 627 of file Data.cxx.

◆ setBuf() [2/2]

Data & resip::Data::setBuf ( ShareEnum  se,
const char *  str 
)
inline

Convience function to call setBuf() with a NULL-terminated string.

This is in-lined for case where compiler knows strlen statically.

Definition at line 341 of file Data.hxx.

◆ size()

size_type resip::Data::size ( ) const
inlinenoexcept

Returns the number of bytes in this Data.

Note
This does NOT indicate the capacity of the underlying buffer.

Definition at line 599 of file Data.hxx.

◆ sizeEqualCaseInsensitiveTokenCompare()

bool Data::sizeEqualCaseInsensitiveTokenCompare ( const Data &  rhs) const

Definition at line 2416 of file Data.cxx.

◆ substr()

Data Data::substr ( size_type  first,
size_type  count = Data::npos 
) const

Copies a portion of this Data into a new Data.

Parameters
firstIndex of the first byte to copy
countNumber of bytes to copy

Definition at line 1932 of file Data.cxx.

◆ takeBuf()

Data & Data::takeBuf ( Data &  other)
noexcept

Take the data from {other}.

Any current buffer is released. {this} will have the same storage mode as {other} and steal its buffer. All storage modes of {other} (Share,Borrow,Take) are legal. When done, {other} will be empty (it will ref its internal buffer).

Definition at line 641 of file Data.cxx.

◆ toBitset()

std::bitset< 256 > Data::toBitset ( const resip::Data &  chars)
static

Creates a bitset reflecting the contents of this data (as a set) ie.

"15eo" would have the bits 49, 53, 101, and 111 set to true, and all others set to false

Definition at line 2477 of file Data.cxx.

◆ toString()

std::string Data::toString ( ) const

Convert to a C++ string.

Definition at line 1109 of file Data.cxx.

◆ trunc()

Data Data::trunc ( size_type  trunc) const

Shortens the size of this Data.

If the contents are truncated, this method appends two dot ('.') characters to the end. Presumably, this is used for output purposes.

Definition at line 1564 of file Data.cxx.

◆ truncate()

Data::size_type Data::truncate ( size_type  len)

Shortens the size of this Data.

Does not impact the size of the allocated buffer. This owns() the buffer (undoes Share) so as to write terminating NULL. See truncate2() as alternative.

Deprecated:
dlb says that no one uses this and it should be removed.
Todo:
Remove this at some point.

Definition at line 928 of file Data.cxx.

◆ truncate2()

Data & Data::truncate2 ( size_type  len)

Shortens the size of this Data so length is at most of {len}.

(If already shorter, doesn't increase length). Does not affect buffer allocation, and doesn't impact writing terminating NULL. Thus is safe to use with Share'd or external Take'n buffers.

Definition at line 940 of file Data.cxx.

◆ uppercase()

Data & Data::uppercase ( )

Converts this Data to uppercase.

Note
This is silly unless the contents are ASCII.

Definition at line 1648 of file Data.cxx.

◆ urlDecode()

EncodeStream & Data::urlDecode ( EncodeStream &  s) const

Un-escapes a Data to a stream according to HTTP URL encoding rules.

Definition at line 1351 of file Data.cxx.

◆ urlDecoded()

Data Data::urlDecoded ( ) const

Performs in-place HTTP URL un-escaping of a Data.

Definition at line 1341 of file Data.cxx.

◆ urlEncode()

EncodeStream & Data::urlEncode ( EncodeStream &  s) const

Escapes a Data to a stream according to HTTP URL encoding rules.

Definition at line 1421 of file Data.cxx.

◆ urlEncoded()

Data Data::urlEncoded ( ) const

Performs in-place HTTP URL escaping of a Data.

Definition at line 1331 of file Data.cxx.

◆ xmlCharDataDecode() [1/2]

Data Data::xmlCharDataDecode ( ) const

Performs in-place XML Character Data un-escaping of a Data.

Definition at line 1464 of file Data.cxx.

◆ xmlCharDataDecode() [2/2]

EncodeStream & Data::xmlCharDataDecode ( EncodeStream &  s) const

Un-escapes a Data to a stream according to XML Character Data encoding rules.

Definition at line 1507 of file Data.cxx.

◆ xmlCharDataEncode() [1/2]

Data Data::xmlCharDataEncode ( ) const

Performs in-place XML Character Data escaping of a Data.

Definition at line 1454 of file Data.cxx.

◆ xmlCharDataEncode() [2/2]

EncodeStream & Data::xmlCharDataEncode ( EncodeStream &  s) const

Escapes a Data to a stream according to XML Character Data encoding rules.

Definition at line 1475 of file Data.cxx.

Friends And Related Symbol Documentation

◆ ::TestData

friend class ::TestData
friend

Definition at line 1094 of file Data.hxx.

◆ DataBuffer

friend class DataBuffer
friend

Definition at line 1091 of file Data.hxx.

◆ DataStream

friend class DataStream
friend

Definition at line 1092 of file Data.hxx.

◆ MD5Buffer

friend class MD5Buffer
friend

Definition at line 1095 of file Data.hxx.

◆ oDataStream

friend class oDataStream
friend

Definition at line 1093 of file Data.hxx.

◆ operator< [1/5]

bool operator< ( const char *  lhs,
const Data &  rhs 
)
friend

◆ operator< [2/5]

bool operator< ( const Data &  lhs,
const char *  rhs 
)
friend

◆ operator< [3/5]

bool operator< ( const Data &  lhs,
const Data &  rhs 
)
friend

◆ operator< [4/5]

bool operator< ( const Data &  lhs,
const std::string &  rhs 
)
friend

◆ operator< [5/5]

bool operator< ( const std::string &  lhs,
const Data &  rhs 
)
friend

◆ operator<< [1/2]

EncodeStream & operator<< ( EncodeStream &  strm,
const Data &  d 
)
friend

◆ operator<< [2/2]

std::ostream & operator<< ( std::ostream &  strm,
const Data &  d 
)
friend

Definition at line 1230 of file Data.hxx.

◆ operator== [1/3]

bool operator== ( const Data &  lhs,
const char *  rhs 
)
friend

◆ operator== [2/3]

bool operator== ( const Data &  lhs,
const Data &  rhs 
)
friend

◆ operator== [3/3]

bool operator== ( const Data &  lhs,
const std::string &  rhs 
)
friend

◆ ParseBuffer

friend class ParseBuffer
friend

Definition at line 1090 of file Data.hxx.

Member Data Documentation

◆ Empty

const Data Data::Empty
static

Constant that represents a zero-length data.

Examples
/home/runner/work/resiprocate/resiprocate/rutil/DnsUtil.hxx.

Definition at line 882 of file Data.hxx.

◆ npos

const Data::size_type Data::npos = std::string::npos
static

Represents an impossible position; returned to indicate failure to find.

Definition at line 887 of file Data.hxx.

◆ Preallocate

const Data::PreallocateType Data::Preallocate
static

used only to disambiguate constructors

Definition at line 116 of file Data.hxx.


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