You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This library for **C++11 and newer** assists reading from and writing to **binary data**, making use of my own experience as a reverse engineer.
2
+
This library for **C++20 and newer** assists reading from and writing to **binary data**, making use of my own experience as a reverse engineer.
3
3
4
4
It aims to:
5
-
-Support as far back as **C++11** for those still using older standards.
5
+
-Make use of modern C++ features where **useful** (i.e. `std::endian` and co.).
6
6
- Be as **open-purposed** as possible for a wide range of use cases.
7
7
- Mirror the **standard library's style** for interface.
8
8
- Receive updates as necessary.
@@ -26,19 +26,21 @@ It aims to:
26
26
-[`dump_file()`](#dump_file)
27
27
28
28
## Dependencies
29
-
I'm not one to do strenuous testing on various different platforms and compilers, but this should work as far back as **C++11**. Earlier support will likely never be implemented by myself.
30
-
31
-
Here is the full list of includes used by this library, and the C++ standards they require.
29
+
Here is the full list of includes used by this library:
32
30
```cpp
33
-
#include<cstring>
31
+
#include<bit>
32
+
#include<cstring>
34
33
#include<fstream>
35
-
#include<cstdint>// C++11
36
-
#include<type_traits>// C++11
37
-
#include<vector>// C++11
34
+
#include<cstdint>
35
+
#include<string_view>
36
+
#include<type_traits>
37
+
#include<vector>
38
38
```
39
39
40
+
Otherwise, no external dependencies are used.
41
+
40
42
## Usage
41
-
With a single header file at only ~9KB, it's very easy to start using this library. Support for build systems like **CMake** may be added in the future.
43
+
With a single header file at only ~10KB, it's very easy to start using this library. Support for build systems like **CMake** may be added in the future.
42
44
43
45
```cpp
44
46
#include<kojo/binary.hpp>// or something along those lines.
@@ -160,27 +162,27 @@ size_t size();
160
162
```
161
163
```cpp
162
164
kojo::binary foo;
163
-
foo.write<std::uint64_t>(23, kojo::endian::big);
164
-
foo.write<std::uint32_t>(420, kojo::endian::big);
165
+
foo.write<std::uint64_t>(23, std::endian::big);
166
+
foo.write<std::uint32_t>(420, std::endian::big);
165
167
std::cout << foo.size(); // 12
166
168
```
167
169
168
170
### `set_endian()`
169
171
Sets the endianness of an **integer** to big or little. Mostly exists for internal use.
170
172
```cpp
171
-
template <typename T> T set_endian(T value, kojo::endian endianness);
173
+
template <typename T> T set_endian(T value, std::endian endianness);
172
174
static_assert(std::is_integral<T>::value, "T must be an integral type.");
173
175
```
174
176
```cpp
175
177
kojo::binary foo;
176
-
std::uint32_t number = foo.set_endian(1, kojo::endian::big); // 00 00 00 01
177
-
number = foo.set_endian(number, kojo::endian::little); // 01 00 00 00
178
+
std::uint32_t number = foo.set_endian(1, std::endian::big); // 00 00 00 01
179
+
number = foo.set_endian(number, std::endian::little); // 01 00 00 00
178
180
```
179
181
180
182
### `read()`
181
183
Reads from data into a specified type, that being an integer, `char`, or `std::string`.
182
184
```cpp
183
-
template <typename T> T read(kojo::endian endianness, size_t offset = 0);
185
+
template <typename T> T read(std::endian endianness, size_t offset = 0);
184
186
static_assert(std::is_integral<T>::value, "T must be an integral type.");
0 commit comments