Skip to content

Commit 0a18fdd

Browse files
committed
Reorganize
1 parent edec99c commit 0a18fdd

10 files changed

Lines changed: 31 additions & 45 deletions

File tree

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// Root
2-
fileReferenceOrigins#8260b721 db_schema:string ctxs:Vector<Origin> = FileReferenceOrigins;
2+
fileReferenceOrigins#fe633fe7 db_schema:string db_schema_json:string ctxs:Vector<Origin> = FileReferenceOrigins;
33

44
origin#72cc7c04 flags:# predicate:string is_constructor:flags.0?true action:ActionOp needs_parent:flags.3?string parent_is_constructor:flags.4?true = origin;
55

src/TL_filerefs_db.tl

Lines changed: 0 additions & 24 deletions
This file was deleted.

src/file_ref_map.dat

3.21 KB
Binary file not shown.

src/file_ref_map.json

Lines changed: 1 addition & 0 deletions
Large diffs are not rendered by default.

tools/FileRefExtractor/BuildMode/Ast.php

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,24 +55,30 @@ public static function crc(string $schema): string
5555
return $id;
5656
}
5757

58-
public function finalize(string $refMapFile, string $dbSchemaFile): void
58+
public function finalize(string $refMapFile, string $refMapFileJson): void
5959
{
6060
$dbSchema = '';
6161
foreach ($this->outputSchema as $constructor => $params) {
6262
$dbSchema .= self::stringifySchema($constructor, $params)."\n";
6363
}
64-
file_put_contents($dbSchemaFile, $dbSchema);
65-
$value = ['_' => 'fileReferenceOrigins', 'db_schema' => $dbSchema, 'ctxs' => $this->output];
64+
$dbSchemaJSON = (new TL(null))->toJson($dbSchema);
65+
$value = [
66+
'_' => 'fileReferenceOrigins',
67+
'db_schema' => $dbSchema,
68+
'db_schema_json' => json_encode($dbSchemaJSON, flags: JSON_THROW_ON_ERROR),
69+
'ctxs' => $this->output,
70+
];
6671
Magic::start(false);
6772

6873
$s = new TLSchema;
69-
$s = $s->setOther(['filerefs' => __DIR__ . '/../../../src/TL_filerefs.tl']);
74+
$s = $s->setOther(['filerefs' => __DIR__ . '/../../../src/TL_file_ref_map_schema.tl']);
7075
$TL = new TL((new ReflectionClass(MTProto::class))->newInstanceWithoutConstructor());
7176
$TL->init($s);
7277
$serialized = $TL->serializeObject(['type' => 'FileReferenceOrigins'], $value, '');
7378
$valueDe = $TL->deserialize($serialized, ['type' => '', 'connection' => null, 'encrypted' => true]);
7479
Assert::true($value == $valueDe);
7580
file_put_contents($refMapFile, $serialized);
81+
file_put_contents($refMapFileJson, json_encode($valueDe, flags: JSON_THROW_ON_ERROR));
7682
}
7783

7884
private static function stringifySchema(string $constructor, array $params): string

tools/FileRefExtractor/FileRefGenerator.php

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,17 +34,14 @@
3434
use danog\MadelineProto\FileRefExtractor\Ops\Noop;
3535
use danog\MadelineProto\FileRefExtractor\Ops\PrimitiveLiteralOp;
3636
use danog\MadelineProto\FileRefExtractor\Ops\ThemeFormatOp;
37-
use danog\MadelineProto\FileRefExtractor\Path;
38-
use danog\MadelineProto\FileRefExtractor\TLContext;
39-
use danog\MadelineProto\FileRefExtractor\TLWrapper;
4037
use danog\MadelineProto\Logger;
4138
use danog\MadelineProto\Magic;
4239
use danog\MadelineProto\Settings\TLSchema;
4340
use danog\MadelineProto\TL\TL;
4441

4542
final class FileRefGenerator
4643
{
47-
public static function generate(int $layer, string $inputSchema, string $outputFile, string $outputSchema): void
44+
public static function generate(int $layer, string $inputSchema, string $outputFile, string $outputFileJson): void
4845
{
4946
Magic::start(false);
5047
$schema = new TLSchema;
@@ -626,10 +623,7 @@ static function (array $stack) use ($locations, $TL, $tmp, &$validated, $storyMe
626623
}
627624
}
628625

629-
$output->finalize(
630-
$outputFile,
631-
$outputSchema,
632-
);
626+
$output->finalize($outputFile, $outputFileJson);
633627

634628
echo("OK $layer!\n".PHP_EOL);
635629
}

tools/FileRefExtractor/Path.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ public function buildPath(TLContext $tl, string $extractor): array
116116
}
117117
$new[] = $newPart;
118118
}
119-
$serialized = $extractor.json_encode($new);
119+
$serialized = $extractor.json_encode($new, flags: JSON_THROW_ON_ERROR);
120120
if (isset($tl->buildMode->stored[$serialized])) {
121121
$name = $tl->buildMode->stored[$serialized]['name'];
122122
} else {

tools/build_docs/layerUpgrade.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ function layerUpgrade(int $layer): void
1313
file_put_contents('docs/docs/docs/USING_METHODS.md', $doc);
1414

1515
foreach (glob('src/*.tl') as $file) {
16-
if (basename($file) === 'TL_filerefs.tl') {
16+
if (basename($file) === 'TL_file_ref_map_schema.tl') {
1717
continue;
1818
}
1919
unlink($file);

tools/gen_filerefmap.php

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@
22

33
use danog\MadelineProto\FileRefExtractor\BuildMode\Ast;
44
use danog\MadelineProto\FileRefExtractor\FileRefGenerator;
5+
use danog\MadelineProto\TL\TL;
56

67
require 'vendor/autoload.php';
78

89
// Cleanup schema
9-
$schemaFile = __DIR__.'/../src/TL_filerefs.tl';
10+
$schemaFile = __DIR__.'/../src/TL_file_ref_map_schema.tl';
1011
$schema = explode("\n", file_get_contents($schemaFile));
1112
foreach ($schema as &$line) {
1213
$line = rtrim(trim($line), ';');
@@ -37,14 +38,22 @@
3738
$last,
3839
__DIR__."/../src/TL_telegram_v$last.tl",
3940
__DIR__.'/../src/file_ref_map.dat',
40-
__DIR__.'/../src/TL_filerefs_db.tl',
41+
__DIR__.'/../src/file_ref_map.json',
4142
);
4243

4344
copy(
44-
__DIR__."/../src/TL_filerefs_db.tl",
45-
__DIR__."/../schemas/TL_telegram_v{$last}_filerefs_db.tl"
45+
__DIR__."/../src/TL_file_ref_map_schema.tl",
46+
__DIR__."/../schemas/TL_telegram_v{$last}_file_ref_map_schema.tl"
4647
);
48+
49+
$TL = new TL(null);
50+
file_put_contents(__DIR__."/../schemas/TL_telegram_v{$last}_file_ref_map_schema.json", json_encode($TL->toJson($schema), flags: JSON_THROW_ON_ERROR));
51+
4752
copy(
4853
__DIR__."/../src/file_ref_map.dat",
4954
__DIR__."/../schemas/TL_telegram_v{$last}_file_ref_map.dat"
50-
);
55+
);
56+
copy(
57+
__DIR__."/../src/file_ref_map.json",
58+
__DIR__."/../schemas/TL_telegram_v{$last}_file_ref_map.json"
59+
);

0 commit comments

Comments
 (0)