MistServer  2.5.3-Pro-19-gf5e75b1 ( Generic_64)
Public Member Functions | Protected Member Functions | Protected Attributes
DTSC::Packet Class Reference

DTSC::Packets can currently be three types: DTSC_HEAD packets are the "DTSC" header string, followed by 4 bytes len and packed content. More...

#include <dtsc.h>

Public Member Functions

 Packet ()
 Default constructor for packets - sets a null pointer and invalid packet. More...
 
 Packet ()
 
 Packet (const Packet &rhs)
 Copy constructor for packets, copies an existing packet with same noCopy flag as original. More...
 
 Packet (const Packet &rhs)
 
 Packet (const char *data_, unsigned int len, bool noCopy=false)
 Data constructor for packets, either references or copies a packet from raw data. More...
 
 Packet (const char *data_, unsigned int len, bool noCopy=false)
 
 ~Packet ()
 This destructor clears frees the data pointer if the packet was not a reference. More...
 
 ~Packet ()
 
void genericFill (long long packTime, long long packOffset, long long packTrack, const char *packData, long long packDataSize, long long packBytePos, bool isKeyframe)
 
void genericFill (long long packTime, long long packOffset, long long packTrack, const char *packData, long long packDataSize, long long packBytePos, bool isKeyframe)
 Re-initializes this Packet to contain a generic DTSC packet with the given data fields. More...
 
char * getData () const
 Returns a pointer to the payload of this packet. More...
 
char * getData () const
 
int getDataLen () const
 Returns the size of this packet. More...
 
int getDataLen () const
 
void getFlag (const char *identifier, bool &result) const
 
void getFlag (const char *identifier, bool &result) const
 Retrieves a single parameter as a boolean. More...
 
bool getFlag (const char *identifier) const
 Retrieves a single parameter as a boolean. More...
 
bool getFlag (const char *identifier) const
 
void getInt (const char *identifier, int &result) const
 
void getInt (const char *identifier, int &result) const
 Retrieves a single parameter as an integer. More...
 
int getInt (const char *identifier) const
 
int getInt (const char *identifier) const
 Retrieves a single parameter as an integer. More...
 
int getPayloadLen () const
 
int getPayloadLen () const
 Returns the size of the payload of this packet. More...
 
Scan getScan () const
 
Scan getScan () const
 Returns a DTSC::Scan instance to the contents of this packet. More...
 
void getString (const char *identifier, char *&result, unsigned int &len) const
 
void getString (const char *identifier, char *&result, unsigned int &len) const
 Retrieves a single parameter as a string. More...
 
void getString (const char *identifier, std::string &result) const
 
void getString (const char *identifier, std::string &result) const
 Retrieves a single parameter as a string. More...
 
long long unsigned int getTime () const
 Returns the timestamp of the packet. More...
 
long long unsigned int getTime () const
 
long int getTrackId () const
 
long int getTrackId () const
 Returns the track id of the packet. More...
 
packType getVersion () const
 Returns the recognized packet type. More...
 
packType getVersion () const
 
bool hasMember (const char *identifier) const
 Checks whether a parameter exists. More...
 
bool hasMember (const char *identifier) const
 
void null ()
 Resets this packet back to the same state as if it had just been freshly constructed. More...
 
void null ()
 
 operator bool () const
 
 operator bool () const
 Returns true if the packet is deemed valid, false otherwise. More...
 
void operator= (const Packet &rhs)
 
void operator= (const Packet &rhs)
 Copier for packets, copies an existing packet with same noCopy flag as original. More...
 
void reInit (const char *data_, unsigned int len, bool noCopy=false)
 
void reInit (const char *data_, unsigned int len, bool noCopy=false)
 Initializes a packet with new data. More...
 
JSON::Value toJSON () const
 
JSON::Value toJSON () const
 Converts the packet into a JSON value. More...
 

Protected Member Functions

void resize (unsigned int size)
 Internally used resize function for when operating in copy mode and the internal buffer is too small. More...
 
void resize (unsigned int size)
 

Protected Attributes

unsigned int bufferLen
 
char * data
 
unsigned int dataLen
 
bool master
 
packType version
 

Detailed Description

DTSC::Packets can currently be three types: DTSC_HEAD packets are the "DTSC" header string, followed by 4 bytes len and packed content.

DTSC_V1 packets are "DTPD", followed by 4 bytes len and packed content. DTSC_V2 packets are "DTP2", followed by 4 bytes len, 4 bytes trackID, 8 bytes time, and packed content. The len is always without the first 8 bytes counted.

Constructor & Destructor Documentation

DTSC::Packet::Packet ( )

Default constructor for packets - sets a null pointer and invalid packet.

DTSC::Packet::Packet ( const Packet rhs)

Copy constructor for packets, copies an existing packet with same noCopy flag as original.

DTSC::Packet::Packet ( const char *  data_,
unsigned int  len,
bool  noCopy = false 
)

Data constructor for packets, either references or copies a packet from raw data.

DTSC::Packet::~Packet ( )

This destructor clears frees the data pointer if the packet was not a reference.

DTSC::Packet::Packet ( )
DTSC::Packet::Packet ( const Packet rhs)
DTSC::Packet::Packet ( const char *  data_,
unsigned int  len,
bool  noCopy = false 
)
DTSC::Packet::~Packet ( )

Member Function Documentation

void DTSC::Packet::genericFill ( long long  packTime,
long long  packOffset,
long long  packTrack,
const char *  packData,
long long  packDataSize,
long long  packBytePos,
bool  isKeyframe 
)

