File: cbor_roundtrip_string.cpp

package info (click to toggle)
glaze 6.4.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky
  • size: 7,312 kB
  • sloc: cpp: 109,539; sh: 99; ansic: 26; makefile: 13
file content (33 lines) | stat: -rw-r--r-- 674 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#include <cassert>
#include <cstddef>
#include <cstdint>
#include <cstring>
#include <glaze/cbor.hpp>
#include <glaze/glaze.hpp>
#include <vector>

struct S
{
   std::string value{};
};

void test(const uint8_t* Data, size_t Size)
{
   S s{{Data, Data + Size}};

   // CBOR handles arbitrary byte sequences in strings, no escaping needed
   std::string buffer{};
   auto write_ec = glz::write_cbor(s, buffer);
   if (write_ec) {
      return;
   }
   auto restored = glz::read_cbor<S>(buffer);
   assert(restored);
   assert(restored.value().value == s.value);
}

extern "C" int LLVMFuzzerTestOneInput(const uint8_t* Data, size_t Size)
{
   test(Data, Size);
   return 0;
}