sbgECom Library  4.0.1987-stable
C library to interface SBG Systems IMU/AHRS/INS
sbgStreamBufferCommon.h File Reference

Used to read/write data from/to a memory buffer stream. More...

#include <sbgCommon.h>

Go to the source code of this file.

Data Structures

struct  _SbgStreamBuffer
 

Macros

#define sbgStreamBufferReadUint16   sbgStreamBufferReadUint16LE
 
#define sbgStreamBufferReadUint8LE   sbgStreamBufferReadUint8
 

Typedefs

typedef enum _SbgSBMode SbgSBMode
 
typedef enum _SbgSBSeekOrigin SbgSBSeekOrigin
 
typedef struct _SbgStreamBuffer SbgStreamBuffer
 

Enumerations

enum  _SbgSBMode {
  SB_MODE_READ ,
  SB_MODE_WRITE
}
 
enum  _SbgSBSeekOrigin {
  SB_SEEK_SET ,
  SB_SEEK_CUR_INC ,
  SB_SEEK_CUR_DEC ,
  SB_SEEK_END
}
 

Functions

SBG_INLINE SbgErrorCode sbgStreamBufferInitForWrite (SbgStreamBuffer *pHandle, void *pLinkedBuffer, size_t bufferSize)
 
SBG_INLINE SbgErrorCode sbgStreamBufferInitForRead (SbgStreamBuffer *pHandle, const void *pLinkedBuffer, size_t bufferSize)
 
SBG_INLINE SbgErrorCode sbgStreamBufferGetLastError (const SbgStreamBuffer *pHandle)
 
SBG_INLINE void sbgStreamBufferClearLastError (SbgStreamBuffer *pHandle)
 
SBG_INLINE size_t sbgStreamBufferGetSize (const SbgStreamBuffer *pHandle)
 
SBG_INLINE size_t sbgStreamBufferGetLength (const SbgStreamBuffer *pHandle)
 
SBG_INLINE size_t sbgStreamBufferGetSpace (const SbgStreamBuffer *pHandle)
 
SBG_INLINE SbgErrorCode sbgStreamBufferSeek (SbgStreamBuffer *pHandle, size_t offset, SbgSBSeekOrigin origin)
 
SBG_INLINE size_t sbgStreamBufferTell (const SbgStreamBuffer *pHandle)
 
SBG_INLINE void * sbgStreamBufferGetLinkedBuffer (const SbgStreamBuffer *pHandle)
 
SBG_INLINE void * sbgStreamBufferGetCursor (const SbgStreamBuffer *pHandle)
 
SBG_INLINE int8_t sbgStreamBufferReadInt8 (SbgStreamBuffer *pHandle)
 
SBG_INLINE uint8_t sbgStreamBufferReadUint8 (SbgStreamBuffer *pHandle)
 
SBG_INLINE bool sbgStreamBufferReadBoolean (SbgStreamBuffer *pHandle)
 
SBG_INLINE SbgErrorCode sbgStreamBufferReadBuffer (SbgStreamBuffer *pHandle, void *pBuffer, size_t numBytesToRead)
 
SBG_INLINE SbgErrorCode sbgStreamBufferWriteInt8 (SbgStreamBuffer *pHandle, int8_t value)
 
SBG_INLINE SbgErrorCode sbgStreamBufferWriteUint8 (SbgStreamBuffer *pHandle, uint8_t value)
 
SBG_INLINE SbgErrorCode sbgStreamBufferWriteBoolean (SbgStreamBuffer *pHandle, bool value)
 
SBG_INLINE SbgErrorCode sbgStreamBufferWriteBuffer (SbgStreamBuffer *pHandle, const void *pBuffer, size_t numBytesToWrite)
 

Detailed Description

Used to read/write data from/to a memory buffer stream.

Author
SBG Systems
Date
02 January 2013
License

The MIT license

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Macro Definition Documentation

◆ sbgStreamBufferReadUint16

#define sbgStreamBufferReadUint16   sbgStreamBufferReadUint16LE

The default method should read and write using the platform endianness

The platform is a little endian one so default methods should use little endian byte order.

◆ sbgStreamBufferReadUint8LE

#define sbgStreamBufferReadUint8LE   sbgStreamBufferReadUint8

Some methods are common between big and little endian. This definitions just unify the API.

Typedef Documentation

◆ SbgSBMode

typedef enum _SbgSBMode SbgSBMode

Stream buffer modes.

◆ SbgSBSeekOrigin

Enum used to define all seek modes

◆ SbgStreamBuffer

Defines a stream buffer.

Enumeration Type Documentation

◆ _SbgSBMode

enum _SbgSBMode

Stream buffer modes.

Enumerator
SB_MODE_READ 

This stream buffer can perform read operations.

SB_MODE_WRITE 

This stream buffer can perform write operations.

