classTableCodec
final class TableCodec
Restricted visibility: declared "@visibility root". Code outside that scope must not name this declaration.
Writes a parse table to bytes and reads it back.
The layout is little-endian throughout: a header of counts, the symbol names, the rules, the default of each state, the fallbacks, the byte offset of each row, and then the rows themselves. A row lists its symbols as 16-bit numbers and then its action codes as 32-bit integers, so a row can be unpacked with two calls.
Constants§
public const MAGIC = 'SQLPTBL1'The bytes every encoded table starts with.
Methods§
public function encode(ParseTable $table): stringEncodes a table.
Parameters
$table | ParseTable | Table to write |
Returns
string The bytesTest cases 2
Called from 1
Calls 6
- function-call
packline 41 - function-call
strlenline 41 - method-call ParseTable::stateCount() line 53
- method-call TableCodec::encodeRow() line 54
- class-const TableCodec::MAGIC() line 58
- function-call
countline 59
public static function integers(string $format, string $bytes): list<int>Unpacks a run of integers.
Parameters
$format | string | Pack format of one repeated integer, such as `v*` |
$bytes | string | The bytes |
Returns
list<int> The integers, none for empty bytesThrows
RuntimeException When the bytes are not a whole number of integersTest cases 2
Called from 4
- static-call SqlParser\Table\PackedRows::row() packages/sql-parser/src/Table/PackedRows.php:51
- static-call SqlParser\Table\PackedRows::row() packages/sql-parser/src/Table/PackedRows.php:52
- static-call SqlParser\Table\TableCodec::decode() packages/sql-parser/src/Table/TableCodec.php:143
- static-call SqlParser\Table\TableCodec::decode() packages/sql-parser/src/Table/TableCodec.php:152
public function encodeRow(array<int, int> $row): stringEncodes the explicit actions of one state.
Parameters
$row | array<int, int> | Action code by symbol number |
Returns
string The bytesTest cases 2
Called from 1
public function decode(string $bytes): ParseTableDecodes a table.
Parameters
$bytes | string | Bytes as encode() wrote them |
Returns
ParseTable The table, with its rows decoded on demandThrows
RuntimeException When the bytes are not an encoded tableTest cases 3
Called from 1
Calls 12
- function-call
str_starts_withline 122 - class-const TableCodec::MAGIC() line 122
- new
RuntimeExceptionline 123 - function-call
strlenline 125 - function-call
unpackline 127 - function-call
substrline 133 - new TableRule line 140
- static-call TableCodec::integers() line 143
- new ParseTable line 155
- new SymbolTable line 156
- function-call
array_sliceline 156 - new PackedRows line 159
Test cases 12§
Test cases that cover or call this symbol, from the coverage report and from the analyzed test sources.
Dedicated tests 6
Other tests reaching this symbol 6
MySqlParserTestcallsPostgreSqlParserTestcallsResourceWriterTestcallsSqliteParserTestcallsPackedRowsTest::testRowcallsTableFileTestcalls