|
KiCad PCB EDA Suite
|
The caller owns the buffer. More...
#include <orcad_stream.h>
Classes | |
| class | LIMIT_GUARD |
| Limit reads to one record so a malformed body cannot consume the next record. More... | |
| class | NEST_GUARD |
| Bound shared parser recursion; entering a level above MAX_NESTING throws IO_ERROR. More... | |
Public Member Functions | |
| ORCAD_STREAM (const void *aData, size_t aLength) | |
| ORCAD_STREAM (const std::vector< char > &aData) | |
| uint8_t | ReadU8 () |
| – scalars (little-endian, bounds-checked, throw IO_ERROR on overrun) ----— | |
| uint16_t | ReadU16 () |
| int16_t | ReadI16 () |
| uint32_t | ReadU32 () |
| int32_t | ReadI32 () |
| std::string | ReadLzt () |
| – strings ----------------------------------------------------------------— | |
| std::string | ReadZt () |
| Consumes the NUL; throws IO_ERROR if no terminator remains. | |
| std::vector< uint8_t > | ReadBytes (size_t aCount) |
| – buffers / cursor ---------------------------------------------------------— | |
| void | Skip (size_t aCount) |
| Advance the cursor; throws IO_ERROR when aCount exceeds the remaining bytes. | |
| void | Seek (size_t aOffset) |
| Set the absolute cursor position; throws IO_ERROR when aOffset exceeds Size(). | |
| size_t | GetOffset () const |
| size_t | Size () const |
| size_t | Remaining () const |
| Bytes left; 0 when the cursor is at or past the end. | |
| bool | AtEnd () const |
| const uint8_t * | Data () const |
| Raw buffer access for bounded lexical lookahead and payload extraction. | |
| int | PeekU8 (size_t aAhead=0) const |
| – non-throwing lookahead ---------------------------------------------------— | |
| bool | PeekMatches (const uint8_t *aBytes, size_t aCount, size_t aAhead=0) const |
| Returns false if fewer than aCount bytes remain; does not advance the cursor. | |
| bool | AtPreamble (size_t aAhead=0) const |
| True when the 4 preamble bytes FF E4 5C 39 sit at cursor + aAhead. | |
| void | Expect (const uint8_t *aBytes, size_t aCount, const wxString &aWhat) |
| – validated reads ------------------------------------------------------------— | |
| void | ExpectByte (uint8_t aValue, const wxString &aWhat) |
| Consume one byte and require the given value. | |
| void | ExpectPreamble (const wxString &aWhat) |
| Consume the 4 preamble bytes; throws IO_ERROR naming aWhat when absent. | |
| void | SkipOptionalPreambleBlock () |
| Legacy primitives have no trailing preamble. | |
Static Public Attributes | |
| static constexpr uint8_t | PREAMBLE [4] = { 0xFF, 0xE4, 0x5C, 0x39 } |
| Magic preceding every framed structure body: FF E4 5C 39. | |
| static constexpr size_t | npos = static_cast<size_t>( -1 ) |
| Generic invalid offset sentinel. | |
| static constexpr int | MAX_NESTING = 64 |
| Nesting limit of the recursive readers; real files stay far below it. | |
Private Member Functions | |
| void | requireBytes (size_t aCount) const |
| Throw IO_ERROR unless aCount bytes remain at the cursor. | |
Private Attributes | |
| const uint8_t * | m_data |
| size_t | m_size |
| size_t | m_offset |
| int | m_nesting |
The caller owns the buffer.
Reads and cursor moves throw IO_ERROR on overrun. Strings retain raw Windows-1252 bytes until conversion with FromOrcadString.
Definition at line 36 of file orcad_stream.h.
| ORCAD_STREAM::ORCAD_STREAM | ( | const void * | aData, |
| size_t | aLength ) |
Definition at line 43 of file orcad_stream.cpp.
References m_data, m_nesting, m_offset, and m_size.
Referenced by ORCAD_STREAM::LIMIT_GUARD::LIMIT_GUARD(), ORCAD_STREAM::NEST_GUARD::NEST_GUARD(), and ORCAD_STREAM().
|
explicit |
Definition at line 52 of file orcad_stream.cpp.
References ORCAD_STREAM().
|
inline |
Definition at line 113 of file orcad_stream.h.
References m_offset, and m_size.
Referenced by OrcadCisParseSchematicInfo(), OrcadParseCache(), OrcadParseSchematicFolderOrder(), and OrcadParseSymbolStream().
| bool ORCAD_STREAM::AtPreamble | ( | size_t | aAhead = 0 | ) | const |
True when the 4 preamble bytes FF E4 5C 39 sit at cursor + aAhead.
Definition at line 237 of file orcad_stream.cpp.
References PeekMatches(), and PREAMBLE.
Referenced by readOccScope(), and SkipOptionalPreambleBlock().
|
inline |
Raw buffer access for bounded lexical lookahead and payload extraction.
Definition at line 116 of file orcad_stream.h.
References m_data.
| void ORCAD_STREAM::Expect | ( | const uint8_t * | aBytes, |
| size_t | aCount, | ||
| const wxString & | aWhat ) |
– validated reads ------------------------------------------------------------—
Consumes the bytes before checking them. A mismatch throws IO_ERROR with expected and actual bytes.
Definition at line 243 of file orcad_stream.cpp.
References hexOf(), m_offset, ReadBytes(), and THROW_IO_ERRORF.
Referenced by ExpectByte(), and ExpectPreamble().
| void ORCAD_STREAM::ExpectByte | ( | uint8_t | aValue, |
| const wxString & | aWhat ) |
Consume one byte and require the given value.
Definition at line 259 of file orcad_stream.cpp.
References Expect().
Referenced by OrcadParseCache(), OrcadReadDisplayProp(), OrcadReadSymbolPin(), and readOccurrence().
| void ORCAD_STREAM::ExpectPreamble | ( | const wxString & | aWhat | ) |
Consume the 4 preamble bytes; throws IO_ERROR naming aWhat when absent.
Definition at line 265 of file orcad_stream.cpp.
|
inline |
Definition at line 107 of file orcad_stream.h.
References m_offset.
Referenced by OrcadParseCache(), OrcadParsePackageStream(), OrcadParsePage(), OrcadReadDevice(), OrcadReadDrawnInstance(), OrcadReadPackage(), OrcadReadPrimitive(), OrcadReadSymbolDef(), and OrcadReadSymbolPin().
| bool ORCAD_STREAM::PeekMatches | ( | const uint8_t * | aBytes, |
| size_t | aCount, | ||
| size_t | aAhead = 0 ) const |
Returns false if fewer than aCount bytes remain; does not advance the cursor.
Definition at line 226 of file orcad_stream.cpp.
References m_data, m_offset, and m_size.
Referenced by AtPreamble(), OrcadReadDevice(), and OrcadReadSymbolDef().
| int ORCAD_STREAM::PeekU8 | ( | size_t | aAhead = 0 | ) | const |
– non-throwing lookahead ---------------------------------------------------—
Returns -1 when cursor + aAhead is outside the stream.
Definition at line 215 of file orcad_stream.cpp.
References m_data, m_offset, and m_size.
Referenced by OrcadReadSymbolPin().
| std::vector< uint8_t > ORCAD_STREAM::ReadBytes | ( | size_t | aCount | ) |
– buffers / cursor ---------------------------------------------------------—
Read exactly aCount bytes; throws IO_ERROR on overrun.
Definition at line 183 of file orcad_stream.cpp.
References m_data, m_offset, and requireBytes().
Referenced by Expect(), and OrcadParseLibrary().
| int16_t ORCAD_STREAM::ReadI16 | ( | ) |
Definition at line 123 of file orcad_stream.cpp.
References ReadU16().
Referenced by OrcadReadDisplayProp(), OrcadReadDrawnInstance(), OrcadReadGraphicInst(), OrcadReadPinInst(), OrcadReadPlacedInstance(), and OrcadReadSymbolDef().
| int32_t ORCAD_STREAM::ReadI32 | ( | ) |
Definition at line 141 of file orcad_stream.cpp.
References ReadU32().
Referenced by OrcadParseLibrary(), OrcadReadAlias(), OrcadReadBusEntryBody(), OrcadReadSymbolPin(), and OrcadReadWire().
| std::string ORCAD_STREAM::ReadLzt | ( | ) |
– strings ----------------------------------------------------------------—
Reads u16 length, raw CP-1252 bytes, and a required NUL. Invalid data throws IO_ERROR.
Definition at line 147 of file orcad_stream.cpp.
References m_data, m_offset, m_size, ReadU16(), and THROW_IO_ERRORF.
Referenced by OrcadParseCache(), OrcadParseLibrary(), OrcadParsePackageStream(), OrcadParsePage(), OrcadParseSchematicFolderOrder(), OrcadReadAlias(), OrcadReadDevice(), OrcadReadDrawnInstance(), OrcadReadGraphicInst(), OrcadReadPackage(), OrcadReadPlacedInstance(), OrcadReadSymbolDef(), OrcadReadSymbolPin(), OrcadReadT0x34Raw(), pageOrderBody(), readLegacyLibraryPartTail(), readOccScope(), readOccTree(), readOccurrence(), and storeLegacyCacheRecord().
| uint16_t ORCAD_STREAM::ReadU16 | ( | ) |
Definition at line 113 of file orcad_stream.cpp.
References m_data, m_offset, and requireBytes().
Referenced by OrcadParseCache(), OrcadParseLibrary(), OrcadParsePage(), OrcadParsePageSettings(), OrcadParseSchematicFolderOrder(), OrcadReadDisplayProp(), OrcadReadPlacedInstance(), OrcadReadSymbolDef(), OrcadReadSymbolPin(), OrcadReadT0x35Raw(), OrcadReadWire(), pageOrderBody(), ReadI16(), readLegacyLibraryPartTail(), ReadLzt(), and readOccurrence().
| uint32_t ORCAD_STREAM::ReadU32 | ( | ) |
Definition at line 129 of file orcad_stream.cpp.
References m_data, m_offset, and requireBytes().
Referenced by OrcadCisParseSchematicInfo(), OrcadParseCache(), OrcadParseLibrary(), OrcadParsePage(), OrcadParsePageSettings(), OrcadReadAlias(), OrcadReadBusEntryBody(), OrcadReadDrawnInstance(), OrcadReadGraphicInst(), OrcadReadOccurrenceTree(), OrcadReadPinInst(), OrcadReadPlacedInstance(), OrcadReadSymbolDef(), OrcadReadSymbolPin(), OrcadReadT0x34Raw(), OrcadReadT0x35Raw(), OrcadReadWire(), ReadI32(), readOccScope(), readOccTree(), readOccurrence(), and SkipOptionalPreambleBlock().
| uint8_t ORCAD_STREAM::ReadU8 | ( | ) |
– scalars (little-endian, bounds-checked, throw IO_ERROR on overrun) ----—
Definition at line 106 of file orcad_stream.cpp.
References m_data, m_offset, and requireBytes().
Referenced by OrcadParseCache(), OrcadParseLibrary(), OrcadReadDevice(), OrcadReadDisplayProp(), OrcadReadDrawnInstance(), OrcadReadGraphicInst(), OrcadReadOccurrenceTree(), OrcadReadPlacedInstance(), and OrcadReadPrimitive().
| std::string ORCAD_STREAM::ReadZt | ( | ) |
Consumes the NUL; throws IO_ERROR if no terminator remains.
Definition at line 166 of file orcad_stream.cpp.
References end, m_data, m_offset, m_size, and THROW_IO_ERRORF.
Referenced by OrcadParseLibrary().
|
inline |
Bytes left; 0 when the cursor is at or past the end.
Definition at line 111 of file orcad_stream.h.
References m_offset, and m_size.
Referenced by OrcadParseCache(), OrcadParseLibrary(), OrcadParsePackageStream(), OrcadParseSymbolStream(), and OrcadReadOccurrenceTree().
|
private |
Throw IO_ERROR unless aCount bytes remain at the cursor.
Definition at line 94 of file orcad_stream.cpp.
References m_offset, m_size, and THROW_IO_ERRORF.
Referenced by ReadBytes(), ReadU16(), ReadU32(), and ReadU8().
| void ORCAD_STREAM::Seek | ( | size_t | aOffset | ) |
Set the absolute cursor position; throws IO_ERROR when aOffset exceeds Size().
Definition at line 206 of file orcad_stream.cpp.
References m_offset, m_size, and THROW_IO_ERRORF.
Referenced by OrcadParseCache(), OrcadParseLibrary(), OrcadParsePackageStream(), OrcadReadDevice(), OrcadReadDrawnInstance(), OrcadReadPackage(), OrcadReadSymbolDef(), and OrcadReadSymbolPin().
|
inline |
| void ORCAD_STREAM::Skip | ( | size_t | aCount | ) |
Advance the cursor; throws IO_ERROR when aCount exceeds the remaining bytes.
Definition at line 192 of file orcad_stream.cpp.
References m_offset, m_size, and THROW_IO_ERRORF.
Referenced by OrcadParseLibrary(), OrcadParsePage(), OrcadParsePageSettings(), OrcadParseSchematicFolderOrder(), OrcadReadBusEntryBody(), OrcadReadDevice(), OrcadReadDrawnInstance(), OrcadReadGraphicInst(), OrcadReadPlacedInstance(), OrcadReadSymbolDef(), OrcadReadSymbolPin(), OrcadReadT0x34Raw(), OrcadReadWire(), pageOrderBody(), readOccScope(), readOccTree(), and SkipOptionalPreambleBlock().
| void ORCAD_STREAM::SkipOptionalPreambleBlock | ( | ) |
Legacy primitives have no trailing preamble.
Skip one only when it is present.
Definition at line 271 of file orcad_stream.cpp.
References AtPreamble(), ReadU32(), and Skip().
|
private |
Definition at line 147 of file orcad_stream.h.
Referenced by Data(), ORCAD_STREAM(), PeekMatches(), PeekU8(), ReadBytes(), ReadLzt(), ReadU16(), ReadU32(), ReadU8(), and ReadZt().
|
private |
Definition at line 150 of file orcad_stream.h.
Referenced by ORCAD_STREAM().
|
private |
Definition at line 149 of file orcad_stream.h.
Referenced by AtEnd(), Expect(), GetOffset(), ORCAD_STREAM::LIMIT_GUARD::LIMIT_GUARD(), ORCAD_STREAM(), PeekMatches(), PeekU8(), ReadBytes(), ReadLzt(), ReadU16(), ReadU32(), ReadU8(), ReadZt(), Remaining(), requireBytes(), Seek(), and Skip().
|
private |
Definition at line 148 of file orcad_stream.h.
Referenced by AtEnd(), ORCAD_STREAM::LIMIT_GUARD::LIMIT_GUARD(), ORCAD_STREAM(), PeekMatches(), PeekU8(), ReadLzt(), ReadZt(), Remaining(), requireBytes(), Seek(), Size(), and Skip().
|
staticconstexpr |
Nesting limit of the recursive readers; real files stay far below it.
Definition at line 46 of file orcad_stream.h.
Referenced by ORCAD_STREAM::NEST_GUARD::NEST_GUARD().
|
staticconstexpr |
Generic invalid offset sentinel.
Definition at line 43 of file orcad_stream.h.
Referenced by readOccHeader(), and ORCAD_STRUCT_READER::ReadPrefixes().
|
staticconstexpr |
Magic preceding every framed structure body: FF E4 5C 39.
Definition at line 40 of file orcad_stream.h.
Referenced by AtPreamble(), and ExpectPreamble().