|
|
@ -8,7 +8,6 @@ |
|
|
|
#include <gp/containers/vector.hpp>
|
|
|
|
|
|
|
|
#include <concepts>
|
|
|
|
#include <string>
|
|
|
|
|
|
|
|
// TODO: Rewrite in a more ORM-like way
|
|
|
|
// TODO: Implement some bignum for support
|
|
|
@ -352,13 +351,12 @@ namespace gp { |
|
|
|
if(!state.size()) return {nullopt, state}; |
|
|
|
auto type = cbor_type(((uint8_t)0b11100000 & (uint8_t)*state.begin()) >> 5); |
|
|
|
|
|
|
|
|
|
|
|
switch(type) { |
|
|
|
case cbor_type::oths: |
|
|
|
{ |
|
|
|
const auto[value, new_state] = pull_arbitrary_integer_from_cbor(state); |
|
|
|
if(!value.has_value()) break; |
|
|
|
if(new_state.size()<value.value()) break; |
|
|
|
gp::vector<char> return_value{alloc}; |
|
|
|
if(value.value() == 22) |
|
|
|
{ |
|
|
|
return {optional(nullptr), parsing_state(new_state.begin()+1, new_state.end())}; |
|
|
@ -370,6 +368,32 @@ namespace gp { |
|
|
|
return {nullopt, state}; |
|
|
|
} |
|
|
|
|
|
|
|
template<> |
|
|
|
inline gp::pair<gp::optional<bool>, parsing_state> read_cbor<bool>(parsing_state state, gp::allocator& alloc) { |
|
|
|
if(!state.size()) return {nullopt, state}; |
|
|
|
auto type = cbor_type(((uint8_t)0b11100000 & (uint8_t)*state.begin()) >> 5); |
|
|
|
|
|
|
|
|
|
|
|
switch(type) { |
|
|
|
case cbor_type::oths: |
|
|
|
{ |
|
|
|
const auto[value, new_state] = pull_arbitrary_integer_from_cbor(state); |
|
|
|
if(!value.has_value()) break; |
|
|
|
if(value.value() == 20) |
|
|
|
{ |
|
|
|
return {false, parsing_state(new_state.begin()+1, new_state.end())}; |
|
|
|
} |
|
|
|
else if(value.value() == 21) |
|
|
|
{ |
|
|
|
return {true, parsing_state(new_state.begin()+1, new_state.end())}; |
|
|
|
} |
|
|
|
break; |
|
|
|
} |
|
|
|
default: break; |
|
|
|
} |
|
|
|
return {nullopt, state}; |
|
|
|
} |
|
|
|
|
|
|
|
template<> |
|
|
|
inline gp::pair<gp::optional<cbor_undefined>, parsing_state> read_cbor<cbor_undefined>(parsing_state state, gp::allocator& alloc) { |
|
|
|
if(!state.size()) return {nullopt, state}; |
|
|
@ -380,8 +404,6 @@ namespace gp { |
|
|
|
{ |
|
|
|
const auto[value, new_state] = pull_arbitrary_integer_from_cbor(state); |
|
|
|
if(!value.has_value()) break; |
|
|
|
if(new_state.size()<value.value()) break; |
|
|
|
gp::vector<char> return_value{alloc}; |
|
|
|
if(value.value() == 23) |
|
|
|
{ |
|
|
|
return {optional(cbor_undefined{}), parsing_state(new_state.begin()+1, new_state.end())}; |
|
|
|