◆ _SbgSBSeekOrigin

Enum used to define all seek modes

Enumerator
SB_SEEK_SET 

The offset is referenced to the begining of the stream.

SB_SEEK_CUR_INC 

The offset is referenced to the current cursor position and increment the current cursor.

SB_SEEK_CUR_DEC 

The offset is referenced to the current cursor position and decrement the current cursor.

SB_SEEK_END 

The offset is referenced to the end of the stream.

Function Documentation

◆ sbgStreamBufferInitForWrite()

SBG_INLINE SbgErrorCode sbgStreamBufferInitForWrite ( SbgStreamBuffer pHandle,
void *  pLinkedBuffer,
size_t  bufferSize 
)

Initialize a stream buffer for both read and write operations and link it to a buffer.

Parameters
[in]pHandleHandle on an allocated stream buffer.
[in]pLinkedBufferPointer on an allocated buffer to link with this stream.
[in]bufferSizeSize in bytes of the linked buffer.
Returns
SBG_NO_ERROR if the stream buffer has been initialized successfully.

References _SbgStreamBuffer::bufferSize, _SbgStreamBuffer::errorCode, _SbgStreamBuffer::modes, _SbgStreamBuffer::pBufferPtr, _SbgStreamBuffer::pCurrentPtr, SB_MODE_WRITE, and SBG_NO_ERROR.

◆ sbgStreamBufferInitForRead()

SBG_INLINE SbgErrorCode sbgStreamBufferInitForRead ( SbgStreamBuffer pHandle,
const void *  pLinkedBuffer,
size_t  bufferSize 
)

Initialize a stream buffer for both read and write operations and link it to a buffer.

Parameters
[in]pHandleHandle on an allocated stream buffer.
[in]pLinkedBufferPointer on an allocated buffer to link with this stream.
[in]bufferSizeSize in bytes of the linked buffer.
Returns
SBG_NO_ERROR if the stream buffer has been initialized successfully.

References _SbgStreamBuffer::bufferSize, _SbgStreamBuffer::errorCode, _SbgStreamBuffer::modes, _SbgStreamBuffer::pBufferPtr, _SbgStreamBuffer::pCurrentPtr, SB_MODE_READ, and SBG_NO_ERROR.

◆ sbgStreamBufferGetLastError()

SBG_INLINE SbgErrorCode sbgStreamBufferGetLastError ( const SbgStreamBuffer pHandle)

Return the error code that has occurred on the last stream buffer operation.

Parameters
[in]pHandlePointer to a valid Stream Buffer handle
Returns
Last stream buffer error code

References _SbgStreamBuffer::errorCode.

◆ sbgStreamBufferClearLastError()

SBG_INLINE void sbgStreamBufferClearLastError ( SbgStreamBuffer pHandle)

Clear the last error code that has occurred on the last stream buffer operation.

Parameters
[in]pHandlePointer to a valid Stream Buffer handle

References _SbgStreamBuffer::errorCode, and SBG_NO_ERROR.

◆ sbgStreamBufferGetSize()

SBG_INLINE size_t sbgStreamBufferGetSize ( const SbgStreamBuffer pHandle)

Returns the size in bytes of this stream.

The size is the linked buffer total size in bytes. For example, for a SbgStreamBuffer linked with a buffer of 256 bytes, this method will always returns 256 even if no data has been written or read.

Parameters
[in]pHandleValid handle on a stream buffer.
Returns
The allocated size of the linked buffer in bytes.

References _SbgStreamBuffer::bufferSize.

Referenced by sbgStreamBufferGetSpace().

◆ sbgStreamBufferGetLength()

SBG_INLINE size_t sbgStreamBufferGetLength ( const SbgStreamBuffer pHandle)

Returns the length in bytes of this stream.

The length is computed using the current cursor position. If no data has been read or written, this method will return 0. If 4 uint32_t has been written, it should return 16.

Parameters
[in]pHandleValid handle on a stream buffer.
Returns
The current cursor position in bytes.

References _SbgStreamBuffer::pBufferPtr, and _SbgStreamBuffer::pCurrentPtr.

Referenced by sbgStreamBufferGetSpace().

◆ sbgStreamBufferGetSpace()

SBG_INLINE size_t sbgStreamBufferGetSpace ( const SbgStreamBuffer pHandle)

Returns the available space in this stream.

The available space is just the delta between the linked buffer size and the current buffer length (cursor position).

Parameters
[in]pHandleValid handle on a stream buffer.
Returns
The space available in this stream buffer in bytes.

References sbgStreamBufferGetLength(), and sbgStreamBufferGetSize().

