Browse Source

fixed some bugs with serialization

tristangurtler 3 years ago
parent
commit
733a78b550
2 changed files with 11 additions and 4 deletions
  1. 2 0
      bgn2/inc/print_helpers.hpp
  2. 9 4
      bgn2/src/print_helpers.cpp

+ 2 - 0
bgn2/inc/print_helpers.hpp

@@ -4,7 +4,9 @@
 #include <iomanip>
 #include <istream>
 #include <ostream>
+#include <iostream>
 #include <cstring>
+#include <string>
 
 extern "C" {
 #include "fp12e.h"

+ 9 - 4
bgn2/src/print_helpers.cpp

@@ -116,15 +116,20 @@ std::ostream& hex_double(std::ostream& os, double d)
 {
     uint64_t u;
     memcpy(&u, &d, sizeof(d));
-    os << std::hex << std::setw(16) << u << std::setw(0) << std::dec;
+    os << std::hex << std::setw(16) << std::setfill('0');
+    os << u;
+    os << std::setfill(' ') << std::setw(0) << std::dec;
 
     return os;
 }
 
 std::istream& hex_double(std::istream& is, double& d)
-{
-    uint64_t u;
-    is >> std::hex >> u >> std::dec;
+{ 
+    char buffer[17];
+    is.get(buffer, 17);
+
+    uint64_t u = std::stoull(buffer, 0, 16);
+
     memcpy(&d, &u, sizeof(u));
 
     return is;