From f40fe73cbd8f61be11721babb1e3615326466041 Mon Sep 17 00:00:00 2001 From: "Claudius \"keldu\" Holeksa" Date: Thu, 9 Nov 2023 17:02:40 +0100 Subject: codec-netcdf: Changed to memory parsing --- c++/codec-netcdf/netcdf.h | 22 ++++++++++++---------- tests/codec-netcdf.cpp | 33 +++++++++++++++++++++++++++++++-- tests/data/array.nc | Bin 156 -> 0 bytes tests/data/primitive.nc | Bin 112 -> 0 bytes 4 files changed, 43 insertions(+), 12 deletions(-) delete mode 100644 tests/data/array.nc delete mode 100644 tests/data/primitive.nc diff --git a/c++/codec-netcdf/netcdf.h b/c++/codec-netcdf/netcdf.h index c99217e..72e7614 100644 --- a/c++/codec-netcdf/netcdf.h +++ b/c++/codec-netcdf/netcdf.h @@ -5,6 +5,7 @@ #include #include +#include namespace saw { namespace encode { @@ -20,22 +21,23 @@ struct Netcdf {}; template class data { private: - std::string path_; + std::vector buff_; public: - data(const std::string& path): - path_{path} + data(std::vector buff): + buff_{std::move(buff)} {} - data(std::string&& path): - path_{std::move(path)} + template + data(const std::array& arr): + buff_{arr.begin(), arr.end()} {} - std::string_view get_path_view() { - return path_; + std::vector& get_data() { + return buff_; } - const std::string& get_path() const { - return path_; + const std::vector& get_data() const { + return buff_; } }; @@ -77,7 +79,7 @@ public: int ncid{}; int rc{}; - rc = nc_open(from_decode.get_path().c_str(), NC_NOWRITE, &ncid); + rc = nc_open_mem("forstio_internal_memory", NC_NOWRITE, from_decode.get_data().size(), &from_decode.get_data()[0], &ncid); if(rc != NC_NOERR){ // Don't know how to get the error, so fail critically. return make_error(); diff --git a/tests/codec-netcdf.cpp b/tests/codec-netcdf.cpp index 72fc5ea..11e53c3 100644 --- a/tests/codec-netcdf.cpp +++ b/tests/codec-netcdf.cpp @@ -14,10 +14,39 @@ using TestArrayStruct = Struct< >; } +std::array tests_data_primitive_nc = { + 0x43, 0x44, 0x46, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x0b, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x04, + 0x64, 0x61, 0x74, 0x61, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x04, + 0x00, 0x00, 0x00, 0x64, 0x00, 0x00, 0x00, 0x05, 0x6f, 0x74, 0x68, 0x65, + 0x72, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x08, + 0x00, 0x00, 0x00, 0x68, 0x00, 0x00, 0x00, 0x05, 0x40, 0x40, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00 +}; + +std::array tests_data_array_nc = { + 0x43, 0x44, 0x46, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0a, + 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x01, 0x78, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x01, 0x79, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x0b, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x04, + 0x64, 0x61, 0x74, 0x61, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x3c, 0x00, 0x00, 0x00, 0x60, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x02, + 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x05, + 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x08, + 0x00, 0x00, 0x00, 0x09, 0x00, 0x00, 0x00, 0x0a, 0x00, 0x00, 0x00, 0x0b, + 0x00, 0x00, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x0d, 0x00, 0x00, 0x00, 0x0e +}; + SAW_TEST("NetCDF Struct Primitive read"){ using namespace saw; - data netcdf{"./data/primitive.nc"}; + data netcdf{tests_data_primitive_nc}; data native; @@ -32,7 +61,7 @@ SAW_TEST("NetCDF Struct Primitive read"){ SAW_TEST("NetCDF Struct Array read"){ using namespace saw; - data netcdf{"./data/array.nc"}; + data netcdf{tests_data_array_nc}; data native; diff --git a/tests/data/array.nc b/tests/data/array.nc deleted file mode 100644 index 2155846..0000000 Binary files a/tests/data/array.nc and /dev/null differ diff --git a/tests/data/primitive.nc b/tests/data/primitive.nc deleted file mode 100644 index ab49e3b..0000000 Binary files a/tests/data/primitive.nc and /dev/null differ -- cgit v1.2.3