Referenced by sbgStreamBufferReadBoolean(), sbgStreamBufferReadBuffer(), sbgStreamBufferReadDoubleBE(), sbgStreamBufferReadDoubleLE(), sbgStreamBufferReadFloatBE(), sbgStreamBufferReadFloatLE(), sbgStreamBufferReadInt16BE(), sbgStreamBufferReadInt16LE(), sbgStreamBufferReadInt24BE(), sbgStreamBufferReadInt24LE(), sbgStreamBufferReadInt32BE(), sbgStreamBufferReadInt32LE(), sbgStreamBufferReadInt40BE(), sbgStreamBufferReadInt40LE(), sbgStreamBufferReadInt48BE(), sbgStreamBufferReadInt48LE(), sbgStreamBufferReadInt56BE(), sbgStreamBufferReadInt56LE(), sbgStreamBufferReadInt64BE(), sbgStreamBufferReadInt64LE(), sbgStreamBufferReadInt8(), sbgStreamBufferReadUint16BE(), sbgStreamBufferReadUint16LE(), sbgStreamBufferReadUint24BE(), sbgStreamBufferReadUint24LE(), sbgStreamBufferReadUint32BE(), sbgStreamBufferReadUint32LE(), sbgStreamBufferReadUint40BE(), sbgStreamBufferReadUint40LE(), sbgStreamBufferReadUint48BE(), sbgStreamBufferReadUint48LE(), sbgStreamBufferReadUint56BE(), sbgStreamBufferReadUint56LE(), sbgStreamBufferReadUint64BE(), sbgStreamBufferReadUint64LE(), sbgStreamBufferReadUint8(), sbgStreamBufferWriteBoolean(), sbgStreamBufferWriteBuffer(), sbgStreamBufferWriteInt16BE(), sbgStreamBufferWriteInt16LE(), sbgStreamBufferWriteInt32BE(), sbgStreamBufferWriteInt32LE(), sbgStreamBufferWriteInt64BE(), sbgStreamBufferWriteInt64LE(), sbgStreamBufferWriteInt8(), sbgStreamBufferWriteUint16BE(), sbgStreamBufferWriteUint16LE(), sbgStreamBufferWriteUint32BE(), sbgStreamBufferWriteUint32LE(), sbgStreamBufferWriteUint48BE(), sbgStreamBufferWriteUint48LE(), sbgStreamBufferWriteUint64BE(), sbgStreamBufferWriteUint64LE(), and sbgStreamBufferWriteUint8().

◆ sbgStreamBufferSeek()

SBG_INLINE SbgErrorCode sbgStreamBufferSeek ( SbgStreamBuffer pHandle,
size_t  offset,
SbgSBSeekOrigin  origin 
)

Move the current cursor position.

Parameters
[in]pHandleValid handle on a stream buffer.
[in]offsetOffset in bytes to apply (only positive).
[in]originOrigin reference point to apply the offset from.
Returns
SBG_NO_ERROR if the stream current cursor position has been moved.

References _SbgStreamBuffer::bufferSize, _SbgStreamBuffer::errorCode, _SbgStreamBuffer::pBufferPtr, _SbgStreamBuffer::pCurrentPtr, SB_SEEK_CUR_DEC, SB_SEEK_CUR_INC, SB_SEEK_END, SB_SEEK_SET, SBG_INVALID_PARAMETER, and SBG_NO_ERROR.

◆ sbgStreamBufferTell()

SBG_INLINE size_t sbgStreamBufferTell ( const SbgStreamBuffer pHandle)

Returns the current offset in bytes from the beginning of the stream.

Parameters
[in]pHandleValid handle on a stream buffer.
Returns
Current offset in bytes from the beginning.

References _SbgStreamBuffer::pBufferPtr, and _SbgStreamBuffer::pCurrentPtr.

◆ sbgStreamBufferGetLinkedBuffer()

SBG_INLINE void* sbgStreamBufferGetLinkedBuffer ( const SbgStreamBuffer pHandle)

Returns a pointer on the internal buffer.

Parameters
[in]pHandleValid handle on a stream buffer.
Returns
Pointer on the begining of the internal buffer.

References _SbgStreamBuffer::pBufferPtr.

◆ sbgStreamBufferGetCursor()

SBG_INLINE void* sbgStreamBufferGetCursor ( const SbgStreamBuffer pHandle)

Returns a pointer on the internal buffer at the current cursor.

Parameters
[in]pHandleValid handle on a stream buffer.
Returns
Pointer on the current cursor of the internal buffer.

References _SbgStreamBuffer::pCurrentPtr.

◆ sbgStreamBufferReadInt8()

SBG_INLINE int8_t sbgStreamBufferReadInt8 ( SbgStreamBuffer pHandle)

Read an int8_t from a stream buffer.

Parameters
[in]pHandleValid stream buffer handle that supports read operations.
Returns
The read value or 0 if we have an error.

