|
@ -105,6 +105,139 @@ struct cbor_test : public test_scaffold { |
|
|
gp_config::assertion(serialized.begin() != ret_it, "could not encode"); |
|
|
gp_config::assertion(serialized.begin() != ret_it, "could not encode"); |
|
|
gp_config::assertion(serialized == serialized_manual, "data did not serialize correctly"); |
|
|
gp_config::assertion(serialized == serialized_manual, "data did not serialize correctly"); |
|
|
} |
|
|
} |
|
|
|
|
|
{ |
|
|
|
|
|
gp::cbor_value data{alloc}; |
|
|
|
|
|
data = gp::cbor_number(128); |
|
|
|
|
|
|
|
|
|
|
|
gp::array<std::byte, 2> serialized; |
|
|
|
|
|
gp::array<std::byte, 2> serialized_manual{ |
|
|
|
|
|
std::byte(0b00011000), |
|
|
|
|
|
std::byte(0b10000000) |
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
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(1024); |
|
|
|
|
|
|
|
|
|
|
|
gp::array<std::byte, 3> serialized; |
|
|
|
|
|
gp::array<std::byte, 3> serialized_manual{ |
|
|
|
|
|
std::byte(0b00011001), |
|
|
|
|
|
std::byte(0b00000100), |
|
|
|
|
|
std::byte(0b00000000) |
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
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(0xAABBCCDDu); |
|
|
|
|
|
|
|
|
|
|
|
gp::array<std::byte, 5> serialized; |
|
|
|
|
|
gp::array<std::byte, 5> serialized_manual{ |
|
|
|
|
|
std::byte(0b00011010), |
|
|
|
|
|
std::byte(0xAA), |
|
|
|
|
|
std::byte(0xBB), |
|
|
|
|
|
std::byte(0xCC), |
|
|
|
|
|
std::byte(0xDD) |
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
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(false, 0xAABBCCDDEEFF0011ull); |
|
|
|
|
|
|
|
|
|
|
|
gp::array<std::byte, 9> serialized; |
|
|
|
|
|
gp::array<std::byte, 9> serialized_manual{ |
|
|
|
|
|
std::byte(0b00011011), |
|
|
|
|
|
std::byte(0xAA), |
|
|
|
|
|
std::byte(0xBB), |
|
|
|
|
|
std::byte(0xCC), |
|
|
|
|
|
std::byte(0xDD), |
|
|
|
|
|
std::byte(0xEE), |
|
|
|
|
|
std::byte(0xFF), |
|
|
|
|
|
std::byte(0x00), |
|
|
|
|
|
std::byte(0x11) |
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
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(true, 0xAABBCCDDEEFF0011ull); |
|
|
|
|
|
|
|
|
|
|
|
gp::array<std::byte, 9> serialized; |
|
|
|
|
|
gp::array<std::byte, 9> serialized_manual{ |
|
|
|
|
|
std::byte(0b00111011), |
|
|
|
|
|
std::byte(0xAA), |
|
|
|
|
|
std::byte(0xBB), |
|
|
|
|
|
std::byte(0xCC), |
|
|
|
|
|
std::byte(0xDD), |
|
|
|
|
|
std::byte(0xEE), |
|
|
|
|
|
std::byte(0xFF), |
|
|
|
|
|
std::byte(0x00), |
|
|
|
|
|
std::byte(0x11) |
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
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::cbor_value data{alloc}; |
|
|
data = gp::cbor_floating_point(128.5f); |
|
|
data = gp::cbor_floating_point(128.5f); |
|
@ -131,6 +264,36 @@ struct cbor_test : public test_scaffold { |
|
|
gp_config::assertion(serialized.begin() != ret_it, "could not encode"); |
|
|
gp_config::assertion(serialized.begin() != ret_it, "could not encode"); |
|
|
gp_config::assertion(serialized == serialized_manual, "data did not serialize correctly"); |
|
|
gp_config::assertion(serialized == serialized_manual, "data did not serialize correctly"); |
|
|
} |
|
|
} |
|
|
|
|
|
{ |
|
|
|
|
|
gp::cbor_value data{alloc}; |
|
|
|
|
|
data = gp::cbor_floating_point((double)128.5); |
|
|
|
|
|
|
|
|
|
|
|
gp::array<std::byte, 9> serialized; |
|
|
|
|
|
gp::array<std::byte, 9> serialized_manual{ |
|
|
|
|
|
std::byte(0b11111011), |
|
|
|
|
|
std::byte(0b01000000), |
|
|
|
|
|
std::byte(0b01100000), |
|
|
|
|
|
std::byte(0b00010000), |
|
|
|
|
|
std::byte(0b00000000), |
|
|
|
|
|
std::byte(0b00000000), |
|
|
|
|
|
std::byte(0b00000000), |
|
|
|
|
|
std::byte(0b00000000), |
|
|
|
|
|
std::byte(0b00000000) |
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
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::vector<std::byte> str{alloc}; |
|
|
gp::vector<std::byte> str{alloc}; |
|
|
str.reserve(5); |
|
|
str.reserve(5); |
|
@ -162,6 +325,68 @@ struct cbor_test : public test_scaffold { |
|
|
gp_config::assertion(serialized.begin() != ret_it, "could not encode"); |
|
|
gp_config::assertion(serialized.begin() != ret_it, "could not encode"); |
|
|
gp_config::assertion(serialized == serialized_manual, "data did not serialize correctly"); |
|
|
gp_config::assertion(serialized == serialized_manual, "data did not serialize correctly"); |
|
|
} |
|
|
} |
|
|
|
|
|
{ |
|
|
|
|
|
gp::vector<std::byte> str{alloc}; |
|
|
|
|
|
str.reserve(5); |
|
|
|
|
|
for(auto a : {'h', 'e', 'l', 'l', 'o'}) |
|
|
|
|
|
str.push_back((std::byte)a); |
|
|
|
|
|
gp::cbor_value data{alloc}; |
|
|
|
|
|
data = str; |
|
|
|
|
|
gp::vector<gp::cbor_value> meta{alloc}; |
|
|
|
|
|
gp::repeat(5, [&](){ |
|
|
|
|
|
meta.push_back(data); |
|
|
|
|
|
}); |
|
|
|
|
|
data = meta; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
gp::array<std::byte, 31> serialized; |
|
|
|
|
|
gp::array<std::byte, 31> serialized_manual{ |
|
|
|
|
|
std::byte(0b10000101), |
|
|
|
|
|
std::byte(0b01000101), |
|
|
|
|
|
std::byte('h'), |
|
|
|
|
|
std::byte('e'), |
|
|
|
|
|
std::byte('l'), |
|
|
|
|
|
std::byte('l'), |
|
|
|
|
|
std::byte('o'), |
|
|
|
|
|
std::byte(0b01000101), |
|
|
|
|
|
std::byte('h'), |
|
|
|
|
|
std::byte('e'), |
|
|
|
|
|
std::byte('l'), |
|
|
|
|
|
std::byte('l'), |
|
|
|
|
|
std::byte('o'), |
|
|
|
|
|
std::byte(0b01000101), |
|
|
|
|
|
std::byte('h'), |
|
|
|
|
|
std::byte('e'), |
|
|
|
|
|
std::byte('l'), |
|
|
|
|
|
std::byte('l'), |
|
|
|
|
|
std::byte('o'), |
|
|
|
|
|
std::byte(0b01000101), |
|
|
|
|
|
std::byte('h'), |
|
|
|
|
|
std::byte('e'), |
|
|
|
|
|
std::byte('l'), |
|
|
|
|
|
std::byte('l'), |
|
|
|
|
|
std::byte('o'), |
|
|
|
|
|
std::byte(0b01000101), |
|
|
|
|
|
std::byte('h'), |
|
|
|
|
|
std::byte('e'), |
|
|
|
|
|
std::byte('l'), |
|
|
|
|
|
std::byte('l'), |
|
|
|
|
|
std::byte('o') |
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
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"); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
return 0; |
|
|
return 0; |
|
|
} |
|
|
} |
|
|