/src/glaze/fuzzing/msgpack_roundtrip_string.cpp
Line | Count | Source |
1 | | #include <cassert> |
2 | | #include <cstddef> |
3 | | #include <cstdint> |
4 | | #include <cstring> |
5 | | #include <glaze/glaze.hpp> |
6 | | #include <glaze/msgpack.hpp> |
7 | | #include <vector> |
8 | | |
9 | | struct S |
10 | | { |
11 | | std::string value{}; |
12 | | }; |
13 | | |
14 | | void test(const uint8_t* Data, size_t Size) |
15 | 836 | { |
16 | 836 | S s{{Data, Data + Size}}; |
17 | | |
18 | | // MessagePack handles arbitrary byte sequences in strings |
19 | 836 | std::string buffer{}; |
20 | 836 | auto write_ec = glz::write_msgpack(s, buffer); |
21 | 836 | if (write_ec) { |
22 | 0 | return; |
23 | 0 | } |
24 | 836 | auto restored = glz::read_msgpack<S>(buffer); |
25 | 836 | assert(restored); |
26 | 836 | assert(restored.value().value == s.value); |
27 | 836 | } |
28 | | |
29 | | extern "C" int LLVMFuzzerTestOneInput(const uint8_t* Data, size_t Size) |
30 | 45.8k | { |
31 | 45.8k | test(Data, Size); |
32 | 45.8k | return 0; |
33 | 45.8k | } |