References _SbgStreamBuffer::errorCode, _SbgStreamBuffer::pCurrentPtr, SBG_BUFFER_OVERFLOW, SBG_NO_ERROR, and sbgStreamBufferGetSpace().

◆ sbgStreamBufferReadUint8()

SBG_INLINE uint8_t sbgStreamBufferReadUint8 ( SbgStreamBuffer pHandle)

Read an uint8_t from a stream buffer.

Parameters
[in]pHandleValid stream buffer handle that supports read operations.
Returns
The read value or 0 if we have an error.

References _SbgStreamBuffer::errorCode, _SbgStreamBuffer::pCurrentPtr, SBG_BUFFER_OVERFLOW, SBG_NO_ERROR, and sbgStreamBufferGetSpace().

◆ sbgStreamBufferReadBoolean()

SBG_INLINE bool sbgStreamBufferReadBoolean ( SbgStreamBuffer pHandle)

Read a boolean from a stream buffer.

Parameters
[in]pHandleValid stream buffer handle that supports read operations.
Returns
The read value or false if we have an error.

References _SbgStreamBuffer::errorCode, _SbgStreamBuffer::pCurrentPtr, SBG_BUFFER_OVERFLOW, SBG_NO_ERROR, and sbgStreamBufferGetSpace().

◆ sbgStreamBufferReadBuffer()

SBG_INLINE SbgErrorCode sbgStreamBufferReadBuffer ( SbgStreamBuffer pHandle,
void *  pBuffer,
size_t  numBytesToRead 
)

Read a buffer from a stream buffer.

Parameters
[in]pHandleValid stream buffer handle that supports read operations.
[out]pBufferAllocated buffer used to hold read data.
[in]numBytesToReadNumber of bytes to read from the stream buffer and to store in pBuffer.
Returns
SBG_NO_ERROR if the data has been read.

References _SbgStreamBuffer::errorCode, _SbgStreamBuffer::pCurrentPtr, SBG_BUFFER_OVERFLOW, SBG_NO_ERROR, and sbgStreamBufferGetSpace().

Referenced by sbgStreamBufferReadStringBE(), and sbgStreamBufferReadStringLE().

◆ sbgStreamBufferWriteInt8()

SBG_INLINE SbgErrorCode sbgStreamBufferWriteInt8 ( SbgStreamBuffer pHandle,
int8_t  value 
)

Write an int8_t into a stream buffer

Parameters
[in]pHandleValid stream buffer handle that supports write operations.
[in]valueThe value to write.
Returns
SBG_NO_ERROR if the value has been successfully written.

References _SbgStreamBuffer::errorCode, _SbgStreamBuffer::pCurrentPtr, SBG_BUFFER_OVERFLOW, SBG_NO_ERROR, and sbgStreamBufferGetSpace().

◆ sbgStreamBufferWriteUint8()

SBG_INLINE SbgErrorCode sbgStreamBufferWriteUint8 ( SbgStreamBuffer pHandle,
uint8_t  value 
)

Write an uint8_t into a stream buffer

Parameters
[in]pHandleValid stream buffer handle that supports write operations.
[in]valueThe value to write.
Returns
SBG_NO_ERROR if the value has been successfully written.

References _SbgStreamBuffer::errorCode, _SbgStreamBuffer::pCurrentPtr, SBG_BUFFER_OVERFLOW, SBG_NO_ERROR, and sbgStreamBufferGetSpace().

◆ sbgStreamBufferWriteBoolean()

SBG_INLINE SbgErrorCode sbgStreamBufferWriteBoolean ( SbgStreamBuffer pHandle,
bool  value 
)

Write a boolean into a stream buffer

Parameters
[in]pHandleValid stream buffer handle that supports write operations.
[in]valueThe value to write.
Returns
SBG_NO_ERROR if the value has been successfully written.

References _SbgStreamBuffer::errorCode, _SbgStreamBuffer::pCurrentPtr, SBG_BUFFER_OVERFLOW, SBG_NO_ERROR, and sbgStreamBufferGetSpace().

◆ sbgStreamBufferWriteBuffer()

SBG_INLINE SbgErrorCode sbgStreamBufferWriteBuffer ( SbgStreamBuffer pHandle,
const void *  pBuffer,
size_t  numBytesToWrite 
)

Write a buffer to a stream buffer.

Parameters
[in]pHandleValid stream buffer handle that supports write operations.
[out]pBufferBuffer to write into the stream buffer.
[in]numBytesToWriteNumber of bytes to write to the stream buffer.
Returns
SBG_NO_ERROR if the data has been written.

References _SbgStreamBuffer::errorCode, _SbgStreamBuffer::pCurrentPtr, SBG_BUFFER_OVERFLOW, SBG_NO_ERROR, and sbgStreamBufferGetSpace().

Referenced by sbgStreamBufferWriteStringBE(), and sbgStreamBufferWriteStringLE().