Main MRPT website > C++ reference for MRPT 1.9.9
List of all members | Public Member Functions | Protected Member Functions | Private Attributes
mrpt::serialization::CArchiveStreamBase< std::vector< uint8_t > > Class Reference

Detailed Description

Specialization for std::vector, suitable for read/write, using the vector<uint8_t> as the underlaying stream container.

Writing always happen at the end of the vector. Reading starts at the beggining upon construction of this wrapper class (via archiveFrom()).

Definition at line 26 of file archiveFrom_std_vector.h.

#include <mrpt/serialization/archiveFrom_std_vector.h>

Inheritance diagram for mrpt::serialization::CArchiveStreamBase< std::vector< uint8_t > >:
Inheritance graph

Public Member Functions

 CArchiveStreamBase (std::vector< uint8_t > &v)
 

Protected Member Functions

size_t write (const void *d, size_t n) override
 Writes a block of bytes. More...
 
size_t read (void *d, size_t n) override
 Reads a block of bytes. More...
 
void internal_ReadObject (CSerializable *newObj, const std::string &className, bool isOldFormat, int8_t version)
 Read the object. More...
 
void internal_ReadObjectHeader (std::string &className, bool &isOldFormat, int8_t &version)
 Read the object Header. More...
 

Private Attributes

std::vector< uint8_t > & m_v
 
int m_pos_read {0}
 

Serialization API for generic "archives" I/O streams

size_t ReadBuffer (void *Buffer, size_t Count)
 Reads a block of bytes from the stream into Buffer. More...
 
template<typename T >
size_t ReadBufferFixEndianness (T *ptr, size_t ElementCount)
 Reads a sequence of elemental datatypes, taking care of reordering their bytes from the MRPT stream standard (little endianness) to the format of the running architecture. More...
 
void WriteBuffer (const void *Buffer, size_t Count)
 Writes a block of bytes to the stream from Buffer. More...
 
template<typename T >
void WriteBufferFixEndianness (const T *ptr, size_t ElementCount)
 Writes a sequence of elemental datatypes, taking care of reordering their bytes from the running architecture to MRPT stream standard (little endianness). More...
 
template<typename STORED_TYPE , typename CAST_TO_TYPE >
void ReadAsAndCastTo (CAST_TO_TYPE &read_here)
 Read a value from a stream stored in a type different of the target variable, making the conversion via static_cast. More...
 
template<typename STORED_TYPE >
STORED_TYPE ReadAs ()
 De-serialize a variable and returns it by value. More...
 
template<typename TYPE_TO_STORE , typename TYPE_FROM_ACTUAL >
void WriteAs (const TYPE_FROM_ACTUAL &value)
 
void WriteObject (const CSerializable *o)
 Writes an object to the stream. More...
 
void WriteObject (const CSerializable &o)
 
CSerializable::Ptr ReadObject ()
 Reads an object from stream, its class determined at runtime, and returns a smart pointer to the object. More...
 
template<typename T >
T::Ptr ReadObject ()
 Reads an object from stream, its class determined at runtime, and returns a smart pointer to the object. More...
 
void ReadObject (CSerializable *existingObj)
 Reads an object from stream, where its class must be the same as the supplied object, where the loaded object will be stored in. More...
 
template<typename T , typename T2 , typename ... REST>
const mrpt::rtti::TRuntimeClassIdfindRegisteredClassInList (std::string_view strClassName)
 
template<typename T >
const mrpt::rtti::TRuntimeClassIdfindRegisteredClassInList (std::string_view strClassName)
 
template<typename... T>
std::variant< T... > ReadVariant ()
 Reads a variant from stream, its class determined at runtime, and returns a variant to the object. More...
 
template<typename T >
void WriteVariant (T t)
 Writes a Variant to the stream. More...
 
template<typename T >
ReadPOD ()
 Reads a simple POD type and returns by value. More...
 
