Copy bytes to a double. See "include/loader/filemgr.h".
| 246 | |
| 247 | // Copy bytes to a double. See "include/loader/filemgr.h". |
| 248 | Expect<double> FileMgr::readF64() { |
| 249 | if (Status != ErrCode::Value::Success) { |
| 250 | return Unexpect(Status); |
| 251 | } |
| 252 | // Set the flag to the start offset. |
| 253 | LastPos = Pos; |
| 254 | |
| 255 | uint64_t Buf = 0; |
| 256 | Byte Byte = 0x00; |
| 257 | // Check whether reading exceeds the data or section boundary. |
| 258 | EXPECTED_TRY(testRead(8)); |
| 259 | for (uint32_t I = 0; I < 8; I++) { |
| 260 | Byte = Data[Pos++]; |
| 261 | Buf |= (Byte & UINT64_C(0xFF)) << (I * UINT64_C(8)); |
| 262 | } |
| 263 | double Result; |
| 264 | static_assert(sizeof(Buf) == sizeof(Result)); |
| 265 | std::memcpy(&Result, &Buf, sizeof(Result)); |
| 266 | return Result; |
| 267 | } |
| 268 | |
| 269 | // Read a vector of bytes. See "include/loader/filemgr.h". |
| 270 | Expect<std::string> FileMgr::readName() { |