PxFileBuf

Defined in include/filebuf/PxFileBuf.h

class PxFileBuf

Callback class for data serialization.

The user needs to supply an PxFileBuf implementation to a number of methods to allow the SDK to read or write chunks of binary data. This allows flexibility for the source/destination of the data. For example the PxFileBuf could store data in a file, memory buffer or custom file format.

Note

It is the users responsibility to ensure that the data is written to the appropriate offset.

Public Types

enum EndianMode

Values:

enumerator ENDIAN_NONE
enumerator ENDIAN_BIG
enumerator ENDIAN_LITTLE
enum OpenMode

Values:

enumerator OPEN_FILE_NOT_FOUND
enumerator OPEN_READ_ONLY
enumerator OPEN_WRITE_ONLY
enumerator OPEN_READ_WRITE_NEW
enumerator OPEN_READ_WRITE_EXISTING
enum SeekType

Values:

enumerator SEEKABLE_NO
enumerator SEEKABLE_READ
enumerator SEEKABLE_WRITE
enumerator SEEKABLE_READWRITE

Public Functions

inline PxFileBuf(EndianMode mode = ENDIAN_LITTLE)
inline virtual ~PxFileBuf(void)
virtual OpenMode getOpenMode(void) const = 0
inline bool isOpen(void) const
virtual SeekType isSeekable(void) const = 0
inline void setEndianMode(EndianMode e)
inline EndianMode getEndianMode(void) const
virtual uint32_t getFileLength(void) const = 0
virtual uint32_t seekRead(uint32_t loc) = 0

Seeks the stream to a particular location for reading.

If the location passed exceeds the length of the stream, then it will seek to the end. Returns the location it ended up at (useful if you seek to the end) to get the file position

virtual uint32_t seekWrite(uint32_t loc) = 0

Seeks the stream to a particular location for writing.

If the location passed exceeds the length of the stream, then it will seek to the end. Returns the location it ended up at (useful if you seek to the end) to get the file position

virtual uint32_t read(void *mem, uint32_t len) = 0

Reads from the stream into a buffer.

Parameters
  • mem[out] The buffer to read the stream into.

  • len[in] The number of bytes to stream into the buffer

Returns

Returns the actual number of bytes read. If not equal to the length requested, then reached end of stream.

virtual uint32_t peek(void *mem, uint32_t len) = 0

Reads from the stream into a buffer but does not advance the read location.

Parameters
  • mem[out] The buffer to read the stream into.

  • len[in] The number of bytes to stream into the buffer

Returns

Returns the actual number of bytes read. If not equal to the length requested, then reached end of stream.

virtual uint32_t write(const void *mem, uint32_t len) = 0

Writes a buffer of memory to the stream.

Parameters
  • mem[in] The address of a buffer of memory to send to the stream.

  • len[in] The number of bytes to send to the stream.

Returns

Returns the actual number of bytes sent to the stream. If not equal to the length specific, then the stream is full or unable to write for some reason.

virtual uint32_t tellRead(void) const = 0

Reports the current stream location read aqccess.

Returns

Returns the current stream read location.

virtual uint32_t tellWrite(void) const = 0

Reports the current stream location for write access.

Returns

Returns the current stream write location.

virtual void flush(void) = 0

Causes any temporarily cached data to be flushed to the stream.

inline virtual void close(void)

Close the stream.

inline void release(void)
inline void swap2Bytes(void *_data) const
inline void swap4Bytes(void *_data) const
inline void swap8Bytes(void *_data) const
inline void storeDword(uint32_t v)
inline void storeFloat(float v)
inline void storeDouble(double v)
inline void storeByte(uint8_t b)
inline void storeWord(uint16_t w)
inline uint8_t readByte(void)
inline uint16_t readWord(void)
inline uint32_t readDword(void)
inline float readFloat(void)
inline double readDouble(void)

Public Static Functions

static inline bool isBigEndian()

Public Static Attributes

static const uint32_t STREAM_SEEK_END = 0xFFFFFFFF

Declares a constant to seek to the end of the stream.

Does not support streams longer than 32 bits