The PByteStream class is a generic byte stream (can be a memory stream or a file stream).
This class can be inherited.
Example: serialize/deserialise some data into a PByteArray
{
}
{
}
...
PMemoryStream ms;
Serialise(ms, 4,
"test",
PDateTime(
"2014-04-05T23:58:59")).OrDie();
int i = 0;
Deserialise(ms, i, s, t).
OrDie();
Definition at line 69 of file PByteStream.h.
#include <PByteStream.h>
◆ PByteStream() [1/2]
PByteStream::PByteStream |
( |
| ) |
|
Construct an empty byte stream.
◆ PByteStream() [2/2]
Constructs a shared copy of other.
◆ ~PByteStream()
virtual PByteStream::~PByteStream |
( |
| ) |
|
|
virtual |
Closes the stream if opened, then destroys this object.
◆ CanRead()
bool PByteStream::CanRead |
( |
| ) |
const |
Returns true if this stream supports reading, false otherwise.
◆ CanSeek()
bool PByteStream::CanSeek |
( |
| ) |
const |
Returns true if this stream supports seeking, false otherwise.
◆ CanWrite()
bool PByteStream::CanWrite |
( |
| ) |
const |
Returns true if this stream supports writing, false otherwise.
◆ Close()
Closes this stream and releases any resources associated with.
Close() is automatically called when is stream is destroyed.
◆ Flush()
Clears all buffers for this stream and causes any buffered data to be written to the underlying device.
◆ GetPosition()
papillon::int64 PByteStream::GetPosition |
( |
| ) |
const |
Returns the current position in this stream (if seeking is supported, 0 otherwise).
◆ HasSize()
bool PByteStream::HasSize |
( |
| ) |
const |
Returns true if this stream has a predefined length, false otherwise.
◆ IsOpened()
PResult PByteStream::IsOpened |
( |
| ) |
const |
Returns PResult::C_OK if the stream is ready opened, another result otherwise.
◆ operator<<()
Serialises the specified object to this stream; throw an exception if failure.
This method works with any Papillon objects (PString, PDateTime, PProperties, etc.) and also with primitive data type (int8, int16, int32, int64, uint8, uint16, uint32, uint64, float, double).
Warning: this method logs error if any.
Definition at line 258 of file PByteStream.h.
◆ operator=()
Performs a shared copy of other to this object.
◆ operator==()
bool PByteStream::operator== |
( |
const PByteStream & |
other | ) |
const |
Returns true if this object is the same instance than other, false otherwise.
◆ operator>>()
Deserialises the specified object from this stream.
This method works with any Papillon objects (PString, PDateTime, PProperties, etc.) and also with primitive data type (int8, int16, int32, int64, uint8, uint16, uint32, uint64, float, double).
Warning: this method logs error if any.
Definition at line 203 of file PByteStream.h.
◆ ReadByte()
PResult PByteStream::ReadByte |
( |
papillon::int8 & |
value | ) |
|
◆ ReadBytes() [1/2]
PResult PByteStream::ReadBytes |
( |
void * |
destinationBuffer, |
|
|
papillon::uint64 |
n |
|
) |
| |
UNSAFE: Reads up to n bytes from this stream and puts data into the specified buffer.
Returns PResult::C_OK if success, another result otherwise (returns PResult::ErrorEndOfSteam() (error code is PResult::E_ERROR_END_OF_STREAM) if end of the stream has been reached)
◆ ReadBytes() [2/2]
PResult PByteStream::ReadBytes |
( |
PByteArray & |
destinationArray, |
|
|
papillon::uint64 |
position, |
|
|
papillon::uint64 |
n |
|
) |
| |
Reads up to n bytes from this stream and puts data into the specified array starting at the specified position.
Returns PResult::C_OK if success, another result otherwise (returns PResult::ErrorEndOfSteam() (error code is PResult::E_ERROR_END_OF_STREAM) if end of the stream has been reached)
◆ ReadClassIdAndCheck()
◆ ReadObject() [1/12]
template<typename T >
PResult PByteStream::ReadObject |
( |
T & |
t | ) |
|
|
inline |
Deserialises the specified object from this stream.
This method works with any Papillon objects (PString, PDateTime, PProperties, etc.) and also with primitive data type (int8, int16, int32, int64, uint8, uint16, uint32, uint64, float, double).
Returns PResult::C_OK if success, another result otherwise.
Definition at line 189 of file PByteStream.h.
◆ ReadObject() [2/12]
template<>
PResult PByteStream::ReadObject |
( |
bool & |
value | ) |
|
|
inline |
◆ ReadObject() [3/12]
template<>
PResult PByteStream::ReadObject |
( |
papillon::int8 & |
value | ) |
|
|
inline |
◆ ReadObject() [4/12]
template<>
PResult PByteStream::ReadObject |
( |
papillon::int16 & |
value | ) |
|
|
inline |
◆ ReadObject() [5/12]
template<>
PResult PByteStream::ReadObject |
( |
papillon::int32 & |
value | ) |
|
|
inline |
◆ ReadObject() [6/12]
template<>
PResult PByteStream::ReadObject |
( |
papillon::int64 & |
value | ) |
|
|
inline |
◆ ReadObject() [7/12]
template<>
PResult PByteStream::ReadObject |
( |
papillon::uint8 & |
value | ) |
|
|
inline |
◆ ReadObject() [8/12]
template<>
PResult PByteStream::ReadObject |
( |
papillon::uint16 & |
value | ) |
|
|
inline |
◆ ReadObject() [9/12]
template<>
PResult PByteStream::ReadObject |
( |
papillon::uint32 & |
value | ) |
|
|
inline |
◆ ReadObject() [10/12]
template<>
PResult PByteStream::ReadObject |
( |
papillon::uint64 & |
value | ) |
|
|
inline |
◆ ReadObject() [11/12]
template<>
PResult PByteStream::ReadObject |
( |
float & |
value | ) |
|
|
inline |
◆ ReadObject() [12/12]
template<>
PResult PByteStream::ReadObject |
( |
double & |
value | ) |
|
|
inline |
◆ Resize()
PResult PByteStream::Resize |
( |
papillon::uint64 |
newSize | ) |
|
Sets the size of this stream, is possible.
Returns PResult::C_OK if success, another result otherwise.
◆ Rewind()
Resets the position within the current stream (sets position to the first byte), if seeking is supported.
◆ Seek()
PResult PByteStream::Seek |
( |
papillon::uint64 |
n | ) |
|
Sets the position within the current stream if seeking is supported.
◆ Size()
papillon::int64 PByteStream::Size |
( |
| ) |
const |
Returns the size of this stream in bytes, if available.
◆ WriteByte()
PResult PByteStream::WriteByte |
( |
papillon::int8 |
value | ) |
|
Writes a byte to this stream.
Returns PResult::C_OK if success, another result otherwise.
◆ WriteBytes() [1/2]
PResult PByteStream::WriteBytes |
( |
const void * |
sourceBuffer, |
|
|
papillon::uint64 |
n |
|
) |
| |
Writes n bytes from the specified buffer to this stream.
Returns PResult::C_OK if success, another result otherwise.
◆ WriteBytes() [2/2]
PResult PByteStream::WriteBytes |
( |
const PByteArray & |
sourceArray, |
|
|
papillon::uint64 |
sourcePosition, |
|
|
papillon::uint64 |
numBytes = 0 |
|
) |
| |
Writes the bytes from the specified array to this stream.
If numBytes is 0, then writes all bytes from the specified array's position to the end of the array. Returns PResult::C_OK if success, another result otherwise.
◆ WriteObject() [1/12]
template<typename T >
PResult PByteStream::WriteObject |
( |
const T & |
t | ) |
|
|
inline |
Serialises the specified object to this stream.
This method works with any Papillon objects (PString, PDateTime, PProperties, etc.) and also with primitive data type (int8, int16, int32, int64, uint8, uint16, uint32, uint64, float, double).
Returns PResult::C_OK if success, another result otherwise.
Definition at line 244 of file PByteStream.h.
◆ WriteObject() [2/12]
template<>
PResult PByteStream::WriteObject |
( |
const bool & |
value | ) |
|
|
inline |
◆ WriteObject() [3/12]
template<>
PResult PByteStream::WriteObject |
( |
const papillon::int8 & |
value | ) |
|
|
inline |
◆ WriteObject() [4/12]
template<>
PResult PByteStream::WriteObject |
( |
const papillon::int16 & |
value | ) |
|
|
inline |
◆ WriteObject() [5/12]
template<>
PResult PByteStream::WriteObject |
( |
const papillon::int32 & |
value | ) |
|
|
inline |
◆ WriteObject() [6/12]
template<>
PResult PByteStream::WriteObject |
( |
const papillon::int64 & |
value | ) |
|
|
inline |
◆ WriteObject() [7/12]
template<>
PResult PByteStream::WriteObject |
( |
const papillon::uint8 & |
value | ) |
|
|
inline |
◆ WriteObject() [8/12]
template<>
PResult PByteStream::WriteObject |
( |
const papillon::uint16 & |
value | ) |
|
|
inline |
◆ WriteObject() [9/12]
template<>
PResult PByteStream::WriteObject |
( |
const papillon::uint32 & |
value | ) |
|
|
inline |
◆ WriteObject() [10/12]
template<>
PResult PByteStream::WriteObject |
( |
const papillon::uint64 & |
value | ) |
|
|
inline |
◆ WriteObject() [11/12]
template<>
PResult PByteStream::WriteObject |
( |
const float & |
value | ) |
|
|
inline |
◆ WriteObject() [12/12]
template<>
PResult PByteStream::WriteObject |
( |
const double & |
value | ) |
|
|
inline |