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: 2 months 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 (6 months ago)
- Default Branch: main
- Last Pushed: 2024-12-21T18:11:39.000Z (4 months ago)
- Last Synced: 2025-01-14T08:13:56.007Z (4 months ago)
- Topics: binary, cpp, cpp23, serializer
- Language: C++
- Homepage:
- Size: 25.4 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 "DataStream/DataStream.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();return 0;
}
```# [GPL v3 License](./LICENSE)
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 .