diff options
author | Claudius "keldu" Holeksa <mail@keldu.de> | 2023-11-09 17:02:40 +0100 |
---|---|---|
committer | Claudius "keldu" Holeksa <mail@keldu.de> | 2023-11-09 17:02:40 +0100 |
commit | f40fe73cbd8f61be11721babb1e3615326466041 (patch) | |
tree | 7fdbc7a66c52215a35081dbbbcb5955916dc5593 | |
parent | d206499057ceaf6927be4fbc3f54e25dacd83034 (diff) |
codec-netcdf: Changed to memory parsing
-rw-r--r-- | c++/codec-netcdf/netcdf.h | 22 | ||||
-rw-r--r-- | tests/codec-netcdf.cpp | 33 | ||||
-rw-r--r-- | tests/data/array.nc | bin | 156 -> 0 bytes | |||
-rw-r--r-- | tests/data/primitive.nc | bin | 112 -> 0 bytes |
4 files changed, 43 insertions, 12 deletions
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 <forstio/codec/data.h> #include <netcdf.h> +#include <netcdf_mem.h> namespace saw { namespace encode { @@ -20,22 +21,23 @@ struct Netcdf {}; template<typename Schema> class data<Schema, encode::Netcdf> { private: - std::string path_; + std::vector<uint8_t> buff_; public: - data(const std::string& path): - path_{path} + data(std::vector<uint8_t> buff): + buff_{std::move(buff)} {} - data(std::string&& path): - path_{std::move(path)} + template<size_t N> + data(const std::array<uint8_t, N>& arr): + buff_{arr.begin(), arr.end()} {} - std::string_view get_path_view() { - return path_; + std::vector<uint8_t>& get_data() { + return buff_; } - const std::string& get_path() const { - return path_; + const std::vector<uint8_t>& 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<err::critical>(); 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<uint8_t,112> 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<uint8_t,156> 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<schema::TestStruct, encode::Netcdf> netcdf{"./data/primitive.nc"}; + data<schema::TestStruct, encode::Netcdf> netcdf{tests_data_primitive_nc}; data<schema::TestStruct, encode::Native> native; @@ -32,7 +61,7 @@ SAW_TEST("NetCDF Struct Primitive read"){ SAW_TEST("NetCDF Struct Array read"){ using namespace saw; - data<schema::TestArrayStruct, encode::Netcdf> netcdf{"./data/array.nc"}; + data<schema::TestArrayStruct, encode::Netcdf> netcdf{tests_data_array_nc}; data<schema::TestArrayStruct, encode::Native> native; diff --git a/tests/data/array.nc b/tests/data/array.nc Binary files differdeleted file mode 100644 index 2155846..0000000 --- a/tests/data/array.nc +++ /dev/null diff --git a/tests/data/primitive.nc b/tests/data/primitive.nc Binary files differdeleted file mode 100644 index ab49e3b..0000000 --- a/tests/data/primitive.nc +++ /dev/null |