StreamBuffer is a lightweight C library that provides functionalities to handle input and output streams over a stream buffer. It allows you to efficiently read and write various data types to and from the buffer, making it easier to handle data in a streaming fashion.
- Support for both little-endian and big-endian byte order.
- Write and read various data types including float, integer, character, and double.
- Efficiently manage incoming and outgoing bytes in the stream buffer.
- User-configurable options to enable or disable certain features.
StreamBuffer has no external dependencies. It is a self-contained library written in standard C, making it easy to integrate into your projects without worrying about additional dependencies.
To use the StreamBuffer library in your C project, follow these steps:
- Copy the
StreamBuffer.h
andStreamBuffer.c
files into your project directory. - Include the
StreamBuffer.h
header file in your source files where you want to use the library functions. - Initialize a
StreamBuffer
object and a buffer to hold the data.
#include "StreamBuffer.h"
#include <stdio.h>
int main() {
uint8_t buff[128];
StreamBuffer stream;
Stream_init(&stream, buff, sizeof(buff));
// Now you can use the StreamBuffer functions to write and read data.
return 0;
}
You can use the StreamBuffer functions to write data of various data types to the stream buffer:
Stream_writeFloat(&stream, 3.14f);
Stream_writeUInt16(&stream, 42);
Stream_writeChar(&stream, 'A');
// ... and more
Similarly, you can use the StreamBuffer functions to read data from the stream buffer:
float floatValue = Stream_readFloat(&stream);
uint16_t uintValue = Stream_readUInt16(&stream);
char charValue = Stream_readChar(&stream);
// ... and more
The StreamBuffer library allows you to set the byte order (endianess) of the data. By default, it uses the system byte order. However, you can change it to little-endian or big-endian as needed:
Stream_setByteOrder(&stream, ByteOrder_LittleEndian);
// or
Stream_setByteOrder(&stream, ByteOrder_BigEndian);
The library comes with some configurable options that you can modify by defining specific macros before including StreamBuffer.h
in your code:
STREAM_WRITE_LIMIT
: Enable or disable the write limit feature.STREAM_CURSOR
: Enable or disable the cursor feature.STREAM_UINT64
: Enable or disable support for 64-bit unsigned integers.STREAM_DOUBLE
: Enable or disable support for double-precision floating-point numbers.
#include "StreamBuffer.h"
#include <stdio.h>
void myReceiveCallback(IStream* stream, uint8_t* data, Stream_LenType len) {
// Process the received data
}
int main() {
uint8_t rxBuffer[128];
IStream iStream;
IStream_init(&iStream, myReceiveCallback, rxBuffer, sizeof(rxBuffer));
// Now you can receive data using the IStream functions.
return 0;
}
#include "StreamBuffer.h"
#include <stdio.h>
void myTransmitFunction(OStream* stream, uint8_t* data, Stream_LenType len) {
// Transmit the data
}
int main() {
uint8_t txBuffer[128];
OStream oStream;
OStream_init(&oStream, myTransmitFunction, txBuffer, sizeof(txBuffer));
// Now you can write data to be transmitted using the OStream functions.
return 0;
}
- Stream-Test test case for stream library
- Stream-Example shows basic usage of
Stream
Library - Stream-InOut shows basic usage of
Stream
Library forInputStream
andOutputStream
- Stream-Limit shows basic usage of
Stream
Library forInputStream
andOutputStream
with limit - Stream-ReadLine shows how to read single line or pattern over
InputStream
- STM32F4-Echo shows how to port
Stream
Library forSTM32F4xx
microcontrollers and echo data overUART
- STM32F4-ReadLine shows how to port
Stream
Library forSTM32F4xx
microcontrollers and read single line or pattern overUART
- STM32F429-DISCO shows how to port
Stream
Library forSTM32F429xx
microcontrollers and echo data overUART
UARTStream This library implement I/O Stream Driver of UART for STM32Fxxx
We welcome contributions to the StreamBuffer library. If you find any issues or have suggestions for improvements, please open an issue or submit a pull request.
The StreamBuffer C library is licensed under the MIT License. See the LICENSE file for more details.
We would like to thank all the contributors to this project for their valuable input and support.