https://github.com/poseidon-code/datastream
A C++ 23 binary data serializer like Qt's `QDataStream` class, but with less functions and simple.
https://github.com/poseidon-code/datastream
binary cpp cpp23 serializer
Last synced: 7 days ago
JSON representation
A C++ 23 binary data serializer like Qt's `QDataStream` class, but with less functions and simple.
- Host: GitHub
- URL: https://github.com/poseidon-code/datastream
- Owner: poseidon-code
- License: gpl-3.0
- Created: 2024-10-28T18:49:31.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2025-07-30T17:15:40.000Z (3 months ago)
- Last Synced: 2025-07-30T20:15:50.562Z (3 months ago)
- Topics: binary, cpp, cpp23, serializer
- Language: C++
- Homepage:
- Size: 31.3 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# DataStream
A modern binary data serializer in C++ 23 standard, almost like Qt's `QDataStream` class but with less functions and simple.
## Usage
```cpp
#include
#include
#include
#include
#include "DataStream/DataStream.hpp"
#include "DataStream/FixedPointQuantizer.hpp"
int main() {
auto a = DataStream::byteswap(static_cast(1));
// using with containers
std::vector b(20,0);
DataStream::Stream bos(b);
uint16_t bo = 1;
bos << bo; // 0x01 0x00
cis.set(bo, 0); // 0x01 0x00
DataStream::Stream bis(b);
uint16_t bi = 0;
bis >> bi; // 0x01 0x00 = 1
cos.get(bi, 0); // 0x01 0x00 = 1
// using with raw arrays
uint8_t c[20] = {0};
DataStream::Stream cos(c);
uint16_t co = 1;
cos << co; // 0x00 0x01
cos.set(co, 0); // 0x00 0x01
DataStream::Stream cis(c);
uint16_t ci = 0;
cis >> ci; // 0x01 0x00 = 256
cis.get(ci, 0); // 0x01 0x00 = 256
// using with fstream
std::fstream e("./test.bin", std::ios::in | std::ios::out | std::ios::trunc | std::ios::binary);
DataStream::Stream eos(e);
uint16_t eo = 1;
eos << eo; // 0x00 0x01
e.seekg(std::ios::beg);
DataStream::Stream eis(e);
uint16_t ei = 0;
eis >> ei; // 0x01 0x00 = 256
e.close();
// using fixed point quantizer
std::float64_t value = 67.9834672;
DataStream::FixedPointQuantizer quantizer(-90.0, 90.0); // low precision on low number of bits
auto quantized_value = quantizer.to_fpq(value); // quantized value to 64bit signed integer
std::cout << quantized_value << std::endl;
std::cout << quantizer.from_fpq(quantized_value) << std::endl; // switched back to floating point value
return 0;
}
```
# [GPL v3 License](./LICENSE)
DataStream : A modern binary data serializer in C++ 23 standard.
Copyright (C) 2024 Pritam Halder
This program is free software: you can redistribute it and/or modify it under the terms of the
GNU General Public License as published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program.
If not, see .