diff --git a/include/gp/ipc/envelope/cbor.hpp b/include/gp/ipc/envelope/cbor.hpp index dddcf50..00e967f 100644 --- a/include/gp/ipc/envelope/cbor.hpp +++ b/include/gp/ipc/envelope/cbor.hpp @@ -8,6 +8,7 @@ #include #include +#include // TODO: Rewrite in a more ORM-like way // TODO: Implement some bignum for support @@ -243,7 +244,7 @@ namespace gp { inline gp::pair, parsing_state> pull_arbitrary_integer_from_cbor(parsing_state state) { auto local = (uint8_t)0b00011111 & (uint8_t)*state.begin(); if(local <= 23) { - return {*state.begin(), {state.begin()+1, state.end()}}; + return {local, {state.begin()+1, state.end()}}; } else { switch((cbor_oths)local) { case cbor_oths::byte: { @@ -279,9 +280,9 @@ namespace gp { } template - inline gp::pair, parsing_state> read_cbor(parsing_state state, gp::allocator&) { + inline gp::pair, parsing_state> read_cbor(parsing_state state, gp::allocator&) { // TODO: Handling of over and underflow - if(state.size()) return {nullopt, state}; + if(!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, parsing_state> read_cbor(parsing_state state, gp::allocator&) { - if(state.size()) return {nullopt, state}; + if(!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>, parsing_state> read_cbor>(parsing_state state, gp::allocator& alloc) { - if(state.size()) return {nullopt, state}; + if(!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, parsing_state> read_cbor(parsing_state state, gp::allocator& alloc) { - if(state.size()) return {nullopt, state}; + if(!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, parsing_state> read_cbor(parsing_state state, gp::allocator& alloc) { - if(state.size()) return {nullopt, state}; + if(!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 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(!state.size()) return state; auto type = cbor_type(((uint8_t)0b11100000 & (uint8_t)*state.begin()) >> 5); switch(type) { diff --git a/include/gp/system/logging_segment.hpp b/include/gp/system/logging_segment.hpp index d803d22..ca41faf 100644 --- a/include/gp/system/logging_segment.hpp +++ b/include/gp/system/logging_segment.hpp @@ -6,8 +6,6 @@ #include "gp/functional/optional.hpp" #include -#include -#include struct segment{ int16_t priority = 0; diff --git a/tests/cbor_test.cpp b/tests/cbor_test.cpp index 175ee77..abcbd34 100644 --- a/tests/cbor_test.cpp +++ b/tests/cbor_test.cpp @@ -176,29 +176,34 @@ struct cbor_test7 : public generic_cbor_test { }; auto callback_handler = [&count](gp::parsing_state state, gp::allocator& alloc) { + log_segment("state remaining", std::to_string(state.size()).c_str()); count++; switch(count-1) { case 0: { auto [value, new_state] = gp::read_cbor(state, alloc); - gp_config::assertion(value.has_value(), "could not encode value"); - gp_config::assertion(value.value() == 12, "could not encode the correct size"); + gp_config::assertion(value.has_value(), "could not decode value 0"); + log_segment("value 0", std::to_string(value.value()).c_str()); + gp_config::assertion(value.value() == 12, "could not decode the correct size"); return new_state; } case 1:{ auto [value, new_state] = gp::read_cbor(state, alloc); - gp_config::assertion(value.has_value(), "could not encode value"); - gp_config::assertion(value.value() == -98, "could not encode the correct size"); + gp_config::assertion(value.has_value(), "could not decode value 1"); + log_segment("value 1", std::to_string(value.value()).c_str()); + gp_config::assertion(value.value() == -98, "could not decode the correct size"); return new_state; } case 2:{ auto [value, new_state] = gp::read_cbor(state, alloc); - gp_config::assertion(value.has_value(), "could not encode value"); + gp_config::assertion(value.has_value(), "could not encode value 2"); + log_segment("value 2", std::to_string(value.value()).c_str()); gp_config::assertion(value.value() == 13, "could not encode the correct size"); return new_state; } case 3:{ auto [value, new_state] = gp::read_cbor(state, alloc); - gp_config::assertion(value.has_value(), "could not encode value"); + gp_config::assertion(value.has_value(), "could not encode value 3"); + log_segment("value 3", std::to_string(value.value()).c_str()); gp_config::assertion(value.value() == 98, "could not encode the correct size"); return new_state; } diff --git a/tests/logging_test.cpp b/tests/logging_test.cpp index f6bb9ce..6e5a94c 100644 --- a/tests/logging_test.cpp +++ b/tests/logging_test.cpp @@ -134,7 +134,8 @@ struct logging_test4 : public test_scaffold { for(auto i : {0, 1, 2, 3}) { auto v = logger.get_segment_by_idx(i); bool same = true; - for(size_t it = 0; it < 4; it++) { + log_segment("found", std::string(v.name.begin().data, v.name.size()).c_str()); + for(size_t it = 0; it < name[0].size(); it++) { same &= name[0][it] == v.name[it]; } gp_config::assertion(!same, "Should not contain oldest element");