|
|
@ -197,17 +197,17 @@ namespace gp { |
|
|
|
} else if(value <= 65535) { |
|
|
|
if(dest.size() < 3) return dest.begin(); |
|
|
|
dest[0] = std::byte(((uint8_t)major << 5u) + (uint8_t)cbor_oths::word); |
|
|
|
(dest.slice_start(3).slice_end(2).cast<gp::endian_wrapper<uint16_t, gp::endian::big>>())[0] = num.value; |
|
|
|
(dest.slice_start(3).slice_end(2).cast<gp::endian_wrapper<uint16_t, gp::endian::big>>())[0] = num; |
|
|
|
return dest.begin()+3; |
|
|
|
} else if(value <= 4294967295) { |
|
|
|
if(dest.size() < 5) return dest.begin(); |
|
|
|
dest[0] = std::byte(((uint8_t)major << 5u) + (uint8_t)cbor_oths::dword); |
|
|
|
(dest.slice_start(5).slice_end(4).cast<gp::endian_wrapper<uint32_t, gp::endian::big>>())[0] = num.value; |
|
|
|
(dest.slice_start(5).slice_end(4).cast<gp::endian_wrapper<uint32_t, gp::endian::big>>())[0] = num; |
|
|
|
return dest.begin()+5; |
|
|
|
} else { |
|
|
|
if(dest.size() < 9) return dest.begin(); |
|
|
|
dest[0] = std::byte(((uint8_t)major << 5u) + (uint8_t)cbor_oths::qword); |
|
|
|
(dest.slice_start(9).slice_end(8).cast<gp::endian_wrapper<uint64_t, gp::endian::big>>())[0] = num.value; |
|
|
|
(dest.slice_start(9).slice_end(8).cast<gp::endian_wrapper<uint64_t, gp::endian::big>>())[0] = num; |
|
|
|
return dest.begin()+9; |
|
|
|
} |
|
|
|
} |
|
|
@ -250,10 +250,32 @@ namespace gp { |
|
|
|
return dest.begin()+1; |
|
|
|
} |
|
|
|
case cbor_composite<cbor_value>::alt<gp::vector<cbor_value>>(): { |
|
|
|
|
|
|
|
auto& ary = contents.value<gp::vector<cbor_value>>(); |
|
|
|
auto it_begin = encode_length(dest, cbor_type::list, ary.size()); |
|
|
|
if(it_begin != dest.begin()) return dest.begin(); |
|
|
|
for(auto& elem : ary) { |
|
|
|
auto slice = dest.slice_end(dest.size() - (it_begin - dest.begin())); |
|
|
|
auto it = elem.encode(slice); |
|
|
|
if(it == it_begin) return dest.begin(); |
|
|
|
it_begin = it; |
|
|
|
} |
|
|
|
return it_begin; |
|
|
|
} |
|
|
|
case cbor_composite<cbor_value>::alt<gp::vector<gp::pair<cbor_value, cbor_value>>>(): { |
|
|
|
|
|
|
|
auto& ary = contents.value<gp::vector<gp::pair<cbor_value,cbor_value>>>(); |
|
|
|
auto it_begin = encode_length(dest, cbor_type::hmap, ary.size()); |
|
|
|
if(it_begin != dest.begin()) return dest.begin(); |
|
|
|
for(auto& elem : ary) { |
|
|
|
auto slice = dest.slice_end(dest.size() - (it_begin - dest.begin())); |
|
|
|
auto it = elem.first.encode(slice); |
|
|
|
if(it == it_begin) return dest.begin(); |
|
|
|
it_begin = it; |
|
|
|
slice = dest.slice_end(dest.size() - (it_begin - dest.begin())); |
|
|
|
it = elem.second.encode(slice); |
|
|
|
if(it == it_begin) return dest.begin(); |
|
|
|
it_begin = it; |
|
|
|
} |
|
|
|
return it_begin; |
|
|
|
} |
|
|
|
case cbor_composite<cbor_value>::alt<gp::nullopt_t>(): { |
|
|
|
if(dest.size() < 1) return dest.begin(); |
|
|
|