|
|
@ -59,6 +59,72 @@ struct cbor_test : public test_scaffold { |
|
|
|
gen.push_back(gp::make_pair(gp::cbor_value{uint8_t(12), alloc}, gp::cbor_value{int32_t(-98), alloc})); |
|
|
|
gen.push_back(gp::make_pair(gp::cbor_value{uint8_t(13), alloc}, gp::cbor_value{uint32_t(98), alloc})); |
|
|
|
data = gen; |
|
|
|
|
|
|
|
gp::array<std::byte, 7> serialized; |
|
|
|
gp::array<std::byte, 7> serialized_manual{ |
|
|
|
std::byte(0b10100010), |
|
|
|
std::byte(0b00001100), |
|
|
|
std::byte(0b00111000), std::byte(98), |
|
|
|
std::byte(0b00001101), |
|
|
|
std::byte(0b00011000), std::byte(98) |
|
|
|
}; |
|
|
|
|
|
|
|
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::cbor_value data{alloc}; |
|
|
|
data = gp::cbor_number(1); |
|
|
|
|
|
|
|
gp::array<std::byte, 1> serialized; |
|
|
|
gp::array<std::byte, 1> serialized_manual{ |
|
|
|
std::byte(1) |
|
|
|
}; |
|
|
|
|
|
|
|
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::cbor_value data{alloc}; |
|
|
|
data = gp::cbor_floating_point(128.5f); |
|
|
|
|
|
|
|
gp::array<std::byte, 5> serialized; |
|
|
|
gp::array<std::byte, 5> serialized_manual{ |
|
|
|
std::byte(0b11111010), |
|
|
|
std::byte(0b01000011), |
|
|
|
std::byte(0b00000000), |
|
|
|
std::byte(0b10000000), |
|
|
|
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::array<char, 5> str{'h', 'e', 'l', 'l', 'o'}; |
|
|
|
gp::cbor_value data{alloc}; |
|
|
|
data = str.as_buffer().cast<std::byte>(); |
|
|
|
|
|
|
|
gp::array<std::byte, 6> serialized; |
|
|
|
gp::array<std::byte, 6> serialized_manual{ |
|
|
|
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"); |
|
|
|
} |
|
|
|
|
|
|
|
return 0; |
|
|
|