summaryrefslogtreecommitdiff
path: root/modules/codec-json/c++
diff options
context:
space:
mode:
authorClaudius 'keldu' Holeksa <mail@keldu.de>2024-08-16 14:36:48 +0200
committerClaudius 'keldu' Holeksa <mail@keldu.de>2024-08-16 14:36:48 +0200
commitc94420cdfac3cf5f4631a5eb63ca33360b719db4 (patch)
treea05be752be7062a0f55f2252eb4aa45f08e2b602 /modules/codec-json/c++
parent6ec1a674b182205c142f3e8f37d4b13c6e70c04b (diff)
Didn't consider the empty array case in decoding
Diffstat (limited to 'modules/codec-json/c++')
-rw-r--r--modules/codec-json/c++/json.tmpl.hpp14
1 files changed, 10 insertions, 4 deletions
diff --git a/modules/codec-json/c++/json.tmpl.hpp b/modules/codec-json/c++/json.tmpl.hpp
index c2e5575..d17c02d 100644
--- a/modules/codec-json/c++/json.tmpl.hpp
+++ b/modules/codec-json/c++/json.tmpl.hpp
@@ -3,8 +3,6 @@
#include <charconv>
#include <sstream>
-#include <iostream>
-
namespace saw {
namespace impl {
struct json_helper {
@@ -739,7 +737,6 @@ struct json_decode<schema::Struct<schema::Member<T,Lits>...>, ToDecode> {
std::array<bool, sizeof...(T)> found_fields;
std::fill(found_fields.begin(), found_fields.end(), false);
- std::cout<<buff.read()<<" "<<(int16_t)buff.read()<<std::endl;
SAW_ASSERT(buff.read() == '{'){
return make_error<err::invalid_state>();
}
@@ -835,6 +832,7 @@ struct json_decode<schema::Array<T,D>, ToDecode> {
static error_or<void> decode_flat_level(buffer_view& buff, std::vector<data<T, encode::Native, storage::Default>>& to, std::array<std::size_t, D>& index, std::array<std::size_t, D>& dims, bool log_dim){
if constexpr (Level == D) {
json_helper::skip_whitespace(buff);
+
try {
to.push_back({});
}catch(std::exception& e){
@@ -852,9 +850,17 @@ struct json_decode<schema::Array<T,D>, ToDecode> {
if ( buff.read_composite_length() == 0 ){
return make_error<err::buffer_exhausted>();
}
+ /**
+ * Check if array is empty.
+ */
+ bool is_empty = false;
+ if(buff.read() == ']'){
+ buff.read_advance(1);
+ is_empty = true;
+ }
index[Level] = 0;
- for(;;){
+ for(;!is_empty;){
// We should have an element right now
auto eov = decode_flat_level<Level+1>(buff,to,index,dims, index[Level] == 0 && log_dim);
if(eov.is_error()){