void sendMessage (const CMessage &msg)
 Send a message to the device. More...
 
bool receiveMessage (CMessage &msg)
 Tries to receive a message from the device. More...
 
CArchiveoperator<< (const CSerializable &obj)
 Write a CSerializable object to a stream in the binary MRPT format. More...
 
CArchiveoperator<< (const CSerializable::Ptr &pObj)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. More...
 
CArchiveoperator>> (CSerializable &obj)
 Reads a CSerializable object from the stream. More...
 
CArchiveoperator>> (CSerializable::Ptr &pObj)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. More...
 
template<typename RET >
RET ReadVariant_helper (CSerializable::Ptr &ptr)
 
template<typename RET , typename T , typename... R>
RET ReadVariant_helper (CSerializable::Ptr &ptr, std::enable_if_t< mrpt::is_shared_ptr< T >::value > *=nullptr)
 
template<typename RET , typename T , typename... R>
RET ReadVariant_helper (CSerializable::Ptr &ptr, std::enable_if_t<!mrpt::is_shared_ptr< T >::value > *=nullptr)
 

Constructor & Destructor Documentation

◆ CArchiveStreamBase()

mrpt::serialization::CArchiveStreamBase< std::vector< uint8_t > >::CArchiveStreamBase ( std::vector< uint8_t > &  v)
inline

Definition at line 32 of file archiveFrom_std_vector.h.

Member Function Documentation

◆ findRegisteredClassInList() [1/2]

template<typename T , typename T2 , typename ... REST>
const mrpt::rtti::TRuntimeClassId* mrpt::serialization::CArchive::findRegisteredClassInList ( std::string_view  strClassName)
inlineinherited

◆ findRegisteredClassInList() [2/2]

template<typename T >
const mrpt::rtti::TRuntimeClassId* mrpt::serialization::CArchive::findRegisteredClassInList ( std::string_view  strClassName)
inlineinherited

Definition at line 243 of file CArchive.h.

References mrpt::rtti::TRuntimeClassId::className.

◆ internal_ReadObject()

void CArchive::internal_ReadObject ( CSerializable newObj,
const std::string className,
bool  isOldFormat,
int8_t  version 
)
protectedinherited

◆ internal_ReadObjectHeader()

void CArchive::internal_ReadObjectHeader ( std::string className,
bool &  isOldFormat,
int8_t version 
)
protectedinherited

◆ operator<<() [1/2]

CArchive & CArchive::operator<< ( const CSerializable obj)
inherited

Write a CSerializable object to a stream in the binary MRPT format.

Write an object to a stream in the binary MRPT format.

Definition at line 187 of file CArchive.cpp.

References mrpt::serialization::CArchive::WriteObject().

◆ operator<<() [2/2]

CArchive & CArchive::operator<< ( const CSerializable::Ptr pObj)
inherited

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 180 of file CArchive.cpp.

References mrpt::serialization::CArchive::WriteObject().

◆ operator>>() [1/2]

CArchive & CArchive::operator>> ( CSerializable obj)
inherited

Reads a CSerializable object from the stream.

Definition at line 199 of file CArchive.cpp.

References mrpt::serialization::CArchive::ReadObject().

◆ operator>>() [2/2]

CArchive & CArchive::operator>> ( CSerializable::Ptr pObj)
inherited

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 193 of file CArchive.cpp.

References mrpt::serialization::CArchive::ReadObject().

◆ read()

size_t mrpt::serialization::CArchiveStreamBase< std::vector< uint8_t > >::read ( void buf,
size_t  len 
)
inlineoverrideprotectedvirtual

Reads a block of bytes.

Exceptions
std::exceptionOn any error, or if ZERO bytes are read.
Returns
Number of bytes actually read if >0.

Implements mrpt::serialization::CArchive.

Definition at line 41 of file archiveFrom_std_vector.h.

References mrpt::system::os::memcpy().

