classBytePlanEncoder
final class BytePlanEncoder
Records the decisions of one guided plan construction as the bytes BytePlanCompiler decodes to the same plan.
Methods§
public function encode(
PlanBuilder $builder,
GenerationPlan<bool>|null $constraints,
int $budget,
Closure(int, non-empty-list<Production>): int $productionChoice,
Closure(int): ?int|null $lexicalChoice = null,
): stringRuns the builder once with the caller's choices and writes the header, production and lexical bytes the compiler reads. Lexical choices end at the first null answer; the compiler makes the remaining ones from the padding bytes. The constraints must be ones the compiler accepts.
Parameters
$builder | PlanBuilder | |
$constraints | GenerationPlan<bool>|null | |
$budget | int | |
$productionChoice | Closure(int, non-empty-list<Production>): int | Selects one candidate at every expansion |
$lexicalChoice | Closure(int): ?int|null | Selects lexical candidates until it answers null |
Returns
stringThrows
InvalidArgumentException When the budget lies outside the range the compiler decodes for these constraintsTest cases 4
BytePlanEncoderTest::testEncodeMakesOpenLexicalChoicesTheWayTheCompilerReadsThePaddingcallsBytePlanEncoderTest::testEncodeStopsRecordingLexicalChoicesAtTheFirstNullAnswercallsBytePlanEncoderTest::testEncodeWritesBytesTheCompilerDecodesToTheRecordedChoicescallsBytePlanEncoderTest::testEncodeWritesTheHeaderRelativeToTheConstraintsMinimumAndDefaultMaximumcalls
Calls 8
- static-call GenerationPlan::all() line 29
- method-call PlanBuilder::minimumExpansions() line 30
- class-const BytePlanCompiler::MAXIMUM_BUDGET() line 31
- new
InvalidArgumentExceptionline 33 - method-call PlanBuilder::build() line 38
- static-call ByteChoices::encode() line 43
- function-call
packline 56 - static-call BytePlanEncoder::interleave() line 56
public static function interleave(string $structure, string $lexical): stringPairs production bytes with lexical bytes the way the compiler splits them, padding the shorter stream with zero.
Parameters
$structure | string | |
$lexical | string |
Returns
stringTest cases 1
Called from 1
Test cases 5§
Test cases that cover or call this symbol, from the coverage report and from the analyzed test sources.
Dedicated tests 5
BytePlanEncoderTest::testEncodeMakesOpenLexicalChoicesTheWayTheCompilerReadsThePaddingcallsBytePlanEncoderTest::testEncodeStopsRecordingLexicalChoicesAtTheFirstNullAnswercallsBytePlanEncoderTest::testEncodeWritesBytesTheCompilerDecodesToTheRecordedChoicescallsBytePlanEncoderTest::testEncodeWritesTheHeaderRelativeToTheConstraintsMinimumAndDefaultMaximumcallsBytePlanEncoderTest::testInterleavePairsProductionBytesWithLexicalBytesAndPadsTheShorterStreamcalls