Very Simple Cross-Platform Library
Public Member Functions | List of all members
hu::varadiistvan::scpl::io::DataStream Class Reference

#include <DataStream.h>

Inheritance diagram for hu::varadiistvan::scpl::io::DataStream:
hu::varadiistvan::scpl::io::BlockingStream hu::varadiistvan::scpl::io::Failable

Public Member Functions

 DataStream (BufferedStream &stream)
 
template<typename T >
readT (T defaultValue=0)
 
int8_t readS8 ()
 
uint8_t readU8 ()
 
int16_t readS16 ()
 
uint16_t readU16 ()
 
int32_t readS32 ()
 
uint32_t readU32 ()
 
int64_t readS64 ()
 
uint64_t readU64 ()
 
float readFloat ()
 
double readDouble ()
 
long double readLongDouble ()
 
size_t readLength ()
 
std::string readString ()
 
size_t readString (char *dest, size_t capacity)
 
bool writeS8 (int8_t x)
 
bool writeU8 (uint8_t x)
 
bool writeS16 (int16_t x)
 
bool writeU16 (uint16_t x)
 
bool writeS32 (int32_t x)
 
bool writeU32 (uint32_t x)
 
bool writeS64 (int64_t x)
 
bool writeU64 (uint64_t x)
 
bool writeFloat (float x)
 
bool writeDouble (double x)
 
bool writeLongDouble (long double x)
 
bool writeLength (size_t length)
 
bool writeString (const char *s, size_t length)
 
bool writeString (const std::string &s)
 
bool writeString (const char *s)
 
- Public Member Functions inherited from hu::varadiistvan::scpl::io::BlockingStream
 BlockingStream (BufferedStream &stream)
 
 operator bool () const
 
void interrupt ()
 
bool isInterrupted ()
 
bool read (void *dest, size_t length)
 
bool skip (size_t length)
 
bool write (const void *src, size_t length)
 
bool flush ()
 
- Public Member Functions inherited from hu::varadiistvan::scpl::io::Failable
 Failable ()
 
bool failed () const
 
errorCode_t getErrorCode () const
 
void repair ()
 

Additional Inherited Members

- Protected Member Functions inherited from hu::varadiistvan::scpl::io::Failable
void setErrorCode (errorCode_t ec)
 

Detailed Description

A blocking stream with extra functions to read and write values of basic data types. The values are read and written in host byte-order, so this stream does not work properly between machines of different endianness.

The reading functions return the value read and you can check of error or interruption only by calling the appropriate functions. The purpose of this behaviour is that the data could be read item-by-item without having to check for the stream's health all the time. Such checks are needed only, if some decision is made, based on the data. In case of an error, the read functions return some well-define default value, typically 0.

The writing functions return a boolean value indicating success or failure, but writing can be handled the same way as reading from the point of view of error checking.

Definition at line 65 of file DataStream.h.

Constructor & Destructor Documentation

◆ DataStream()

hu::varadiistvan::scpl::io::DataStream::DataStream ( BufferedStream stream)
inline

Construct the stream.

Definition at line 243 of file DataStream.h.

Member Function Documentation

◆ readDouble()

double hu::varadiistvan::scpl::io::DataStream::readDouble ( )
inline

Read a double value.

Definition at line 322 of file DataStream.h.

◆ readFloat()

float hu::varadiistvan::scpl::io::DataStream::readFloat ( )
inline

Read a float value.

Definition at line 315 of file DataStream.h.

◆ readLength()

size_t DataStream::readLength ( )

Read a length value. This is a of at most 32 bits, represented by a variable number of bytes for space efficiency.

See also
writeLength()

Definition at line 42 of file DataStream.cc.

◆ readLongDouble()

long double hu::varadiistvan::scpl::io::DataStream::readLongDouble ( )
inline

Read a long double value.

Definition at line 329 of file DataStream.h.

◆ readS16()

int16_t hu::varadiistvan::scpl::io::DataStream::readS16 ( )
inline

Read a signed, 16-bit value

Definition at line 273 of file DataStream.h.

◆ readS32()

int32_t hu::varadiistvan::scpl::io::DataStream::readS32 ( )
inline

Read a signed, 32-bit value

Definition at line 287 of file DataStream.h.

◆ readS64()

int64_t hu::varadiistvan::scpl::io::DataStream::readS64 ( )
inline

Read a signed, 64-bit value

Definition at line 301 of file DataStream.h.

◆ readS8()

int8_t hu::varadiistvan::scpl::io::DataStream::readS8 ( )
inline

Read a signed, 8-bit value

Definition at line 259 of file DataStream.h.

◆ readString() [1/2]

string DataStream::readString ( )

Read a string.