◆ ReadAs()

template<typename STORED_TYPE >
STORED_TYPE mrpt::serialization::CArchive::ReadAs ( )
inlineinherited

De-serialize a variable and returns it by value.

Definition at line 145 of file CArchive.h.

◆ ReadAsAndCastTo()

template<typename STORED_TYPE , typename CAST_TO_TYPE >
void mrpt::serialization::CArchive::ReadAsAndCastTo ( CAST_TO_TYPE &  read_here)
inlineinherited

Read a value from a stream stored in a type different of the target variable, making the conversion via static_cast.

Useful for coding backwards compatible de-serialization blocks

Definition at line 137 of file CArchive.h.

Referenced by mrpt::maps::CPointsMap::TRenderOptions::readFromStream().

◆ ReadBuffer()

size_t CArchive::ReadBuffer ( void Buffer,
size_t  Count 
)
inherited

Reads a block of bytes from the stream into Buffer.

Exceptions
std::exceptionOn any error, or if ZERO bytes are read.
Returns
The amound of bytes actually read.
Note
This method is endianness-dependent.
See also
ReadBufferImmediate ; Important, see: ReadBufferFixEndianness,

Definition at line 24 of file CArchive.cpp.

References ASSERT_, mrpt::serialization::CArchive::read(), and THROW_EXCEPTION.

Referenced by mrpt::serialization::CArchive::internal_ReadObject(), mrpt::serialization::CArchive::internal_ReadObjectHeader(), mrpt::serialization::CArchive::ReadBufferFixEndianness(), mrpt::serialization::CArchive::receiveMessage(), and mrpt::obs::CObservationVelodyneScan::serializeFrom().

◆ ReadBufferFixEndianness()

template<typename T >
size_t mrpt::serialization::CArchive::ReadBufferFixEndianness ( T *  ptr,
size_t  ElementCount 
)
inlineinherited

Reads a sequence of elemental datatypes, taking care of reordering their bytes from the MRPT stream standard (little endianness) to the format of the running architecture.

Parameters
ElementCountThe number of elements (not bytes) to read.
ptrA pointer to the first output element in an array (or std::vector<>, etc...).
Returns
The amound of bytes (not elements) actually read (under error situations, the last element may be invalid if the data stream abruptly ends). Example of usage:
s >> N;
vector<float> vec(N);
if (N)
s.ReadBufferFixEndianness<float>(&vec[0],N);
Exceptions
std::exceptionOn any error, or if ZERO bytes are read.
See also
ReadBufferFixEndianness, ReadBuffer

Definition at line 84 of file CArchive.h.

References mrpt::serialization::CArchive::ReadBuffer(), and mrpt::reverseBytesInPlace().

Referenced by mrpt::serialization::CArchive::internal_ReadObjectHeader(), mrpt::math::operator>>(), mrpt::serialization::CArchive::ReadPOD(), and triangle_readFromStream().

◆ ReadObject() [1/3]

CSerializable::Ptr mrpt::serialization::CArchive::ReadObject ( )
inlineinherited

Reads an object from stream, its class determined at runtime, and returns a smart pointer to the object.

Exceptions
std::exceptionOn I/O error or undefined class.
CExceptionEOFOn an End-Of-File condition found at a correct place: an EOF that abruptly finishes in the middle of one object raises a plain std::exception instead.

Definition at line 167 of file CArchive.h.

Referenced by mrpt::serialization::CArchive::operator>>().

◆ ReadObject() [2/3]

template<typename T >
T::Ptr mrpt::serialization::CArchive::ReadObject ( )
inlineinherited

Reads an object from stream, its class determined at runtime, and returns a smart pointer to the object.

This version is similar to mrpt::make_aligned_shared<T>.

Exceptions
std::exceptionOn I/O error or undefined class.
CExceptionEOFOn an End-Of-File condition found at a correct place: an EOF that abruptly finishes in the middle of one object raises a plain std::exception instead.