Re-initializes this Packet to contain a generic DTSC packet with the given data fields.

When given a NULL pointer, the data is reserved and memset to 0

void DTSC::Packet::genericFill ( long long  packTime,
long long  packOffset,
long long  packTrack,
const char *  packData,
long long  packDataSize,
long long  packBytePos,
bool  isKeyframe 
)
char * DTSC::Packet::getData ( ) const

Returns a pointer to the payload of this packet.

Returns
A pointer to the payload of this packet.
char* DTSC::Packet::getData ( ) const
int DTSC::Packet::getDataLen ( ) const

Returns the size of this packet.

Returns
The size of this packet.
int DTSC::Packet::getDataLen ( ) const
void DTSC::Packet::getFlag ( const char *  identifier,
bool &  result 
) const

Retrieves a single parameter as a boolean.

Parameters
identifierThe name of the parameter
resultThe result is stored in this boolean
void DTSC::Packet::getFlag ( const char *  identifier,
bool &  result 
) const
bool DTSC::Packet::getFlag ( const char *  identifier) const
bool DTSC::Packet::getFlag ( const char *  identifier) const

Retrieves a single parameter as a boolean.

Parameters
identifierThe name of the parameter
Returns
The requested parameter as a boolean
void DTSC::Packet::getInt ( const char *  identifier,
int &  result 
) const

Retrieves a single parameter as an integer.

Parameters
identifierThe name of the parameter
resultThe result is stored in this integer
void DTSC::Packet::getInt ( const char *  identifier,
int &  result 
) const
int DTSC::Packet::getInt ( const char *  identifier) const

Retrieves a single parameter as an integer.

Parameters
identifierThe name of the parameter
Returns
The requested parameter as an integer
int DTSC::Packet::getInt ( const char *  identifier) const
int DTSC::Packet::getPayloadLen ( ) const

Returns the size of the payload of this packet.

Returns
The size of the payload of this packet.
int DTSC::Packet::getPayloadLen ( ) const
Scan DTSC::Packet::getScan ( ) const

Returns a DTSC::Scan instance to the contents of this packet.

May return an invalid instance if this packet is invalid.

Scan DTSC::Packet::getScan ( ) const
void DTSC::Packet::getString ( const char *  identifier,
char *&  result,
unsigned int &  len 
) const

Retrieves a single parameter as a string.

Parameters
identifierThe name of the parameter
resultA location on which the string will be returned
lenAn integer in which the length of the string will be returned
void DTSC::Packet::getString ( const char *  identifier,
char *&  result,
unsigned int &  len 
) const
void DTSC::Packet::getString ( const char *  identifier,
std::string &  result 
) const

Retrieves a single parameter as a string.

Parameters
identifierThe name of the parameter
resultThe string in which to store the result
void DTSC::Packet::getString ( const char *  identifier,
std::string &  result 
) const
long long unsigned int DTSC::Packet::getTime ( ) const

Returns the timestamp of the packet.

Returns
The timestamp of this packet.
long long unsigned int DTSC::Packet::getTime ( ) const
long int DTSC::Packet::getTrackId ( ) const
long int DTSC::Packet::getTrackId ( ) const

Returns the track id of the packet.

Returns
The track id of this packet.
packType DTSC::Packet::getVersion ( ) const

Returns the recognized packet type.

This type is set by reInit and all constructors, and then just referenced from there on.

packType DTSC::Packet::getVersion ( ) const
bool DTSC::Packet::hasMember ( const char *  identifier) const
bool DTSC::Packet::hasMember ( const char *  identifier) const

Checks whether a parameter exists.

Parameters
identifierThe name of the parameter
Returns
Whether the parameter exists or not
void DTSC::Packet::null ( )

Resets this packet back to the same state as if it had just been freshly constructed.

If needed, this frees the data pointer.

void DTSC::Packet::null ( )
DTSC::Packet::operator bool ( ) const
DTSC::Packet::operator bool ( ) const

Returns true if the packet is deemed valid, false otherwise.

Valid packets have a length of at least 8, known header type, and length equal to the length set in the header.

void DTSC::Packet::operator= ( const Packet rhs)
void DTSC::Packet::operator= ( const Packet rhs)

Copier for packets, copies an existing packet with same noCopy flag as original.

If going from copy to noCopy, this will free the data pointer first.

void DTSC::Packet::reInit ( const char *  data_,
unsigned int  len,
bool  noCopy = false 
)
void DTSC::Packet::reInit ( const char *  data_,
unsigned int  len,
bool  noCopy = false 
)

Initializes a packet with new data.

Parameters
data_The new data for the packet
lenThe length of the data pointed to by data_
noCopyDetermines whether to make a copy or not
void DTSC::Packet::resize ( unsigned int  size)
protected
void DTSC::Packet::resize ( unsigned int  len)
protected

Internally used resize function for when operating in copy mode and the internal buffer is too small.

It will only resize up, never down.

Parameters
lenThe length th scale the buffer up to if necessary
JSON::Value DTSC::Packet::toJSON ( ) const
JSON::Value DTSC::Packet::toJSON ( ) const

Converts the packet into a JSON value.

Returns
A JSON::Value representation of this packet.

Field Documentation

unsigned int DTSC::Packet::bufferLen
protected
char * DTSC::Packet::data
protected
unsigned int DTSC::Packet::dataLen
protected
bool DTSC::Packet::master
protected
packType DTSC::Packet::version
protected

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