sbgECom Library
4.0.1987-stable
C library to interface SBG Systems IMU/AHRS/INS
|
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 } |
Used to read/write data from/to a memory buffer stream.
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.
#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.
#define sbgStreamBufferReadUint8LE sbgStreamBufferReadUint8 |
Some methods are common between big and little endian. This definitions just unify the API.
typedef enum _SbgSBMode SbgSBMode |
Stream buffer modes.
typedef enum _SbgSBSeekOrigin SbgSBSeekOrigin |
Enum used to define all seek modes
typedef struct _SbgStreamBuffer SbgStreamBuffer |
Defines a stream buffer.
enum _SbgSBMode |
enum _SbgSBSeekOrigin |
Enum used to define all seek modes
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.
[in] | pHandle | Handle on an allocated stream buffer. |
[in] | pLinkedBuffer | Pointer on an allocated buffer to link with this stream. |
[in] | bufferSize | Size in bytes of the linked buffer. |
References _SbgStreamBuffer::bufferSize, _SbgStreamBuffer::errorCode, _SbgStreamBuffer::modes, _SbgStreamBuffer::pBufferPtr, _SbgStreamBuffer::pCurrentPtr, SB_MODE_WRITE, and SBG_NO_ERROR.
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.
[in] | pHandle | Handle on an allocated stream buffer. |
[in] | pLinkedBuffer | Pointer on an allocated buffer to link with this stream. |
[in] | bufferSize | Size in bytes of the linked buffer. |
References _SbgStreamBuffer::bufferSize, _SbgStreamBuffer::errorCode, _SbgStreamBuffer::modes, _SbgStreamBuffer::pBufferPtr, _SbgStreamBuffer::pCurrentPtr, SB_MODE_READ, and SBG_NO_ERROR.
SBG_INLINE SbgErrorCode sbgStreamBufferGetLastError | ( | const SbgStreamBuffer * | pHandle | ) |
Return the error code that has occurred on the last stream buffer operation.
[in] | pHandle | Pointer to a valid Stream Buffer handle |
References _SbgStreamBuffer::errorCode.
SBG_INLINE void sbgStreamBufferClearLastError | ( | SbgStreamBuffer * | pHandle | ) |
Clear the last error code that has occurred on the last stream buffer operation.
[in] | pHandle | Pointer to a valid Stream Buffer handle |
References _SbgStreamBuffer::errorCode, and SBG_NO_ERROR.
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.
[in] | pHandle | Valid handle on a stream buffer. |
References _SbgStreamBuffer::bufferSize.
Referenced by sbgStreamBufferGetSpace().
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.
[in] | pHandle | Valid handle on a stream buffer. |
References _SbgStreamBuffer::pBufferPtr, and _SbgStreamBuffer::pCurrentPtr.
Referenced by 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).
[in] | pHandle | Valid handle on a stream buffer. |
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().
SBG_INLINE SbgErrorCode sbgStreamBufferSeek | ( | SbgStreamBuffer * | pHandle, |
size_t | offset, | ||
SbgSBSeekOrigin | origin | ||
) |
Move the current cursor position.
[in] | pHandle | Valid handle on a stream buffer. |
[in] | offset | Offset in bytes to apply (only positive). |
[in] | origin | Origin reference point to apply the offset from. |
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.
SBG_INLINE size_t sbgStreamBufferTell | ( | const SbgStreamBuffer * | pHandle | ) |
Returns the current offset in bytes from the beginning of the stream.
[in] | pHandle | Valid handle on a stream buffer. |
References _SbgStreamBuffer::pBufferPtr, and _SbgStreamBuffer::pCurrentPtr.
SBG_INLINE void* sbgStreamBufferGetLinkedBuffer | ( | const SbgStreamBuffer * | pHandle | ) |
Returns a pointer on the internal buffer.
[in] | pHandle | Valid handle on a stream buffer. |
References _SbgStreamBuffer::pBufferPtr.
SBG_INLINE void* sbgStreamBufferGetCursor | ( | const SbgStreamBuffer * | pHandle | ) |
Returns a pointer on the internal buffer at the current cursor.
[in] | pHandle | Valid handle on a stream buffer. |
References _SbgStreamBuffer::pCurrentPtr.
SBG_INLINE int8_t sbgStreamBufferReadInt8 | ( | SbgStreamBuffer * | pHandle | ) |
Read an int8_t from a stream buffer.
[in] | pHandle | Valid stream buffer handle that supports read operations. |
References _SbgStreamBuffer::errorCode, _SbgStreamBuffer::pCurrentPtr, SBG_BUFFER_OVERFLOW, SBG_NO_ERROR, and sbgStreamBufferGetSpace().
SBG_INLINE uint8_t sbgStreamBufferReadUint8 | ( | SbgStreamBuffer * | pHandle | ) |
Read an uint8_t from a stream buffer.
[in] | pHandle | Valid stream buffer handle that supports read operations. |
References _SbgStreamBuffer::errorCode, _SbgStreamBuffer::pCurrentPtr, SBG_BUFFER_OVERFLOW, SBG_NO_ERROR, and sbgStreamBufferGetSpace().
SBG_INLINE bool sbgStreamBufferReadBoolean | ( | SbgStreamBuffer * | pHandle | ) |
Read a boolean from a stream buffer.
[in] | pHandle | Valid stream buffer handle that supports read operations. |
References _SbgStreamBuffer::errorCode, _SbgStreamBuffer::pCurrentPtr, SBG_BUFFER_OVERFLOW, SBG_NO_ERROR, and sbgStreamBufferGetSpace().
SBG_INLINE SbgErrorCode sbgStreamBufferReadBuffer | ( | SbgStreamBuffer * | pHandle, |
void * | pBuffer, | ||
size_t | numBytesToRead | ||
) |
Read a buffer from a stream buffer.
[in] | pHandle | Valid stream buffer handle that supports read operations. |
[out] | pBuffer | Allocated buffer used to hold read data. |
[in] | numBytesToRead | Number of bytes to read from the stream buffer and to store in pBuffer. |
References _SbgStreamBuffer::errorCode, _SbgStreamBuffer::pCurrentPtr, SBG_BUFFER_OVERFLOW, SBG_NO_ERROR, and sbgStreamBufferGetSpace().
Referenced by sbgStreamBufferReadStringBE(), and sbgStreamBufferReadStringLE().
SBG_INLINE SbgErrorCode sbgStreamBufferWriteInt8 | ( | SbgStreamBuffer * | pHandle, |
int8_t | value | ||
) |
Write an int8_t into a stream buffer
[in] | pHandle | Valid stream buffer handle that supports write operations. |
[in] | value | The value to write. |
References _SbgStreamBuffer::errorCode, _SbgStreamBuffer::pCurrentPtr, SBG_BUFFER_OVERFLOW, SBG_NO_ERROR, and sbgStreamBufferGetSpace().
SBG_INLINE SbgErrorCode sbgStreamBufferWriteUint8 | ( | SbgStreamBuffer * | pHandle, |
uint8_t | value | ||
) |
Write an uint8_t into a stream buffer
[in] | pHandle | Valid stream buffer handle that supports write operations. |
[in] | value | The value to write. |
References _SbgStreamBuffer::errorCode, _SbgStreamBuffer::pCurrentPtr, SBG_BUFFER_OVERFLOW, SBG_NO_ERROR, and sbgStreamBufferGetSpace().
SBG_INLINE SbgErrorCode sbgStreamBufferWriteBoolean | ( | SbgStreamBuffer * | pHandle, |
bool | value | ||
) |
Write a boolean into a stream buffer
[in] | pHandle | Valid stream buffer handle that supports write operations. |
[in] | value | The value to write. |
References _SbgStreamBuffer::errorCode, _SbgStreamBuffer::pCurrentPtr, SBG_BUFFER_OVERFLOW, SBG_NO_ERROR, and sbgStreamBufferGetSpace().
SBG_INLINE SbgErrorCode sbgStreamBufferWriteBuffer | ( | SbgStreamBuffer * | pHandle, |
const void * | pBuffer, | ||
size_t | numBytesToWrite | ||
) |
Write a buffer to a stream buffer.
[in] | pHandle | Valid stream buffer handle that supports write operations. |
[out] | pBuffer | Buffer to write into the stream buffer. |
[in] | numBytesToWrite | Number of bytes to write to the stream buffer. |
References _SbgStreamBuffer::errorCode, _SbgStreamBuffer::pCurrentPtr, SBG_BUFFER_OVERFLOW, SBG_NO_ERROR, and sbgStreamBufferGetSpace().
Referenced by sbgStreamBufferWriteStringBE(), and sbgStreamBufferWriteStringLE().