Definition at line 177 of file CArchive.h.

References mrpt::rtti::TRuntimeClassId::createObject(), mrpt::rtti::findRegisteredClass(), mrpt::serialization::CArchive::internal_ReadObject(), mrpt::serialization::CArchive::internal_ReadObjectHeader(), and THROW_EXCEPTION_FMT.

◆ ReadObject() [3/3]

void CArchive::ReadObject ( CSerializable existingObj)
inherited

Reads an object from stream, where its class must be the same as the supplied object, where the loaded object will be stored in.

Exceptions
std::exceptionOn I/O error or different class found.
CExceptionEOFOn an End-Of-File condition found at a correct place: an EOF that abruptly finishes in the middle of one object raises a plain std::exception instead.

Definition at line 526 of file CArchive.cpp.

References ASSERT_, mrpt::format(), mrpt::serialization::CSerializable::GetRuntimeClass(), mrpt::serialization::CArchive::internal_ReadObject(), mrpt::serialization::CArchive::internal_ReadObjectHeader(), and THROW_EXCEPTION.

◆ ReadPOD()

template<typename T >
T mrpt::serialization::CArchive::ReadPOD ( )
inlineinherited

Reads a simple POD type and returns by value.

Useful when stream >> var; cannot be used becuase of errors of misaligned reference binding. Use with macro MRPT_READ_POD to avoid typing the type T yourself.

Note
[New in MRPT 2.0.0]
Write operator s << var; is safe for misaligned variables.

Definition at line 305 of file CArchive.h.

References mrpt::serialization::CArchive::ReadBufferFixEndianness().

◆ ReadVariant()

template<typename... T>
std::variant<T...> mrpt::serialization::CArchive::ReadVariant ( )
inlineinherited

Reads a variant from stream, its class determined at runtime, and returns a variant to the object.

To be compatible with the current polymorphic system this support smart pointer types. For pointer types, This will bind to the first possible pointer type. variant<CSerializable::Ptr, CRenderizable::Ptr>

Exceptions
std::exceptionOn I/O error or undefined class.
CExceptionEOFOn an End-Of-File condition found at a correct place: an EOF that abruptly finishes in the middle of one object raises a plain std::exception instead.

Definition at line 261 of file CArchive.h.

References mrpt::rtti::TRuntimeClassId::createObject(), mrpt::serialization::CArchive::findRegisteredClassInList(), mrpt::serialization::CArchive::internal_ReadObject(), mrpt::serialization::CArchive::internal_ReadObjectHeader(), mrpt::serialization::CArchive::ReadVariant_helper(), and THROW_EXCEPTION_FMT.

Referenced by mrpt::serialization::operator>>().

◆ ReadVariant_helper() [1/3]

template<typename RET >
RET mrpt::serialization::CArchive::ReadVariant_helper ( CSerializable::Ptr ptr)
inlineprivateinherited

◆ ReadVariant_helper() [2/3]

template<typename RET , typename T , typename... R>
RET mrpt::serialization::CArchive::ReadVariant_helper ( CSerializable::Ptr ptr,
std::enable_if_t< mrpt::is_shared_ptr< T >::value > *  = nullptr 
)
inlineprivateinherited

Definition at line 216 of file CArchive.h.

References IS_CLASS, R, and mrpt::serialization::CArchive::ReadVariant_helper().

◆ ReadVariant_helper() [3/3]

template<typename RET , typename T , typename... R>
RET mrpt::serialization::CArchive::ReadVariant_helper ( CSerializable::Ptr ptr,
std::enable_if_t<!mrpt::is_shared_ptr< T >::value > *  = nullptr 
)
inlineprivateinherited

Definition at line 226 of file CArchive.h.

References IS_CLASS, R, and mrpt::serialization::CArchive::ReadVariant_helper().

◆ receiveMessage()

