|
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) ----— | |
| int8_t | ReadI8 () |
| 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 35 of file orcad_stream.h.
| ORCAD_STREAM::ORCAD_STREAM | ( | const void * | aData, |
| size_t | aLength ) |
Definition at line 42 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 51 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(), OrcadParseCacheV2(), 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 242 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 248 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 264 of file orcad_stream.cpp.
References Expect().
Referenced by OrcadParseCache(), OrcadParseCacheV2(), OrcadReadDisplayProp(), OrcadReadSymbolPin(), readOccurrence(), v2DisplayProp(), v2DrawnInstance(), v2PrimBody(), and v2SymbolPin().
| void ORCAD_STREAM::ExpectPreamble | ( | const wxString & | aWhat | ) |
Consume the 4 preamble bytes; throws IO_ERROR naming aWhat when absent.
Definition at line 270 of file orcad_stream.cpp.
|
inline |
Definition at line 107 of file orcad_stream.h.
References m_offset.
Referenced by BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), OrcadParseCache(), OrcadParseCacheV2(), OrcadParsePackageStream(), OrcadParsePage(), OrcadReadDevice(), OrcadReadDrawnInstance(), OrcadReadPackage(), OrcadReadPinInst(), OrcadReadPrimitive(), OrcadReadSymbolDef(), OrcadReadSymbolPin(), and v2PrimBody().
| 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 231 of file orcad_stream.cpp.
References m_data, m_offset, and m_size.
Referenced by AtPreamble(), OrcadReadDevice(), OrcadReadSymbolDef(), and v2Device().
| int ORCAD_STREAM::PeekU8 | ( | size_t | aAhead = 0 | ) | const |
– non-throwing lookahead ---------------------------------------------------—
Returns -1 when cursor + aAhead is outside the stream.
Definition at line 220 of file orcad_stream.cpp.
References m_data, m_offset, and m_size.
Referenced by OrcadParsePageV2(), OrcadReadSymbolPin(), v2Structure(), and v2SymbolPin().
| std::vector< uint8_t > ORCAD_STREAM::ReadBytes | ( | size_t | aCount | ) |
– buffers / cursor ---------------------------------------------------------—
Read exactly aCount bytes; throws IO_ERROR on overrun.
Definition at line 188 of file orcad_stream.cpp.
References m_data, m_offset, and requireBytes().
Referenced by Expect(), OrcadParseLibrary(), and v2PrimBody().
| int16_t ORCAD_STREAM::ReadI16 | ( | ) |
Definition at line 128 of file orcad_stream.cpp.
References ReadU16().
Referenced by OrcadReadDisplayProp(), OrcadReadDrawnInstance(), OrcadReadGraphicInst(), OrcadReadPinInst(), OrcadReadPlacedInstance(), OrcadReadSymbolDef(), v2DisplayProp(), v2DrawnInstance(), v2GraphicInst(), v2LibSymbolDef(), v2PinInst(), v2PlacedInstance(), v2Prefix(), v2PrimBody(), and v2SymbolDef().
| int32_t ORCAD_STREAM::ReadI32 | ( | ) |
Definition at line 146 of file orcad_stream.cpp.
References ReadU32().
Referenced by OrcadReadAlias(), OrcadReadBusEntryBody(), OrcadReadSymbolPin(), OrcadReadWire(), v2Alias(), v2PrimBody(), v2SymbolPin(), and v2Wire().
| int8_t ORCAD_STREAM::ReadI8 | ( | ) |
Definition at line 112 of file orcad_stream.cpp.
References ReadU8().
| 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 152 of file orcad_stream.cpp.
References m_data, m_offset, m_size, ReadU16(), and THROW_IO_ERRORF.
Referenced by OrcadParseCache(), OrcadParseCacheV2(), OrcadParseLibrary(), OrcadParsePackageStream(), OrcadParsePage(), OrcadParsePageV2(), OrcadParseSchematicFolderOrder(), OrcadReadAlias(), OrcadReadDevice(), OrcadReadDrawnInstance(), OrcadReadErcObject(), OrcadReadGraphicInst(), OrcadReadOccurrenceTree(), OrcadReadOccurrenceTreeV2(), OrcadReadPackage(), OrcadReadPlacedInstance(), OrcadReadSymbolDef(), OrcadReadSymbolPin(), OrcadReadT0x34Raw(), pageOrderBody(), readOccScope(), readOccurrence(), v2Alias(), v2CachePartCell(), v2Device(), v2DrawnInstance(), v2GraphicInst(), v2LibraryPartTail(), v2LibSymbolDef(), v2Package(), v2PartCell(), v2PlacedInstance(), v2PrimBody(), v2ReadOccScope(), v2ReadOccurrence(), v2SymbolDef(), and v2SymbolPin().
| uint16_t ORCAD_STREAM::ReadU16 | ( | ) |
Definition at line 118 of file orcad_stream.cpp.
References m_data, m_offset, and requireBytes().
Referenced by OrcadParseCache(), OrcadParseCacheV2(), OrcadParseLibrary(), OrcadParseOlbPackageStreamV2(), OrcadParsePackageStream(), OrcadParsePage(), OrcadParsePageSettings(), OrcadParsePageV2(), OrcadParseSchematicFolderOrder(), OrcadReadDevice(), OrcadReadDisplayProp(), OrcadReadDisplayPropList(), OrcadReadDrawnInstance(), OrcadReadOccurrenceTree(), OrcadReadOccurrenceTreeV2(), OrcadReadPackage(), OrcadReadPlacedInstance(), OrcadReadSymbolDef(), OrcadReadSymbolPin(), OrcadReadT0x35Raw(), OrcadReadWire(), pageOrderBody(), ReadI16(), ReadLzt(), readOccScope(), readOccurrence(), v2CachePartCell(), v2Device(), v2DisplayProp(), v2DisplayPropList(), v2DrawnInstance(), v2GraphicInst(), v2LibraryPartTail(), v2LibSymbolDef(), v2Package(), v2PartCell(), v2PlacedInstance(), v2Prefix(), v2PrimBody(), v2ReadOccScope(), v2ReadOccurrence(), v2SymbolDef(), v2SymbolPin(), and v2Wire().
| uint32_t ORCAD_STREAM::ReadU32 | ( | ) |
Definition at line 134 of file orcad_stream.cpp.
References m_data, m_offset, and requireBytes().
Referenced by BOOST_AUTO_TEST_CASE(), OrcadCisParseSchematicInfo(), OrcadParseCache(), OrcadParseCacheV2(), OrcadParseLibrary(), OrcadParsePage(), OrcadParsePageSettings(), OrcadParsePageV2(), OrcadReadAlias(), OrcadReadBusEntryBody(), OrcadReadDisplayProp(), OrcadReadDrawnInstance(), OrcadReadGraphicInst(), OrcadReadOccurrenceTree(), OrcadReadOccurrenceTreeV2(), OrcadReadPinInst(), OrcadReadPlacedInstance(), OrcadReadSymbolDef(), OrcadReadSymbolPin(), OrcadReadT0x34Raw(), OrcadReadT0x35Raw(), OrcadReadWire(), ReadI32(), readOccScope(), readOccurrence(), SkipOptionalPreambleBlock(), v2Alias(), v2DrawnInstance(), v2GraphicInst(), v2LibSymbolDef(), v2PinInst(), v2PlacedInstance(), v2PrimBody(), v2ReadOccScope(), v2ReadOccurrence(), v2SymbolDef(), v2SymbolPin(), and v2Wire().
| uint8_t ORCAD_STREAM::ReadU8 | ( | ) |
– scalars (little-endian, bounds-checked, throw IO_ERROR on overrun) ----—
Definition at line 105 of file orcad_stream.cpp.
References m_data, m_offset, and requireBytes().
Referenced by OrcadParseCache(), OrcadParseCacheV2(), OrcadReadDevice(), OrcadReadDisplayProp(), OrcadReadDrawnInstance(), OrcadReadGraphicInst(), OrcadReadOccurrenceTree(), OrcadReadPlacedInstance(), OrcadReadPrimitive(), ReadI8(), v2Device(), v2DisplayProp(), v2DrawnInstance(), v2GraphicInst(), v2PlacedInstance(), v2Prefix(), v2PrimBody(), and v2Primitive().
| std::string ORCAD_STREAM::ReadZt | ( | ) |
Consumes the NUL; throws IO_ERROR if no terminator remains.
Definition at line 171 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(), OrcadParseCacheV2(), OrcadParseLibrary(), OrcadParseOlbPackageStreamV2(), OrcadParseOlbSymbolStreamV2(), OrcadParsePackageStream(), OrcadReadOccurrenceTreeV2(), v2CheckCount(), and v2PrimBody().
|
private |
Throw IO_ERROR unless aCount bytes remain at the cursor.
Definition at line 93 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 211 of file orcad_stream.cpp.
References m_offset, m_size, and THROW_IO_ERRORF.
Referenced by OrcadParseCache(), OrcadParseLibrary(), OrcadParsePackageStream(), OrcadReadDevice(), OrcadReadDrawnInstance(), OrcadReadPackage(), OrcadReadPinInst(), 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 197 of file orcad_stream.cpp.
References m_offset, m_size, and THROW_IO_ERRORF.
Referenced by OrcadParseLibrary(), OrcadParsePage(), OrcadParsePageSettings(), OrcadParsePageV2(), OrcadParseSchematicFolderOrder(), OrcadReadBusEntryBody(), OrcadReadDevice(), OrcadReadDrawnInstance(), OrcadReadGraphicInst(), OrcadReadOccurrenceTree(), OrcadReadOccurrenceTreeV2(), OrcadReadPlacedInstance(), OrcadReadPort(), OrcadReadSymbolDef(), OrcadReadSymbolPin(), OrcadReadT0x34Raw(), OrcadReadTitleBlock(), OrcadReadWire(), pageOrderBody(), readOccScope(), SkipOptionalPreambleBlock(), v2Device(), v2DrawnInstance(), v2GraphicInst(), v2PlacedInstance(), v2PrimBody(), v2SymbolPin(), and v2Wire().
| void ORCAD_STREAM::SkipOptionalPreambleBlock | ( | ) |
Legacy primitives have no trailing preamble.
Skip one only when it is present.
Definition at line 276 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 45 of file orcad_stream.h.
Referenced by ORCAD_STREAM::NEST_GUARD::NEST_GUARD().
|
staticconstexpr |
Generic invalid offset sentinel.
Definition at line 42 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 39 of file orcad_stream.h.
Referenced by AtPreamble(), BOOST_AUTO_TEST_CASE(), and ExpectPreamble().