Very Simple Cross-Platform Library
|
#include <DataStream.h>
Public Member Functions | |
DataStream (BufferedStream &stream) | |
template<typename T > | |
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) |
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.
|
inline |
Construct the stream.
Definition at line 243 of file DataStream.h.
|
inline |
Read a double value.
Definition at line 322 of file DataStream.h.
|
inline |
Read a float value.
Definition at line 315 of file DataStream.h.
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.
Definition at line 42 of file DataStream.cc.
|
inline |
Read a long double value.
Definition at line 329 of file DataStream.h.
|
inline |
Read a signed, 16-bit value
Definition at line 273 of file DataStream.h.
|
inline |
Read a signed, 32-bit value
Definition at line 287 of file DataStream.h.
|
inline |
Read a signed, 64-bit value
Definition at line 301 of file DataStream.h.
|
inline |
Read a signed, 8-bit value
Definition at line 259 of file DataStream.h.
string DataStream::readString | ( | ) |
Read a string.
Definition at line 59 of file DataStream.cc.
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!
Definition at line 77 of file DataStream.cc.
T hu::varadiistvan::scpl::io::DataStream::readT | ( | T | defaultValue = 0 | ) |
Template for simple, type-specific reading.
Definition at line 250 of file DataStream.h.
|
inline |
Read an unsigned, 16-bit value
Definition at line 280 of file DataStream.h.
|
inline |
Read an unsigned, 32-bit value
Definition at line 294 of file DataStream.h.
|
inline |
Read an unsigned, 64-bit value
Definition at line 308 of file DataStream.h.
|
inline |
Read an unsigned, 8-bit value
Definition at line 266 of file DataStream.h.
|
inline |
Write a double value.
Definition at line 399 of file DataStream.h.
|
inline |
Write a float value.
Definition at line 392 of file DataStream.h.
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.
|
inline |
Write a long double value.
Definition at line 406 of file DataStream.h.
|
inline |
Write a signed, 16-bit value
Definition at line 350 of file DataStream.h.
|
inline |
Write a signed, 32-bit value
Definition at line 364 of file DataStream.h.
|
inline |
Write a signed, 64-bit value
Definition at line 378 of file DataStream.h.
|
inline |
Write a signed, 8-bit value
Definition at line 336 of file DataStream.h.
|
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.
|
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.
|
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.
|
inline |
Write an unsigned, 16-bit value
Definition at line 357 of file DataStream.h.
|
inline |
Write an unsigned, 32-bit value
Definition at line 371 of file DataStream.h.
|
inline |
Write an unsigned, 64-bit value
Definition at line 385 of file DataStream.h.
|
inline |
Write an unsigned, 8-bit value
Definition at line 343 of file DataStream.h.