bool CArchive::receiveMessage ( CMessage msg)
inherited

Tries to receive a message from the device.

Exceptions
std::exceptionOn communication errors
Returns
True if successful, false if there is no new data from the device (but communications seem to work fine)
See also
The frame format is described in sendMessage()

Definition at line 603 of file CArchive.cpp.

References mrpt::serialization::CMessage::content, MAKEWORD16B, mrpt::system::os::memcpy(), MRPT_END, MRPT_START, mrpt::serialization::CArchive::ReadBuffer(), and mrpt::serialization::CMessage::type.

◆ sendMessage()

void CArchive::sendMessage ( const CMessage msg)
inherited

Send a message to the device.

Note that only the low byte from the "type" field will be used.

For frames of size < 255 the frame format is an array of bytes in this order:

<START_FLAG> <HEADER> <LENGTH> <BODY> <END_FLAG>
<START_FLAG> = 0x69
<HEADER> = A header byte
<LENGHT> = Number of bytes of BODY
<BODY> = N x bytes
<END_FLAG> = 0X96
Total length = <LENGTH> + 4

For frames of size > 255 the frame format is an array of bytes in this order:

<START_FLAG> <HEADER> <HIBYTE(LENGTH)> <LOBYTE(LENGTH)> <BODY>
<END_FLAG>
<START_FLAG> = 0x79
<HEADER> = A header byte
<LENGHT> = Number of bytes of BODY
<BODY> = N x bytes
<END_FLAG> = 0X96
Total length = <LENGTH> + 5
Exceptions
std::exceptionOn communication errors

Definition at line 569 of file CArchive.cpp.

References mrpt::serialization::CMessage::content, mrpt::system::os::memcpy(), MRPT_END, MRPT_START, mrpt::serialization::CMessage::type, and mrpt::serialization::CArchive::WriteBuffer().

◆ write()

size_t mrpt::serialization::CArchiveStreamBase< std::vector< uint8_t > >::write ( const void buf,
size_t  len 
)
inlineoverrideprotectedvirtual

Writes a block of bytes.

Exceptions
std::exceptionOn any error
Returns
Number of bytes actually written.

Implements mrpt::serialization::CArchive.

Definition at line 34 of file archiveFrom_std_vector.h.

References mrpt::system::os::memcpy().

◆ WriteAs()

template<typename TYPE_TO_STORE , typename TYPE_FROM_ACTUAL >
void mrpt::serialization::CArchive::WriteAs ( const TYPE_FROM_ACTUAL &  value)
inlineinherited

◆ WriteBuffer()

void CArchive::WriteBuffer ( const void Buffer,
size_t  Count 
)
inherited

Writes a block of bytes to the stream from Buffer.

Exceptions
std::exceptionOn any error
See also
Important, see: WriteBufferFixEndianness
Note
This method is endianness-dependent.

Definition at line 48 of file CArchive.cpp.

References ASSERT_, THROW_EXCEPTION, and mrpt::serialization::CArchive::write().

Referenced by IMPLEMENT_CArchive_READ_WRITE_SIMPLE_TYPE(), mrpt::obs::gnss::Message_NV_OEM6_GENERIC_FRAME::internal_writeToStream(), mrpt::obs::gnss::Message_NV_OEM6_GENERIC_SHORT_FRAME::internal_writeToStream(), mrpt::obs::gnss::Message_NV_OEM6_RANGECMP::internal_writeToStream(), mrpt::obs::gnss::Message_NV_OEM6_VERSION::internal_writeToStream(), mrpt::serialization::operator<<(), mrpt::serialization::CArchive::sendMessage(), mrpt::math::CMatrixB::serializeTo(), mrpt::obs::CObservationCANBusJ1939::serializeTo(), mrpt::nav::CLogFileRecord::serializeTo(), mrpt::serialization::CMemoryChunkBase< Derived >::serializeTo(), mrpt::maps::CWirelessPowerGridMap2D::serializeTo(), mrpt::maps::CGasConcentrationGridMap2D::serializeTo(), mrpt::maps::CHeightGridMap2D_MRF::serializeTo(), mrpt::maps::CReflectivityGridMap2D::serializeTo(), mrpt::obs::CObservation2DRangeScan::serializeTo(), mrpt::maps::COccupancyGridMap2D::serializeTo(), mrpt::obs::CObservationVelodyneScan::serializeTo(), mrpt::maps::CRandomFieldGridMap3D::serializeTo(), mrpt::img::CImage::serializeTo(), mrpt::serialization::CArchive::WriteBufferFixEndianness(), mrpt::serialization::CArchive::WriteObject(), and mrpt::opengl::CRenderizable::writeToStreamRender().

