API Reference — dna/StreamReader
class StreamReader : public Reader
Abstract base for DNA stream readers — defines the read() contract and error status codes shared by all concrete reader implementations.
When to use this
Inherit from StreamReader (via BinaryStreamReader or JSONStreamReader) when you need to load DNA data from an I/O stream. Use the static status codes — SignatureMismatchError, VersionMismatchError, InvalidDataError — to interpret failure results after calling read() without needing to know which concrete subclass is in use.
Example
// Obtain a concrete reader via BinaryStreamReader::create()
dna::BinaryStreamReader* reader = dna::BinaryStreamReader::create(stream);
reader->read();
// Check the status context after read()
if (sc::Status::currentCode() == dna::StreamReader::SignatureMismatchError) {
// The stream does not contain a valid DNA file
}
if (sc::Status::currentCode() == dna::StreamReader::VersionMismatchError) {
// The DNA version is not supported by this reader build
}
dna::BinaryStreamReader::destroy(reader);
Raises
SignatureMismatchError— Set on the status context when the stream does not begin with the expected DNA file signature. Verify that the stream points to a valid DNA file and that the stream position is at the start.VersionMismatchError— Set when the DNA file version is incompatible with this reader. Check that the DNA file was produced by a compatible toolchain version.InvalidDataError— Set when the stream contains structurally malformed data. Inspect the source asset for corruption or truncation.
Watch out for
StreamReadercannot be instantiated directly — use a concrete subclass (BinaryStreamReader,JSONStreamReader). There is no factory onStreamReaderitself.- The three static
sc::StatusCodemembers are error sentinels for the status-context pattern, not C++ exceptions. After callingread(), checksc::Status::currentCode()rather than wrapping in a try/catch.