diff --git a/src/dml/types/DblField.cpp b/src/dml/types/DblField.cpp index 7eaf895..9d1c2e8 100644 --- a/src/dml/types/DblField.cpp +++ b/src/dml/types/DblField.cpp @@ -1,4 +1,5 @@ #include "ki/dml/Field.h" +#include "ki/util/ValueBytes.h" namespace ki { @@ -7,19 +8,28 @@ namespace dml template <> void DblField::write_to(std::ostream &ostream) const { - + const ValueBytes endianness_check = { 0x0102 }; + ValueBytes data = { m_value }; + if (endianness_check.buff[0] == 0x01) + std::reverse(&data.buff[0], &data.buff[7]); + ostream.write(data.buff, sizeof(DBL)); } template <> void DblField::read_from(std::istream &istream) { - + const ValueBytes endianness_check = { 0x0102 }; + ValueBytes data; + istream.read(data.buff, sizeof(DBL)); + if (endianness_check.buff[0] == 0x01) + std::reverse(&data.buff[0], &data.buff[3]); + m_value = data.value; } template <> size_t DblField::get_size() const { - return 0; + return sizeof(DBL); } } -} \ No newline at end of file +} diff --git a/src/dml/types/FltField.cpp b/src/dml/types/FltField.cpp index 13a1e46..bfa3fd6 100644 --- a/src/dml/types/FltField.cpp +++ b/src/dml/types/FltField.cpp @@ -1,4 +1,5 @@ #include "ki/dml/Field.h" +#include "ki/util/ValueBytes.h" namespace ki { @@ -7,19 +8,28 @@ namespace dml template <> void FltField::write_to(std::ostream &ostream) const { - + const ValueBytes endianness_check = { 0x0102 }; + ValueBytes data = { m_value }; + if (endianness_check.buff[0] == 0x01) + std::reverse(&data.buff[0], &data.buff[3]); + ostream.write(data.buff, sizeof(FLT)); } template <> void FltField::read_from(std::istream &istream) { - + const ValueBytes endianness_check = { 0x0102 }; + ValueBytes data; + istream.read(data.buff, sizeof(FLT)); + if (endianness_check.buff[0] == 0x01) + std::reverse(&data.buff[0], &data.buff[3]); + m_value = data.value; } template <> size_t FltField::get_size() const { - return 0; + return sizeof(FLT); } } -} \ No newline at end of file +} diff --git a/test/src/unit-dml.cpp b/test/src/unit-dml.cpp index de77e31..7c5fc5d 100644 --- a/test/src/unit-dml.cpp +++ b/test/src/unit-dml.cpp @@ -135,7 +135,7 @@ TEST_CASE("Field Serialization", "[dml]") { record->add_field("TestDbl")->set_value(152.4); record->write_to(ss); - REQUIRE(ss.str() == "\xCD\xCC\xCC\xCC\xCC\x0C\x64\x40"); + REQUIRE(ss.str() == "\xCD\xCC\xCC\xCC\xCC\x0C\x63\x40"); } SECTION("GID Fields") @@ -245,7 +245,7 @@ TEST_CASE("Field Deserialization", "[dml]") SECTION("DBL Fields") { - ss.write("\xCD\xCC\xCC\xCC\xCC\x0C\x64\x40", 8); + ss.write("\xCD\xCC\xCC\xCC\xCC\x0C\x63\x40", 8); ss.seekg(std::stringstream::beg); auto *field = record->add_field("TestDbl");