◆ WriteBufferFixEndianness()

template<typename T >
void mrpt::serialization::CArchive::WriteBufferFixEndianness ( const T *  ptr,
size_t  ElementCount 
)
inlineinherited

Writes a sequence of elemental datatypes, taking care of reordering their bytes from the running architecture to MRPT stream standard (little endianness).

Parameters
ElementCountThe number of elements (not bytes) to write.
ptrA pointer to the first input element in an array (or std::vector<>, etc...). Example of usage:
vector<float> vec = ...
uint32_t N = vec.size();
s << N
if (N)
s.WriteBufferFixEndianness<float>(&vec[0],N);
Exceptions
std::exceptionOn any error
See also
WriteBuffer

Definition at line 123 of file CArchive.h.

References mrpt::serialization::CArchive::WriteBuffer().

Referenced by mrpt::math::operator<<(), mrpt::math::CPolygon::serializeTo(), mrpt::math::CMatrix::serializeTo(), mrpt::math::CMatrixD::serializeTo(), mrpt::maps::CColouredPointsMap::serializeTo(), mrpt::maps::CWeightedPointsMap::serializeTo(), mrpt::maps::CSimplePointsMap::serializeTo(), mrpt::obs::CObservation2DRangeScan::serializeTo(), mrpt::maps::COccupancyGridMap2D::serializeTo(), mrpt::obs::CObservation3DRangeScan::serializeTo(), and triangle_writeToStream().

◆ WriteObject() [1/2]

void mrpt::serialization::CArchive::WriteObject ( const CSerializable o)
inlineinherited

◆ WriteObject() [2/2]

void CArchive::WriteObject ( const CSerializable o)
inherited

◆ WriteVariant()

template<typename T >
void mrpt::serialization::CArchive::WriteVariant ( t)
inlineinherited

Writes a Variant to the stream.

Definition at line 292 of file CArchive.h.

References mrpt::serialization::CArchive::WriteObject().

Member Data Documentation

◆ m_pos_read

int mrpt::serialization::CArchiveStreamBase< std::vector< uint8_t > >::m_pos_read {0}
private

Definition at line 29 of file archiveFrom_std_vector.h.

◆ m_v

std::vector<uint8_t>& mrpt::serialization::CArchiveStreamBase< std::vector< uint8_t > >::m_v
private

Definition at line 28 of file archiveFrom_std_vector.h.

s
GLdouble s
Definition: glext.h:3676
mrpt::obs::gnss::header
nv_oem6_header_t header
Novatel frame: NV_OEM6_BESTPOS.
Definition: gnss_messages_novatel.h:226
length
GLuint GLsizei GLsizei * length
Definition: glext.h:4064
LENGTH
@ LENGTH
Definition: inflate.h:50
uint32_t
unsigned __int32 uint32_t
Definition: rptypes.h:47
x
GLenum GLint x
Definition: glext.h:3538



Page generated by Doxygen 1.8.17 for MRPT 1.9.9 Git: ad3a9d8ae Tue May 1 23:10:22 2018 -0700 at miƩ 12 jul 2023 10:03:34 CEST