LibCBOR/Tests/Main.cpp

39 lines
928 B
C++

#include "CBOR/Core.hpp"
#include "CBOR/Encoder.hpp"
#include <array>
#include <cstdint>
#include <print>
#include <vector>
int main()
{
using namespace std::string_view_literals;
std::array<std::uint8_t, 256> buffer = {0};
std::vector<std::uint8_t> binData(5, 'g');
CBOR::BasicEncoder enc(buffer);
enc.BeginMap(7);
enc.Encode("Hello ");
enc.Encode("World! ");
enc.Encode("Behold by new power! ");
enc.Encode("It truly is a sight to see ..."sv);
enc.Encode(std::int64_t(1212121212121212));
enc.Encode(binData);
enc.Encode("random double");
enc.Encode(420.69);
enc.Encode("random float");
enc.Encode(420.69f);
enc.Encode("undefined?");
enc.Encode(CBOR::Special::Undefined);
enc.Encode("null?");
enc.Encode(CBOR::Special::Null);
enc.End();
for (const auto &byte: buffer) {
std::print("{:02x} ", byte);
}
std::println("");
}