diff --git a/include/gp/enveloppe/cbor.hpp b/include/gp/enveloppe/cbor.hpp index 55d3a62..b12eb25 100644 --- a/include/gp/enveloppe/cbor.hpp +++ b/include/gp/enveloppe/cbor.hpp @@ -147,7 +147,7 @@ namespace gp { template using cbor_composite = gp::fixed_variant< - undefined_t, + gp::undefined_t, cbor_number, gp::vector, bool, diff --git a/include/gp/variant.hpp b/include/gp/variant.hpp index 749ff69..ed72de6 100644 --- a/include/gp/variant.hpp +++ b/include/gp/variant.hpp @@ -31,7 +31,7 @@ namespace gp{ template,T...>::value,int> = 0> fixed_variant(U& value) - : index{r_index_of::value} + : index{r_index_of, T...>::value} { using actual = gp::remove_cvref_t; dtor = gp::function([](void* thing){ diff --git a/tests/cbor_test.cpp b/tests/cbor_test.cpp index ef1640e..306ebcf 100644 --- a/tests/cbor_test.cpp +++ b/tests/cbor_test.cpp @@ -105,6 +105,92 @@ struct cbor_test : public test_scaffold { gp_config::assertion(serialized.begin() != ret_it, "could not encode"); gp_config::assertion(serialized == serialized_manual, "data did not serialize correctly"); } + { + gp::cbor_value data{alloc}; + data = bool(false); + + gp::array serialized; + gp::array serialized_manual{ + std::byte(0b11100000+20) + }; + + auto ret_it = data.encode(serialized.as_buffer()); + + gp_config::assertion(serialized.begin() != ret_it, "could not encode"); + gp_config::assertion(serialized == serialized_manual, "data did not serialize correctly"); + + gp::fill(serialized,(std::byte)0); + + auto decoded = gp::cbor_value::decode(alloc, serialized_manual.as_buffer()); + ret_it = decoded.first.encode(serialized.as_buffer()); + + gp_config::assertion(serialized.begin() != ret_it, "could not encode"); + gp_config::assertion(serialized == serialized_manual, "data did not serialize correctly"); + } + { + gp::cbor_value data{alloc}; + data = bool(true); + + gp::array serialized; + gp::array serialized_manual{ + std::byte(0b11100000+21) + }; + + auto ret_it = data.encode(serialized.as_buffer()); + + gp_config::assertion(serialized.begin() != ret_it, "could not encode"); + gp_config::assertion(serialized == serialized_manual, "data did not serialize correctly"); + + gp::fill(serialized,(std::byte)0); + + auto decoded = gp::cbor_value::decode(alloc, serialized_manual.as_buffer()); + ret_it = decoded.first.encode(serialized.as_buffer()); + + gp_config::assertion(serialized.begin() != ret_it, "could not encode"); + gp_config::assertion(serialized == serialized_manual, "data did not serialize correctly"); + } + { + gp::cbor_value data{gp::nullopt, alloc}; + + gp::array serialized; + gp::array serialized_manual{ + std::byte(0b11100000+22) + }; + + auto ret_it = data.encode(serialized.as_buffer()); + + gp_config::assertion(serialized.begin() != ret_it, "could not encode"); + gp_config::assertion(serialized == serialized_manual, "data did not serialize correctly"); + + gp::fill(serialized,(std::byte)0); + + auto decoded = gp::cbor_value::decode(alloc, serialized_manual.as_buffer()); + ret_it = decoded.first.encode(serialized.as_buffer()); + + gp_config::assertion(serialized.begin() != ret_it, "could not encode"); + gp_config::assertion(serialized == serialized_manual, "data did not serialize correctly"); + } + { + gp::cbor_value data{alloc}; + + gp::array serialized; + gp::array serialized_manual{ + std::byte(0b11100000+23) + }; + + auto ret_it = data.encode(serialized.as_buffer()); + + gp_config::assertion(serialized.begin() != ret_it, "could not encode"); + gp_config::assertion(serialized == serialized_manual, "data did not serialize correctly"); + + gp::fill(serialized,(std::byte)0); + + auto decoded = gp::cbor_value::decode(alloc, serialized_manual.as_buffer()); + ret_it = decoded.first.encode(serialized.as_buffer()); + + gp_config::assertion(serialized.begin() != ret_it, "could not encode"); + gp_config::assertion(serialized == serialized_manual, "data did not serialize correctly"); + } { gp::cbor_value data{alloc}; data = gp::cbor_number(128);