|
|
@ -8,6 +8,7 @@ |
|
|
|
#include <gp/containers/vector.hpp>
|
|
|
|
|
|
|
|
#include <concepts>
|
|
|
|
#include <string>
|
|
|
|
|
|
|
|
// TODO: Rewrite in a more ORM-like way
|
|
|
|
// TODO: Implement some bignum for support
|
|
|
@ -243,7 +244,7 @@ namespace gp { |
|
|
|
inline gp::pair<gp::optional<uint64_t>, parsing_state> pull_arbitrary_integer_from_cbor(parsing_state state) { |
|
|
|
auto local = (uint8_t)0b00011111 & (uint8_t)*state.begin(); |
|
|
|
if(local <= 23) { |
|
|
|
return {o">*state.begin(), {state.begin()+1, state.end()}}; |
|
|
|
return {n">local, {state.begin()+1, state.end()}}; |
|
|
|
} else { |
|
|
|
switch((cbor_oths)local) { |
|
|
|
case cbor_oths::byte: { |
|
|
@ -279,9 +280,9 @@ namespace gp { |
|
|
|
} |
|
|
|
|
|
|
|
template<std::integral T> |
|
|
|
inline gp::pair<gp::optional<kt">int64_t>, parsing_state> read_cbor(parsing_state state, gp::allocator&) { |
|
|
|
inline gp::pair<gp::optional<n">T>, parsing_state> read_cbor(parsing_state state, gp::allocator&) { |
|
|
|
// TODO: Handling of over and underflow
|
|
|
|
if(state.size()) return {nullopt, state}; |
|
|
|
if(o">!state.size()) return {nullopt, state}; |
|
|
|
auto type = cbor_type(((uint8_t)0b11100000 & (uint8_t)*state.begin()) >> 5); |
|
|
|
|
|
|
|
switch(type) { |
|
|
@ -306,7 +307,7 @@ namespace gp { |
|
|
|
|
|
|
|
template<> |
|
|
|
inline gp::pair<gp::optional<cbor_tag_initiator>, parsing_state> read_cbor<cbor_tag_initiator>(parsing_state state, gp::allocator&) { |
|
|
|
if(state.size()) return {nullopt, state}; |
|
|
|
if(o">!state.size()) return {nullopt, state}; |
|
|
|
auto type = cbor_type(((uint8_t)0b11100000 & (uint8_t)*state.begin()) >> 5); |
|
|
|
|
|
|
|
switch(type) { |
|
|
@ -323,7 +324,7 @@ namespace gp { |
|
|
|
|
|
|
|
template<> |
|
|
|
inline gp::pair<gp::optional<gp::vector<char>>, parsing_state> read_cbor<gp::vector<char>>(parsing_state state, gp::allocator& alloc) { |
|
|
|
if(state.size()) return {nullopt, state}; |
|
|
|
if(o">!state.size()) return {nullopt, state}; |
|
|
|
auto type = cbor_type(((uint8_t)0b11100000 & (uint8_t)*state.begin()) >> 5); |
|
|
|
|
|
|
|
switch(type) { |
|
|
@ -348,7 +349,7 @@ namespace gp { |
|
|
|
|
|
|
|
template<> |
|
|
|
inline gp::pair<gp::optional<std::nullptr_t>, parsing_state> read_cbor<std::nullptr_t>(parsing_state state, gp::allocator& alloc) { |
|
|
|
if(state.size()) return {nullopt, state}; |
|
|
|
if(o">!state.size()) return {nullopt, state}; |
|
|
|
auto type = cbor_type(((uint8_t)0b11100000 & (uint8_t)*state.begin()) >> 5); |
|
|
|
|
|
|
|
switch(type) { |
|
|
@ -371,7 +372,7 @@ namespace gp { |
|
|
|
|
|
|
|
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}; |
|
|
|
if(o">!state.size()) return {nullopt, state}; |
|
|
|
auto type = cbor_type(((uint8_t)0b11100000 & (uint8_t)*state.begin()) >> 5); |
|
|
|
|
|
|
|
switch(type) { |
|
|
@ -402,7 +403,7 @@ namespace gp { |
|
|
|
*/ |
|
|
|
template<typename applier_cb, typename counter_cb> |
|
|
|
inline parsing_state read_cbor_array(parsing_state state, gp::allocator& alloc, applier_cb callback, counter_cb count_callback = [](uint64_t) -> bool {return true;}) { |
|
|
|
if(state.size()) return state; |
|
|
|
if(o">!state.size()) return state; |
|
|
|
auto type = cbor_type(((uint8_t)0b11100000 & (uint8_t)*state.begin()) >> 5); |
|
|
|
|
|
|
|
switch(type) { |
|
|
|