Definition at line 59 of file DataStream.cc.

◆ readString() [2/2]

size_t DataStream::readString ( char *  dest,
size_t  capacity 
)

Read a string into the given buffer. If the string is too large for the buffer, its end will be discarded. A trailing 0 is added in cases!

Returns
the actual length of the string.

Definition at line 77 of file DataStream.cc.

◆ readT()

template<typename T >
T hu::varadiistvan::scpl::io::DataStream::readT ( defaultValue = 0)

Template for simple, type-specific reading.

Definition at line 250 of file DataStream.h.

◆ readU16()

uint16_t hu::varadiistvan::scpl::io::DataStream::readU16 ( )
inline

Read an unsigned, 16-bit value

Definition at line 280 of file DataStream.h.

◆ readU32()

uint32_t hu::varadiistvan::scpl::io::DataStream::readU32 ( )
inline

Read an unsigned, 32-bit value

Definition at line 294 of file DataStream.h.

◆ readU64()

uint64_t hu::varadiistvan::scpl::io::DataStream::readU64 ( )
inline

Read an unsigned, 64-bit value

Definition at line 308 of file DataStream.h.

◆ readU8()

uint8_t hu::varadiistvan::scpl::io::DataStream::readU8 ( )
inline

Read an unsigned, 8-bit value

Definition at line 266 of file DataStream.h.

◆ writeDouble()

bool hu::varadiistvan::scpl::io::DataStream::writeDouble ( double  x)
inline

Write a double value.

Definition at line 399 of file DataStream.h.

◆ writeFloat()

bool hu::varadiistvan::scpl::io::DataStream::writeFloat ( float  x)
inline

Write a float value.

Definition at line 392 of file DataStream.h.

◆ writeLength()

bool DataStream::writeLength ( size_t  length)

Write a length value. This a 32-bit value written as a sequence of bytes of variable length. A bytes's lower 7 bits contain parts of the value. The MSB indicates if another byte is left.

Definition at line 103 of file DataStream.cc.

◆ writeLongDouble()

bool hu::varadiistvan::scpl::io::DataStream::writeLongDouble ( long double  x)
inline

Write a long double value.

Definition at line 406 of file DataStream.h.

◆ writeS16()

bool hu::varadiistvan::scpl::io::DataStream::writeS16 ( int16_t  x)
inline

Write a signed, 16-bit value

Definition at line 350 of file DataStream.h.

◆ writeS32()

bool hu::varadiistvan::scpl::io::DataStream::writeS32 ( int32_t  x)
inline

Write a signed, 32-bit value

Definition at line 364 of file DataStream.h.

◆ writeS64()

bool hu::varadiistvan::scpl::io::DataStream::writeS64 ( int64_t  x)
inline

Write a signed, 64-bit value

Definition at line 378 of file DataStream.h.

◆ writeS8()

bool hu::varadiistvan::scpl::io::DataStream::writeS8 ( int8_t  x)
inline

Write a signed, 8-bit value

Definition at line 336 of file DataStream.h.

◆ writeString() [1/3]

bool hu::varadiistvan::scpl::io::DataStream::writeString ( const char *  s)
inline

Write a string. First the string's length is written as a length (see writeLength()), then the characters of the string without the trailing 0.

Definition at line 428 of file DataStream.h.

◆ writeString() [2/3]

bool hu::varadiistvan::scpl::io::DataStream::writeString ( const char *  s,
size_t  length 
)
inline

Write a string. First the string's length is written as a length (see writeLength()), then the characters of the string without the trailing 0.

Definition at line 413 of file DataStream.h.

◆ writeString() [3/3]

bool hu::varadiistvan::scpl::io::DataStream::writeString ( const std::string &  s)
inline

Write a string. First the string's length is written as a length (see writeLength()), then the characters of the string without the trailing 0.

Definition at line 421 of file DataStream.h.

◆ writeU16()

bool hu::varadiistvan::scpl::io::DataStream::writeU16 ( uint16_t  x)
inline

Write an unsigned, 16-bit value

Definition at line 357 of file DataStream.h.

◆ writeU32()

bool hu::varadiistvan::scpl::io::DataStream::writeU32 ( uint32_t  x)
inline

Write an unsigned, 32-bit value

Definition at line 371 of file DataStream.h.

◆ writeU64()

bool hu::varadiistvan::scpl::io::DataStream::writeU64 ( uint64_t  x)
inline

Write an unsigned, 64-bit value

Definition at line 385 of file DataStream.h.

◆ writeU8()

bool hu::varadiistvan::scpl::io::DataStream::writeU8 ( uint8_t  x)
inline

Write an unsigned, 8-bit value

Definition at line 343 of file DataStream.h.


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