|
Orrery
A GPU-accelerated N-body gravitational simulator
|
Reads what BinaryWriter writes. More...
#include <orrery/sim/binary_stream.hpp>
Public Member Functions | |
| BinaryReader (std::istream &in) noexcept | |
| std::uint8_t | read_u8 () |
| std::uint32_t | read_u32 () |
| std::uint64_t | read_u64 () |
| core::Real | read_real () |
| void | read_reals (std::span< core::Real > values) |
| Fill values with that many consecutive Real. | |
| std::string | read_bytes (std::size_t length) |
| Read exactly length bytes. | |
| std::string | read_string (std::size_t limit) |
| Read a 32-bit length followed by that many bytes. | |
| std::uint64_t | checksum () const noexcept |
| The checksum of everything read so far, comparable against the one the writer recorded. | |
| bool | ok () const noexcept |
| Whether every read so far found the bytes it wanted. | |
Reads what BinaryWriter writes.
Every read of a stream that has already failed returns zero rather than blocking or throwing, and ok() stays false once it has been false. That lets a format reader parse a whole header without checking after each field and then decide what to do once, which is both easier to read and the only way the error message can name the file rather than the field.
|
nodiscard |
Read a 32-bit length followed by that many bytes.
The length is checked against limit before the allocation is made. Without that, a corrupt file claiming a four-billion-byte string would have this function ask for four gigabytes before discovering the file is eighty bytes long, and a reader that can be made to exhaust memory by a malformed input is a reader that cannot be pointed at an untrusted file.