niobium/fhetch_reader.h
Include: #include "niobium/fhetch_reader.h"
Declarations
struct niobium::fhetch::ReadDiagnostic
struct niobium::fhetch::ReadDiagnosticOne thing the reader has to say about a line.
Fields
| Name | Declaration | Description |
|---|---|---|
line_number | int line_number = 0 | |
message | std::string message |
struct niobium::fhetch::ReadResult
struct niobium::fhetch::ReadResultOutcome of a read. ok is false only when something was wrong in a way that would have silently changed the program — a malformed modulus table, or an operand that does not fit. Unknown opcodes and unparseable lines are warnings: they are skipped, and the caller decides whether that matters.
Fields
| Name | Declaration | Description |
|---|---|---|
ok | bool ok = false | |
program | Program program | |
errors | std::vector<ReadDiagnostic> errors | |
warnings | std::vector<ReadDiagnostic> warnings |
first_error
std::string first_error() constFirst error's message, or empty. For callers that just want to log something and give up.
niobium::fhetch::read_fhetch_text
ReadResult read_fhetch_text(std::string_view text)Parse a .fhetch trace from memory.
m=<N> is ambiguous in the text — a writer renders both a modulus-table index and a literal prime the same way, because the text form has no way to distinguish them. It is resolved by magnitude: N is an index when it is less than the modulus table's size, and a literal prime otherwise. That is sound rather than a guess, since chain moduli are 50-60 bit primes and a table has tens of entries, so the ranges cannot overlap. With no table present, every modulus is a literal. Instruction::modulus_is_literal records which reading applied, so a consumer never has to repeat it.
niobium::fhetch::read_fhetch_binary
ReadResult read_fhetch_binary(const std::byte *bytes, size_t size)Decode a .fhex byte stream into the same Program a text trace gives.
The binary form is unambiguous where the text is not — its records flag a literal modulus, and it carries omega/mask/logn — so nothing has to be inferred here.
niobium::fhetch::read_fhetch_file
ReadResult read_fhetch_file(const std::filesystem::path &path)Read a program from a file, in whichever serialization it holds.
The form is detected from the file's own magic bytes rather than its name, so a .fhetch that happens to contain binary still reads. A file that cannot be opened is an error, not a warning.
Something not looking right? Suggest a change on GitHub.