summaryrefslogtreecommitdiff
path: root/modules/codec-json/c++/json.tmpl.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'modules/codec-json/c++/json.tmpl.hpp')
-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()){