KDIS  2-8-x
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
KDataStream Class Reference

#include <KDataStream.h>

Public Member Functions

void Clear ()
 Description: Clears contents. More...
 
void CopyFromBuffer (const KOCTET *SerialData, KUINT16 DataSize, Endian NetworkEndian=Big_Endian)
 Description: Copy data from a buffer/array into the data stream. More...
 
KUINT16 CopyIntoBuffer (KOCTET *Buffer, KUINT16 BufferSize, KUINT16 WritePos=0) const throw ( KException )
 
KString GetAsString () const
 Description: Returns string representation of the stream, values are in hex. More...
 
const std::vector< KUOCTET > & GetBuffer () const
 
const KOCTETGetBufferPtr () const
 
KUINT16 GetBufferSize () const
 Description: Returns current buffer size in Octets/Bytes. More...
 
KUINT16 GetCurrentWritePosition () const
 
Endian GetMachineEndian () const
 Description: Returns the machine endian. Calculated automatically. More...
 
Endian GetNetWorkEndian () const
 
 KDataStream (Endian NetworkEndian=Big_Endian)
 
 KDataStream (KOCTET *SerialData, KUINT16 DataSize, Endian NetworkEndian=Big_Endian)
 
KBOOL operator!= (const KDataStream &Value) const
 
template<class Type >
KDataStreamoperator<< (Type T)
 
KDataStreamoperator<< (KDataStream val)
 
KBOOL operator== (const KDataStream &Value) const
 
template<class Type >
KDataStreamoperator>> (Type &T)
 
template<class Type >
void Read (Type &T)
 Description: Read data from stream. More...
 
void Read (KUOCTET &V)
 
void Read (KOCTET &V)
 
void ReadFromString (const KString &S)
 
void ResetWritePosition ()
 Description: Moves the write position back to the start of the buffer. More...
 
void SetCurrentWritePosition (KUINT16 WP)
 
template<class Type >
void Write (Type T)
 Description: Write data into stream. More...
 
void Write (KUOCTET V)
 
void Write (KOCTET V)
 
 ~KDataStream ()
 

Constructor & Destructor Documentation

KDataStream ( Endian  NetworkEndian = Big_Endian)
KDataStream ( KOCTET SerialData,
KUINT16  DataSize,
Endian  NetworkEndian = Big_Endian 
)

Member Function Documentation

Endian GetMachineEndian ( ) const

Description: Returns the machine endian. Calculated automatically.

Endian GetNetWorkEndian ( ) const

Description: Returns the network endian, set by user in constructor, Big_Endian by default.

KUINT16 GetBufferSize ( ) const

Description: Returns current buffer size in Octets/Bytes.

KUINT16 CopyIntoBuffer ( KOCTET Buffer,
KUINT16  BufferSize,
KUINT16  WritePos = 0 
) const
throw (KException
)

Description: Copy the stream into an Octet buffer, Returns total bytes copied into buffer. Throws exception if the buffer is too small.

void CopyFromBuffer ( const KOCTET SerialData,
KUINT16  DataSize,
Endian  NetworkEndian = Big_Endian 
)

Description: Copy data from a buffer/array into the data stream.

const KOCTET* GetBufferPtr ( ) const

Description: Returns a pointer to the buffer. This is a more efficient way of sending data than using CopyIntoBuffer.

const std::vector<KUOCTET>& GetBuffer ( ) const

Description: Returns a constant reference to the internal buffer. Useful if you need lower-level access to the data.

void ResetWritePosition ( )

Description: Moves the write position back to the start of the buffer.

void SetCurrentWritePosition ( KUINT16  WP)

Description: The write position is the current position in the buffer that we are reading data from. Using these 2 functions it is possible to "peak" at data and then restore the buffers write position. For example if we wanted to read the next 4 bytes to determine what the next data type is we could peak and then reset the write position back by 4 so that the data can be re-read by the data types decode function.

KUINT16 GetCurrentWritePosition ( ) const
void Clear ( )

Description: Clears contents.

KString GetAsString ( ) const

Description: Returns string representation of the stream, values are in hex.

void ReadFromString ( const KString S)

Description: Read a string of hex octets and convert into a data stream. This function works in conjunction with GetAsString, each PDU could be saved to a file and then read back in using this function. Good for debugging or logging data.

void Write ( Type  T)

Description: Write data into stream.

void Write ( KUOCTET  V)
void Write ( KOCTET  V)
void Read ( Type &  T)

Description: Read data from stream.

void Read ( KUOCTET V)
void Read ( KOCTET V)
KDataStream & operator<< ( Type  T)
KDataStream& operator<< ( KDataStream  val)
KDataStream & operator>> ( Type &  T)
KBOOL operator== ( const KDataStream Value) const
KBOOL operator!= ( const KDataStream Value) const

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