Generator: fetch from Web ; supports Layer in end-to-end messages

This commit is contained in:
Wizou 2021-08-07 03:44:11 +02:00
parent 498aa2c319
commit 8ecf2e1a53
5 changed files with 925 additions and 1028 deletions

View file

@ -2,262 +2,317 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using System.Net.Http;
using System.Text.Json; using System.Text.Json;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
namespace WTelegram namespace WTelegram
{ {
public static class Generator public class Generator
{ {
//TODO: generate BinaryReader/Writer serialization directly to avoid using Reflection //TODO: generate BinaryReader/Writer serialization directly to avoid using Reflection
//TODO: generate partial class with methods for functions instead of exposing request classes //TODO: generate partial class with methods for functions instead of exposing request classes
readonly Dictionary<int, string> ctorToTypes = new();
readonly HashSet<string> allTypes = new();
readonly Dictionary<int, Dictionary<string, TypeInfo>> typeInfosByLayer = new();
Dictionary<string, TypeInfo> typeInfos;
int currentLayer;
string tabIndent;
public static void FromJson(string jsonPath, string outputCs, string tableCs = null) public async Task FromWeb()
{ {
Console.WriteLine("Fetch web pages...");
//using var http = new HttpClient();
//var html = await http.GetStringAsync("https://core.telegram.org/api/layers");
var html = await Task.FromResult("#layer-121");
currentLayer = int.Parse(Regex.Match(html, @"#layer-(\d+)").Groups[1].Value);
//await File.WriteAllBytesAsync("TL.MTProto.json", await http.GetByteArrayAsync("https://core.telegram.org/schema/mtproto-json"));
//await File.WriteAllBytesAsync("TL.Schema.json", await http.GetByteArrayAsync("https://core.telegram.org/schema/json"));
//await File.WriteAllBytesAsync("TL.Secret.json", await http.GetByteArrayAsync("https://core.telegram.org/schema/end-to-end-json"));
FromJson("TL.MTProto.json", "TL.MTProto.cs", @"TL.Table.cs");
FromJson("TL.Schema.json", "TL.Schema.cs", @"TL.Table.cs");
FromJson("TL.Secret.json", "TL.Secret.cs", @"TL.Table.cs");
}
public void FromJson(string jsonPath, string outputCs, string tableCs = null)
{
Console.WriteLine("Parsing " + jsonPath);
var schema = JsonSerializer.Deserialize<SchemaJson>(File.ReadAllText(jsonPath)); var schema = JsonSerializer.Deserialize<SchemaJson>(File.ReadAllText(jsonPath));
using var sw = File.CreateText(outputCs); using var sw = File.CreateText(outputCs);
sw.WriteLine("using System;"); sw.WriteLine("using System;");
sw.WriteLine(); sw.WriteLine();
sw.WriteLine("namespace TL"); sw.WriteLine("namespace TL");
sw.Write("{"); sw.Write("{");
string tabIndent = "\t"; tabIndent = "\t";
Dictionary<string, TypeInfo> typeInfos = new(); var layers = schema.constructors.GroupBy(c => c.layer).OrderBy(g => g.Key);
foreach (var ctor in schema.constructors) foreach (var layer in layers)
{ {
var structName = CSharpName(ctor.predicate); typeInfos = typeInfosByLayer.GetOrCreate(layer.Key);
var typeInfo = typeInfos.GetOrCreate(ctor.type); if (layer.Key != 0)
if (typeInfo.ReturnName == null) typeInfo.ReturnName = CSharpName(ctor.type);
typeInfo.Structs.Add(ctor);
if (structName == typeInfo.ReturnName) typeInfo.SameName = ctor;
}
typeInfos.Remove("Bool");
typeInfos.Remove("Vector t");
foreach (var (name, typeInfo) in typeInfos)
{
if (typeInfo.SameName == null)
{ {
typeInfo.NeedAbstract = -1; sw.WriteLine();
if (typeInfo.Structs.Count > 1) sw.WriteLine("\tnamespace Layer" + layer.Key);
sw.Write("\t{");
tabIndent += "\t";
}
string layerPrefix = layer.Key == 0 ? "" : $"Layer{layer.Key}.";
foreach (var ctor in layer)
{
if (ctorToTypes.ContainsKey(ctor.ID)) continue;
if (ctor.type is "Bool" or "Vector t") continue;
var structName = CSharpName(ctor.predicate);
ctorToTypes[ctor.ID] = layerPrefix + structName;
var typeInfo = typeInfos.GetOrCreate(ctor.type);
if (ctor.ID == 0x5BB8E511) { ctorToTypes[ctor.ID] = structName = ctor.predicate = ctor.type = "_Message"; }
if (typeInfo.ReturnName == null) typeInfo.ReturnName = CSharpName(ctor.type);
typeInfo.Structs.Add(ctor);
if (structName == typeInfo.ReturnName) typeInfo.SameName = ctor;
}
foreach (var (name, typeInfo) in typeInfos)
{
if (allTypes.Contains(typeInfo.ReturnName)) { typeInfo.NeedAbstract = -2; continue; }
if (typeInfo.SameName == null)
{ {
List<Param> fakeCtorParams = new(); typeInfo.NeedAbstract = -1;
while (typeInfo.Structs[0].@params.Length > fakeCtorParams.Count) if (typeInfo.Structs.Count > 1)
{ {
fakeCtorParams.Add(typeInfo.Structs[0].@params[fakeCtorParams.Count]); List<Param> fakeCtorParams = new();
if (!typeInfo.Structs.All(ctor => HasPrefix(ctor, fakeCtorParams))) while (typeInfo.Structs[0].@params.Length > fakeCtorParams.Count)
{ {
fakeCtorParams.RemoveAt(fakeCtorParams.Count - 1); fakeCtorParams.Add(typeInfo.Structs[0].@params[fakeCtorParams.Count]);
break; if (!typeInfo.Structs.All(ctor => HasPrefix(ctor, fakeCtorParams)))
{
fakeCtorParams.RemoveAt(fakeCtorParams.Count - 1);
break;
}
}
if (fakeCtorParams.Count > 0)
{
typeInfo.Structs.Insert(0, typeInfo.SameName = new Constructor
{ id = null, @params = fakeCtorParams.ToArray(), predicate = typeInfo.ReturnName, type = typeInfo.ReturnName });
typeInfo.NeedAbstract = fakeCtorParams.Count;
} }
} }
if (fakeCtorParams.Count > 0) }
else if (typeInfo.Structs.Count > 1)
{
typeInfo.NeedAbstract = typeInfo.SameName.@params.Length;
foreach (var ctor in typeInfo.Structs)
{ {
typeInfo.Structs.Insert(0, typeInfo.SameName = new Constructor if (ctor == typeInfo.SameName) continue;
{ id = null, @params = fakeCtorParams.ToArray(), predicate = typeInfo.ReturnName, type = typeInfo.ReturnName }); if (!HasPrefix(ctor, typeInfo.SameName.@params)) { typeInfo.NeedAbstract = -1; typeInfo.ReturnName += "Base"; break; }
typeInfo.NeedAbstract = fakeCtorParams.Count;
} }
} }
} }
else if (typeInfo.Structs.Count > 1) foreach (var typeInfo in typeInfos.Values)
WriteTypeInfo(sw, typeInfo, jsonPath, layerPrefix, false);
if (layer.Key != 0)
{ {
typeInfo.NeedAbstract = typeInfo.SameName.@params.Length; sw.WriteLine("\t}");
foreach (var ctor in typeInfo.Structs) tabIndent = tabIndent[1..];
{
if (ctor == typeInfo.SameName) continue;
if (!HasPrefix(ctor, typeInfo.SameName.@params)) { typeInfo.NeedAbstract = -1; typeInfo.ReturnName += "Base"; break; }
}
} }
} }
foreach (var typeInfo in typeInfos.Values) if (typeInfosByLayer[0]["Message"].SameName.ID == 0x5BB8E511) typeInfosByLayer[0].Remove("Message");
WriteTypeInfo(sw, typeInfo);
sw.WriteLine(); sw.WriteLine();
sw.WriteLine("\tpublic static partial class Fn // ---functions---");
sw.Write("\t{");
tabIndent = "\t\t";
var methods = new List<TypeInfo>(); var methods = new List<TypeInfo>();
foreach (var method in schema.methods) if (schema.methods.Length != 0)
{ {
var typeInfo = new TypeInfo { ReturnName = method.type }; typeInfos = typeInfosByLayer[0];
typeInfo.Structs.Add(new Constructor { id = method.id, @params = method.@params, predicate = method.method, type = method.type }); sw.WriteLine("\tpublic static partial class Fn // ---functions---");
methods.Add(typeInfo); sw.Write("\t{");
WriteTypeInfo(sw, typeInfo, true); tabIndent = "\t\t";
foreach (var method in schema.methods)
{
var typeInfo = new TypeInfo { ReturnName = method.type };
typeInfo.Structs.Add(new Constructor { id = method.id, @params = method.@params, predicate = method.method, type = method.type });
methods.Add(typeInfo);
WriteTypeInfo(sw, typeInfo, jsonPath, "", true);
}
sw.WriteLine("\t}");
} }
sw.WriteLine("\t}");
sw.WriteLine("}"); sw.WriteLine("}");
if (tableCs != null) UpdateTable(); if (tableCs != null) UpdateTable(jsonPath, tableCs, methods);
}
void WriteTypeInfo(StreamWriter sw, TypeInfo typeInfo, bool isMethod = false) void WriteTypeInfo(StreamWriter sw, TypeInfo typeInfo, string definedIn, string layerPrefix, bool isMethod)
{
var parentClass = typeInfo.NeedAbstract != 0 ? typeInfo.ReturnName : "ITLObject";
var genericType = typeInfo.ReturnName.Length == 1 ? $"<{typeInfo.ReturnName}>" : null;
if (isMethod) parentClass = $"ITLFunction<{MapType(typeInfo.ReturnName, "")}>";
bool needNewLine = true;
if (typeInfo.NeedAbstract == -1 && allTypes.Add(layerPrefix + parentClass))
{ {
var parentClass = typeInfo.NeedAbstract != 0 ? typeInfo.ReturnName : "ITLObject"; needNewLine = false;
var genericType = typeInfo.ReturnName.Length == 1 ? $"<{typeInfo.ReturnName}>" : null;
if (isMethod)
parentClass = $"ITLFunction<{MapType(typeInfo.ReturnName, "")}>";
sw.WriteLine(); sw.WriteLine();
if (typeInfo.NeedAbstract == -1) sw.WriteLine($"{tabIndent}public abstract class {parentClass} : ITLObject {{ }}");
sw.WriteLine($"{tabIndent}public abstract class {parentClass} : ITLObject {{ }}"); }
int skipParams = 0; int skipParams = 0;
foreach (var ctor in typeInfo.Structs) foreach (var ctor in typeInfo.Structs)
{
string className = CSharpName(ctor.predicate) + genericType;
//if (typeInfo.ReturnName == "SendMessageAction") System.Diagnostics.Debugger.Break();
if (layerPrefix != "" && className == parentClass) { className += "_"; ctorToTypes[ctor.ID] = layerPrefix + className; }
if (!allTypes.Add(layerPrefix + className)) continue;
if (needNewLine) { needNewLine = false; sw.WriteLine(); }
if (ctor.id == null)
sw.Write($"{tabIndent}public abstract class {className} : ITLObject");
else
{ {
string className = CSharpName(ctor.predicate) + genericType; sw.Write($"{tabIndent}[TLDef(0x{ctor.ID:X8})] //{ctor.predicate}#{ctor.ID:x8} ");
if (ctor.id == null) if (genericType != null) sw.Write($"{{{typeInfo.ReturnName}:Type}} ");
sw.Write($"{tabIndent}public abstract class {className} : ITLObject"); foreach (var parm in ctor.@params) sw.Write($"{parm.name}:{parm.type} ");
else sw.WriteLine($"= {ctor.type}");
sw.Write($"{tabIndent}public class {className} : ");
sw.Write(skipParams == 0 && typeInfo.NeedAbstract > 0 ? "ITLObject" : parentClass);
}
var parms = ctor.@params.Skip(skipParams).ToArray();
if (parms.Length == 0)
{
sw.WriteLine(" { }");
continue;
}
var hasFlagEnum = parms.Any(p => p.type.StartsWith("flags."));
bool multiline = hasFlagEnum || parms.Length > 1;
if (multiline)
{
sw.WriteLine();
sw.WriteLine(tabIndent + "{");
}
else
sw.Write(" { ");
if (hasFlagEnum)
{
var list = new SortedList<int, string>();
foreach (var parm in parms)
{ {
int ctorId = int.Parse(ctor.id); if (!parm.type.StartsWith("flags.") || !parm.type.EndsWith("?true")) continue;
sw.Write($"{tabIndent}[TLDef(0x{ctorId:X8})] //{ctor.predicate}#{ctorId:x8} "); var mask = 1 << int.Parse(parm.type[6..parm.type.IndexOf('?')]);
if (genericType != null) sw.Write($"{{{typeInfo.ReturnName}:Type}} "); if (!list.ContainsKey(mask)) list[mask] = MapName(parm.name);
foreach (var parm in ctor.@params) sw.Write($"{parm.name}:{parm.type} ");
sw.WriteLine($"= {ctor.type}");
sw.Write($"{tabIndent}public class {className} : ");
sw.Write(skipParams == 0 && typeInfo.NeedAbstract > 0 ? "ITLObject" : parentClass);
}
var parms = ctor.@params.Skip(skipParams).ToArray();
if (parms.Length == 0)
{
sw.WriteLine(" { }");
continue;
}
var hasFlagEnum = parms.Any(p => p.type.StartsWith("flags."));
bool multiline = hasFlagEnum || parms.Length > 1;
if (multiline)
{
sw.WriteLine();
sw.WriteLine(tabIndent + "{");
}
else
sw.Write(" { ");
if (hasFlagEnum)
{
var list = new SortedList<int, string>();
foreach (var parm in parms)
{
if (!parm.type.StartsWith("flags.") || !parm.type.EndsWith("?true")) continue;
var mask = 1 << int.Parse(parm.type[6..parm.type.IndexOf('?')]);
if (!list.ContainsKey(mask)) list[mask] = MapName(parm.name);
}
foreach (var parm in parms)
{
if (!parm.type.StartsWith("flags.") || parm.type.EndsWith("?true")) continue;
var mask = 1 << int.Parse(parm.type[6..parm.type.IndexOf('?')]);
if (list.ContainsKey(mask)) continue;
var name = MapName("has_" + parm.name);
if (list.Values.Contains(name)) name += "_field";
list[mask] = name;
}
string line = tabIndent + "\t[Flags] public enum Flags { ";
foreach (var (mask, name) in list)
{
var str = $"{name} = 0x{mask:X}, ";
if (line.Length + str.Length + tabIndent.Length * 3 >= 134) { sw.WriteLine(line); line = tabIndent + "\t\t"; }
line += str;
}
sw.WriteLine(line.TrimEnd(',', ' ') + " }");
} }
foreach (var parm in parms) foreach (var parm in parms)
{ {
if (parm.type.EndsWith("?true")) continue; if (!parm.type.StartsWith("flags.") || parm.type.EndsWith("?true")) continue;
if (multiline) sw.Write(tabIndent + "\t"); var mask = 1 << int.Parse(parm.type[6..parm.type.IndexOf('?')]);
if (parm.type == "#") if (list.ContainsKey(mask)) continue;
sw.Write($"public {(hasFlagEnum ? "Flags" : "int")} {parm.name};"); var name = MapName("has_" + parm.name);
else if (list.Values.Contains(name)) name += "_field";
{ list[mask] = name;
if (parm.type.StartsWith("flags."))
{
int qm = parm.type.IndexOf('?');
sw.Write($"[IfFlag({parm.type[6..qm]})] public {MapType(parm.type[(qm + 1)..], parm.name)} {MapName(parm.name)};");
}
else
sw.Write($"public {MapType(parm.type, parm.name)} {MapName(parm.name)};");
}
if (multiline) sw.WriteLine();
} }
string line = tabIndent + "\t[Flags] public enum Flags { ";
if (ctorNeedClone.Contains(className)) foreach (var (mask, name) in list)
sw.WriteLine($"{tabIndent}\tpublic {className} Clone() => ({className})MemberwiseClone();");
if (multiline)
sw.WriteLine(tabIndent + "}");
else
sw.WriteLine(" }");
skipParams = typeInfo.NeedAbstract;
}
string MapName(string name) => name switch
{
"out" => "out_",
"static" => "static_",
"long" => "long_",
"default" => "default_",
"public" => "public_",
"params" => "params_",
"private" => "private_",
_ => name
};
string MapType(string type, string name)
{
if (type.StartsWith("Vector<", StringComparison.OrdinalIgnoreCase))
return MapType(type[7..^1], name) + "[]";
else if (type == "Bool")
return "bool";
else if (type == "bytes")
return "byte[]";
else if (type == "int128")
return "Int128";
else if (type == "int256")
return "Int256";
else if (type == "Object")
return "ITLObject";
else if (type == "!X")
return "ITLFunction<X>";
else if (typeInfos.TryGetValue(type, out var typeInfo))
return typeInfo.ReturnName;
else if (type == "int")
{ {
var name2 = '_' + name + '_'; var str = $"{name} = 0x{mask:X}, ";
if (name2.EndsWith("_date_") || name2.EndsWith("_time_") || name2 == "_expires_" || name2 == "_now_" || name2.StartsWith("_valid_")) if (line.Length + str.Length + tabIndent.Length * 3 >= 134) { sw.WriteLine(line); line = tabIndent + "\t\t"; }
return "DateTime"; line += str;
else
return "int";
} }
else if (type == "string") sw.WriteLine(line.TrimEnd(',', ' ') + " }");
return name.StartsWith("md5") ? "byte[]" : "string"; }
else foreach (var parm in parms)
return type; {
if (parm.type.EndsWith("?true")) continue;
if (multiline) sw.Write(tabIndent + "\t");
if (parm.type == "#")
sw.Write($"public {(hasFlagEnum ? "Flags" : "int")} {parm.name};");
else
{
if (parm.type.StartsWith("flags."))
{
int qm = parm.type.IndexOf('?');
sw.Write($"[IfFlag({parm.type[6..qm]})] public {MapType(parm.type[(qm + 1)..], parm.name)} {MapName(parm.name)};");
}
else
sw.Write($"public {MapType(parm.type, parm.name)} {MapName(parm.name)};");
}
if (multiline) sw.WriteLine();
} }
}
void UpdateTable() if (ctorNeedClone.Contains(className))
sw.WriteLine($"{tabIndent}\tpublic {className} Clone() => ({className})MemberwiseClone();");
if (multiline)
sw.WriteLine(tabIndent + "}");
else
sw.WriteLine(" }");
skipParams = typeInfo.NeedAbstract;
}
string MapName(string name) => name switch
{ {
var myTag = $"\t\t\t// from {Path.GetFileNameWithoutExtension(jsonPath)}:"; "out" => "out_",
using (var sr = new StreamReader(tableCs)) "static" => "static_",
using (var sw = new StreamWriter(tableCs + ".new")) "long" => "long_",
"default" => "default_",
"public" => "public_",
"params" => "params_",
"private" => "private_",
_ => name
};
string MapType(string type, string name)
{
if (type.StartsWith("Vector<", StringComparison.OrdinalIgnoreCase))
return MapType(type[7..^1], name) + "[]";
else if (type == "Bool")
return "bool";
else if (type == "bytes")
return "byte[]";
else if (type == "int128")
return "Int128";
else if (type == "int256")
return "Int256";
else if (type == "Object")
return "ITLObject";
else if (type == "!X")
return "ITLFunction<X>";
else if (typeInfos.TryGetValue(type, out var typeInfo))
return typeInfo.ReturnName;
else if (type == "int")
{ {
string line; var name2 = '_' + name + '_';
while ((line = sr.ReadLine()) != null) if (name2.EndsWith("_date_") || name2.EndsWith("_time_") || name2 == "_expires_" || name2 == "_now_" || name2.StartsWith("_valid_"))
{ return "DateTime";
sw.WriteLine(line); else
if (line == myTag) return "int";
{
foreach (var typeInfo in typeInfos.Values)
foreach (var ctor in typeInfo.Structs)
if (ctor.id != null)
sw.WriteLine($"\t\t\t[0x{int.Parse(ctor.id):X8}] = typeof({CSharpName(ctor.predicate)}),");
foreach (var typeInfo in methods)
foreach (var ctor in typeInfo.Structs)
{
var generic = typeInfo.ReturnName.Length == 1 ? "<>" : "";
sw.WriteLine($"\t\t\t[0x{int.Parse(ctor.id):X8}] = typeof(Fn.{CSharpName(ctor.predicate)}{generic}),");
}
while ((line = sr.ReadLine()) != null)
if (line.StartsWith("\t\t\t// "))
break;
sw.WriteLine(line);
}
}
} }
File.Replace(tableCs + ".new", tableCs, null); else if (type == "string")
return name.StartsWith("md5") ? "byte[]" : "string";
else
return type;
} }
} }
void UpdateTable(string jsonPath, string tableCs, List<TypeInfo> methods)
{
var myTag = $"\t\t\t// from {Path.GetFileNameWithoutExtension(jsonPath)}:";
var seen_ids = new HashSet<int>();
using (var sr = new StreamReader(tableCs))
using (var sw = new StreamWriter(tableCs + ".new"))
{
string line;
while ((line = sr.ReadLine()) != null)
{
if (currentLayer != 0 && line.StartsWith("\t\tpublic const int Layer"))
sw.WriteLine($"\t\tpublic const int Layer = {currentLayer};\t\t\t\t// fetched {DateTime.UtcNow}");
else
sw.WriteLine(line);
if (line == myTag)
{
foreach (var ctor in ctorToTypes)
if (seen_ids.Add(ctor.Key))
sw.WriteLine($"\t\t\t[0x{ctor.Key:X8}] = typeof({ctor.Value}),");
while ((line = sr.ReadLine()) != null)
if (line.StartsWith("\t\t\t// "))
break;
sw.WriteLine(line);
}
else if (line.StartsWith("\t\t\t[0x"))
seen_ids.Add(int.Parse(line[6..14], System.Globalization.NumberStyles.HexNumber));
}
}
File.Replace(tableCs + ".new", tableCs, null);
}
static readonly HashSet<string> ctorNeedClone = new() { /*"User"*/ }; static readonly HashSet<string> ctorNeedClone = new() { /*"User"*/ };
private static bool HasPrefix(Constructor ctor, IList<Param> prefixParams) private static bool HasPrefix(Constructor ctor, IList<Param> prefixParams)
@ -301,6 +356,9 @@ namespace WTelegram
public string predicate { get; set; } public string predicate { get; set; }
public Param[] @params { get; set; } public Param[] @params { get; set; }
public string type { get; set; } public string type { get; set; }
public int layer { get; set; }
public int ID => int.Parse(id);
} }
public class Param public class Param

View file

@ -113,7 +113,7 @@ namespace TL
public int bytes; public int bytes;
} }
[TLDef(0x949D9DC)] //future_salt#0949d9dc valid_since:int valid_until:int salt:long = FutureSalt [TLDef(0x0949D9DC)] //future_salt#0949d9dc valid_since:int valid_until:int salt:long = FutureSalt
public class FutureSalt : ITLObject public class FutureSalt : ITLObject
{ {
public DateTime valid_since; public DateTime valid_since;

View file

@ -2,181 +2,361 @@ using System;
namespace TL namespace TL
{ {
public abstract class DecryptedMessageBase : ITLObject { } namespace Layer8
[TLDef(0x1F814F1F)] //decryptedMessage#1f814f1f random_id:long random_bytes:bytes message:string media:DecryptedMessageMedia = DecryptedMessage
public class DecryptedMessage : DecryptedMessageBase
{ {
public long random_id; public abstract class DecryptedMessageBase : ITLObject { }
public byte[] random_bytes; [TLDef(0x1F814F1F)] //decryptedMessage#1f814f1f random_id:long random_bytes:bytes message:string media:DecryptedMessageMedia = DecryptedMessage
public string message; public class DecryptedMessage : DecryptedMessageBase
public DecryptedMessageMedia media; {
} public long random_id;
[TLDef(0xAA48327D)] //decryptedMessageService#aa48327d random_id:long random_bytes:bytes action:DecryptedMessageAction = DecryptedMessage public byte[] random_bytes;
public class DecryptedMessageService : DecryptedMessageBase public string message;
{ public DecryptedMessageMedia media;
public long random_id; }
public byte[] random_bytes; [TLDef(0xAA48327D)] //decryptedMessageService#aa48327d random_id:long random_bytes:bytes action:DecryptedMessageAction = DecryptedMessage
public DecryptedMessageAction action; public class DecryptedMessageService : DecryptedMessageBase
{
public long random_id;
public byte[] random_bytes;
public DecryptedMessageAction action;
}
public abstract class DecryptedMessageMedia : ITLObject { }
[TLDef(0x089F5C4A)] //decryptedMessageMediaEmpty#089f5c4a = DecryptedMessageMedia
public class DecryptedMessageMediaEmpty : DecryptedMessageMedia { }
[TLDef(0x32798A8C)] //decryptedMessageMediaPhoto#32798a8c thumb:bytes thumb_w:int thumb_h:int w:int h:int size:int key:bytes iv:bytes = DecryptedMessageMedia
public class DecryptedMessageMediaPhoto : DecryptedMessageMedia
{
public byte[] thumb;
public int thumb_w;
public int thumb_h;
public int w;
public int h;
public int size;
public byte[] key;
public byte[] iv;
}
[TLDef(0x4CEE6EF3)] //decryptedMessageMediaVideo#4cee6ef3 thumb:bytes thumb_w:int thumb_h:int duration:int w:int h:int size:int key:bytes iv:bytes = DecryptedMessageMedia
public class DecryptedMessageMediaVideo : DecryptedMessageMedia
{
public byte[] thumb;
public int thumb_w;
public int thumb_h;
public int duration;
public int w;
public int h;
public int size;
public byte[] key;
public byte[] iv;
}
[TLDef(0x35480A59)] //decryptedMessageMediaGeoPoint#35480a59 lat:double long:double = DecryptedMessageMedia
public class DecryptedMessageMediaGeoPoint : DecryptedMessageMedia
{
public double lat;
public double long_;
}
[TLDef(0x588A0A97)] //decryptedMessageMediaContact#588a0a97 phone_number:string first_name:string last_name:string user_id:int = DecryptedMessageMedia
public class DecryptedMessageMediaContact : DecryptedMessageMedia
{
public string phone_number;
public string first_name;
public string last_name;
public int user_id;
}
[TLDef(0xB095434B)] //decryptedMessageMediaDocument#b095434b thumb:bytes thumb_w:int thumb_h:int file_name:string mime_type:string size:int key:bytes iv:bytes = DecryptedMessageMedia
public class DecryptedMessageMediaDocument : DecryptedMessageMedia
{
public byte[] thumb;
public int thumb_w;
public int thumb_h;
public string file_name;
public string mime_type;
public int size;
public byte[] key;
public byte[] iv;
}
[TLDef(0x6080758F)] //decryptedMessageMediaAudio#6080758f duration:int size:int key:bytes iv:bytes = DecryptedMessageMedia
public class DecryptedMessageMediaAudio : DecryptedMessageMedia
{
public int duration;
public int size;
public byte[] key;
public byte[] iv;
}
public abstract class DecryptedMessageAction : ITLObject { }
[TLDef(0xA1733AEC)] //decryptedMessageActionSetMessageTTL#a1733aec ttl_seconds:int = DecryptedMessageAction
public class DecryptedMessageActionSetMessageTTL : DecryptedMessageAction { public int ttl_seconds; }
[TLDef(0x0C4F40BE)] //decryptedMessageActionReadMessages#0c4f40be random_ids:Vector<long> = DecryptedMessageAction
public class DecryptedMessageActionReadMessages : DecryptedMessageAction { public long[] random_ids; }
[TLDef(0x65614304)] //decryptedMessageActionDeleteMessages#65614304 random_ids:Vector<long> = DecryptedMessageAction
public class DecryptedMessageActionDeleteMessages : DecryptedMessageAction { public long[] random_ids; }
[TLDef(0x8AC1F475)] //decryptedMessageActionScreenshotMessages#8ac1f475 random_ids:Vector<long> = DecryptedMessageAction
public class DecryptedMessageActionScreenshotMessages : DecryptedMessageAction { public long[] random_ids; }
[TLDef(0x6719E45C)] //decryptedMessageActionFlushHistory#6719e45c = DecryptedMessageAction
public class DecryptedMessageActionFlushHistory : DecryptedMessageAction { }
} }
public abstract class DecryptedMessageMedia : ITLObject { } namespace Layer17
[TLDef(0x089F5C4A)] //decryptedMessageMediaEmpty#089f5c4a = DecryptedMessageMedia
public class DecryptedMessageMediaEmpty : DecryptedMessageMedia { }
[TLDef(0x32798A8C)] //decryptedMessageMediaPhoto#32798a8c thumb:bytes thumb_w:int thumb_h:int w:int h:int size:int key:bytes iv:bytes = DecryptedMessageMedia
public class DecryptedMessageMediaPhoto : DecryptedMessageMedia
{ {
public byte[] thumb; public abstract class DecryptedMessageBase : ITLObject { }
public int thumb_w; [TLDef(0x204D3878)] //decryptedMessage#204d3878 random_id:long ttl:int message:string media:DecryptedMessageMedia = DecryptedMessage
public int thumb_h; public class DecryptedMessage : DecryptedMessageBase
public int w; {
public int h; public long random_id;
public int size; public int ttl;
public byte[] key; public string message;
public byte[] iv; public DecryptedMessageMedia media;
} }
[TLDef(0x4CEE6EF3)] //decryptedMessageMediaVideo#4cee6ef3 thumb:bytes thumb_w:int thumb_h:int duration:int w:int h:int size:int key:bytes iv:bytes = DecryptedMessageMedia [TLDef(0x73164160)] //decryptedMessageService#73164160 random_id:long action:DecryptedMessageAction = DecryptedMessage
public class DecryptedMessageMediaVideo : DecryptedMessageMedia public class DecryptedMessageService : DecryptedMessageBase
{ {
public byte[] thumb; public long random_id;
public int thumb_w; public DecryptedMessageAction action;
public int thumb_h; }
public int duration;
public int w;
public int h;
public int size;
public byte[] key;
public byte[] iv;
}
[TLDef(0x35480A59)] //decryptedMessageMediaGeoPoint#35480a59 lat:double long:double = DecryptedMessageMedia
public class DecryptedMessageMediaGeoPoint : DecryptedMessageMedia
{
public double lat;
public double long_;
}
[TLDef(0x588A0A97)] //decryptedMessageMediaContact#588a0a97 phone_number:string first_name:string last_name:string user_id:int = DecryptedMessageMedia
public class DecryptedMessageMediaContact : DecryptedMessageMedia
{
public string phone_number;
public string first_name;
public string last_name;
public int user_id;
}
[TLDef(0xB095434B)] //decryptedMessageMediaDocument#b095434b thumb:bytes thumb_w:int thumb_h:int file_name:string mime_type:string size:int key:bytes iv:bytes = DecryptedMessageMedia
public class DecryptedMessageMediaDocument : DecryptedMessageMedia
{
public byte[] thumb;
public int thumb_w;
public int thumb_h;
public string file_name;
public string mime_type;
public int size;
public byte[] key;
public byte[] iv;
}
[TLDef(0x6080758F)] //decryptedMessageMediaAudio#6080758f duration:int size:int key:bytes iv:bytes = DecryptedMessageMedia
public class DecryptedMessageMediaAudio : DecryptedMessageMedia
{
public int duration;
public int size;
public byte[] key;
public byte[] iv;
}
[TLDef(0xFA95B0DD)] //decryptedMessageMediaExternalDocument#fa95b0dd id:long access_hash:long date:int mime_type:string size:int thumb:PhotoSize dc_id:int attributes:Vector<DocumentAttribute> = DecryptedMessageMedia
public class DecryptedMessageMediaExternalDocument : DecryptedMessageMedia
{
public long id;
public long access_hash;
public DateTime date;
public string mime_type;
public int size;
public PhotoSizeBase thumb;
public int dc_id;
public DocumentAttribute[] attributes;
}
[TLDef(0x8A0DF56F)] //decryptedMessageMediaVenue#8a0df56f lat:double long:double title:string address:string provider:string venue_id:string = DecryptedMessageMedia
public class DecryptedMessageMediaVenue : DecryptedMessageMedia
{
public double lat;
public double long_;
public string title;
public string address;
public string provider;
public string venue_id;
}
[TLDef(0xE50511D8)] //decryptedMessageMediaWebPage#e50511d8 url:string = DecryptedMessageMedia
public class DecryptedMessageMediaWebPage : DecryptedMessageMedia { public string url; }
public abstract class DecryptedMessageAction : ITLObject { } public abstract class DecryptedMessageMedia : ITLObject { }
[TLDef(0xA1733AEC)] //decryptedMessageActionSetMessageTTL#a1733aec ttl_seconds:int = DecryptedMessageAction [TLDef(0x524A415D)] //decryptedMessageMediaVideo#524a415d thumb:bytes thumb_w:int thumb_h:int duration:int mime_type:string w:int h:int size:int key:bytes iv:bytes = DecryptedMessageMedia
public class DecryptedMessageActionSetMessageTTL : DecryptedMessageAction { public int ttl_seconds; } public class DecryptedMessageMediaVideo : DecryptedMessageMedia
[TLDef(0x0C4F40BE)] //decryptedMessageActionReadMessages#0c4f40be random_ids:Vector<long> = DecryptedMessageAction {
public class DecryptedMessageActionReadMessages : DecryptedMessageAction { public long[] random_ids; } public byte[] thumb;
[TLDef(0x65614304)] //decryptedMessageActionDeleteMessages#65614304 random_ids:Vector<long> = DecryptedMessageAction public int thumb_w;
public class DecryptedMessageActionDeleteMessages : DecryptedMessageAction { public long[] random_ids; } public int thumb_h;
[TLDef(0x8AC1F475)] //decryptedMessageActionScreenshotMessages#8ac1f475 random_ids:Vector<long> = DecryptedMessageAction public int duration;
public class DecryptedMessageActionScreenshotMessages : DecryptedMessageAction { public long[] random_ids; } public string mime_type;
[TLDef(0x6719E45C)] //decryptedMessageActionFlushHistory#6719e45c = DecryptedMessageAction public int w;
public class DecryptedMessageActionFlushHistory : DecryptedMessageAction { } public int h;
[TLDef(0x511110B0)] //decryptedMessageActionResend#511110b0 start_seq_no:int end_seq_no:int = DecryptedMessageAction public int size;
public class DecryptedMessageActionResend : DecryptedMessageAction public byte[] key;
{ public byte[] iv;
public int start_seq_no; }
public int end_seq_no; [TLDef(0x57E0A9CB)] //decryptedMessageMediaAudio#57e0a9cb duration:int mime_type:string size:int key:bytes iv:bytes = DecryptedMessageMedia
} public class DecryptedMessageMediaAudio : DecryptedMessageMedia
[TLDef(0xF3048883)] //decryptedMessageActionNotifyLayer#f3048883 layer:int = DecryptedMessageAction {
public class DecryptedMessageActionNotifyLayer : DecryptedMessageAction { public int layer; } public int duration;
[TLDef(0xCCB27641)] //decryptedMessageActionTyping#ccb27641 action:SendMessageAction = DecryptedMessageAction public string mime_type;
public class DecryptedMessageActionTyping : DecryptedMessageAction { public SendMessageAction action; } public int size;
[TLDef(0xF3C9611B)] //decryptedMessageActionRequestKey#f3c9611b exchange_id:long g_a:bytes = DecryptedMessageAction public byte[] key;
public class DecryptedMessageActionRequestKey : DecryptedMessageAction public byte[] iv;
{ }
public long exchange_id;
public byte[] g_a;
}
[TLDef(0x6FE1735B)] //decryptedMessageActionAcceptKey#6fe1735b exchange_id:long g_b:bytes key_fingerprint:long = DecryptedMessageAction
public class DecryptedMessageActionAcceptKey : DecryptedMessageAction
{
public long exchange_id;
public byte[] g_b;
public long key_fingerprint;
}
[TLDef(0xDD05EC6B)] //decryptedMessageActionAbortKey#dd05ec6b exchange_id:long = DecryptedMessageAction
public class DecryptedMessageActionAbortKey : DecryptedMessageAction { public long exchange_id; }
[TLDef(0xEC2E0B9B)] //decryptedMessageActionCommitKey#ec2e0b9b exchange_id:long key_fingerprint:long = DecryptedMessageAction
public class DecryptedMessageActionCommitKey : DecryptedMessageAction
{
public long exchange_id;
public long key_fingerprint;
}
[TLDef(0xA82FDD63)] //decryptedMessageActionNoop#a82fdd63 = DecryptedMessageAction
public class DecryptedMessageActionNoop : DecryptedMessageAction { }
[TLDef(0x1BE31789)] //decryptedMessageLayer#1be31789 random_bytes:bytes layer:int in_seq_no:int out_seq_no:int message:DecryptedMessage = DecryptedMessageLayer [TLDef(0x1BE31789)] //decryptedMessageLayer#1be31789 random_bytes:bytes layer:int in_seq_no:int out_seq_no:int message:DecryptedMessage = DecryptedMessageLayer
public class DecryptedMessageLayer : ITLObject public class DecryptedMessageLayer : ITLObject
{ {
public byte[] random_bytes; public byte[] random_bytes;
public int layer; public int layer;
public int in_seq_no; public int in_seq_no;
public int out_seq_no; public int out_seq_no;
public DecryptedMessageBase message; public DecryptedMessageBase message;
}
[TLDef(0x92042FF7)] //sendMessageUploadVideoAction#92042ff7 = SendMessageAction
public class SendMessageUploadVideoAction : SendMessageAction { }
[TLDef(0xE6AC8A6F)] //sendMessageUploadAudioAction#e6ac8a6f = SendMessageAction
public class SendMessageUploadAudioAction : SendMessageAction { }
[TLDef(0x990A3C1A)] //sendMessageUploadPhotoAction#990a3c1a = SendMessageAction
public class SendMessageUploadPhotoAction : SendMessageAction { }
[TLDef(0x8FAEE98E)] //sendMessageUploadDocumentAction#8faee98e = SendMessageAction
public class SendMessageUploadDocumentAction : SendMessageAction { }
public abstract class DecryptedMessageAction : ITLObject { }
[TLDef(0x511110B0)] //decryptedMessageActionResend#511110b0 start_seq_no:int end_seq_no:int = DecryptedMessageAction
public class DecryptedMessageActionResend : DecryptedMessageAction
{
public int start_seq_no;
public int end_seq_no;
}
[TLDef(0xF3048883)] //decryptedMessageActionNotifyLayer#f3048883 layer:int = DecryptedMessageAction
public class DecryptedMessageActionNotifyLayer : DecryptedMessageAction { public int layer; }
[TLDef(0xCCB27641)] //decryptedMessageActionTyping#ccb27641 action:SendMessageAction = DecryptedMessageAction
public class DecryptedMessageActionTyping : DecryptedMessageAction { public SendMessageAction action; }
} }
[TLDef(0x7C596B46)] //fileLocationUnavailable#7c596b46 volume_id:long local_id:int secret:long = FileLocation namespace Layer20
public class FileLocationUnavailable : FileLocation
{ {
public long volume_id; public abstract class DecryptedMessageAction : ITLObject { }
public int local_id; [TLDef(0xF3C9611B)] //decryptedMessageActionRequestKey#f3c9611b exchange_id:long g_a:bytes = DecryptedMessageAction
public long secret; public class DecryptedMessageActionRequestKey : DecryptedMessageAction
} {
[TLDef(0x53D69076)] //fileLocation#53d69076 dc_id:int volume_id:long local_id:int secret:long = FileLocation public long exchange_id;
public class FileLocation_ : FileLocation public byte[] g_a;
{ }
public int dc_id; [TLDef(0x6FE1735B)] //decryptedMessageActionAcceptKey#6fe1735b exchange_id:long g_b:bytes key_fingerprint:long = DecryptedMessageAction
public long volume_id; public class DecryptedMessageActionAcceptKey : DecryptedMessageAction
public int local_id; {
public long secret; public long exchange_id;
public byte[] g_b;
public long key_fingerprint;
}
[TLDef(0xDD05EC6B)] //decryptedMessageActionAbortKey#dd05ec6b exchange_id:long = DecryptedMessageAction
public class DecryptedMessageActionAbortKey : DecryptedMessageAction { public long exchange_id; }
[TLDef(0xEC2E0B9B)] //decryptedMessageActionCommitKey#ec2e0b9b exchange_id:long key_fingerprint:long = DecryptedMessageAction
public class DecryptedMessageActionCommitKey : DecryptedMessageAction
{
public long exchange_id;
public long key_fingerprint;
}
[TLDef(0xA82FDD63)] //decryptedMessageActionNoop#a82fdd63 = DecryptedMessageAction
public class DecryptedMessageActionNoop : DecryptedMessageAction { }
} }
public static partial class Fn // ---functions--- namespace Layer23
{
[TLDef(0xFB0A5727)] //documentAttributeSticker#fb0a5727 = DocumentAttribute
public class DocumentAttributeSticker : DocumentAttribute { }
[TLDef(0x5910CCCB)] //documentAttributeVideo#5910cccb duration:int w:int h:int = DocumentAttribute
public class DocumentAttributeVideo : DocumentAttribute
{
public int duration;
public int w;
public int h;
}
[TLDef(0x051448E5)] //documentAttributeAudio#051448e5 duration:int = DocumentAttribute
public class DocumentAttributeAudio : DocumentAttribute { public int duration; }
[TLDef(0x7C596B46)] //fileLocationUnavailable#7c596b46 volume_id:long local_id:int secret:long = FileLocation
public class FileLocationUnavailable : FileLocation
{
public long volume_id;
public int local_id;
public long secret;
}
[TLDef(0x53D69076)] //fileLocation#53d69076 dc_id:int volume_id:long local_id:int secret:long = FileLocation
public class FileLocation_ : FileLocation
{
public int dc_id;
public long volume_id;
public int local_id;
public long secret;
}
public abstract class DecryptedMessageMedia : ITLObject { }
[TLDef(0xFA95B0DD)] //decryptedMessageMediaExternalDocument#fa95b0dd id:long access_hash:long date:int mime_type:string size:int thumb:PhotoSize dc_id:int attributes:Vector<DocumentAttribute> = DecryptedMessageMedia
public class DecryptedMessageMediaExternalDocument : DecryptedMessageMedia
{
public long id;
public long access_hash;
public DateTime date;
public string mime_type;
public int size;
public PhotoSize thumb;
public int dc_id;
public DocumentAttribute[] attributes;
}
}
namespace Layer45
{
[TLDef(0x36B091DE)] //decryptedMessage#36b091de flags:# random_id:long ttl:int message:string media:flags.9?DecryptedMessageMedia entities:flags.7?Vector<MessageEntity> via_bot_name:flags.11?string reply_to_random_id:flags.3?long = DecryptedMessage
public class DecryptedMessage : ITLObject
{
[Flags] public enum Flags { has_reply_to_random_id = 0x8, has_entities = 0x80, has_media = 0x200, has_via_bot_name = 0x800 }
public Flags flags;
public long random_id;
public int ttl;
public string message;
[IfFlag(9)] public DecryptedMessageMedia media;
[IfFlag(7)] public MessageEntity[] entities;
[IfFlag(11)] public string via_bot_name;
[IfFlag(3)] public long reply_to_random_id;
}
public abstract class DecryptedMessageMedia : ITLObject { }
[TLDef(0xF1FA8D78)] //decryptedMessageMediaPhoto#f1fa8d78 thumb:bytes thumb_w:int thumb_h:int w:int h:int size:int key:bytes iv:bytes caption:string = DecryptedMessageMedia
public class DecryptedMessageMediaPhoto : DecryptedMessageMedia
{
public byte[] thumb;
public int thumb_w;
public int thumb_h;
public int w;
public int h;
public int size;
public byte[] key;
public byte[] iv;
public string caption;
}
[TLDef(0x970C8C0E)] //decryptedMessageMediaVideo#970c8c0e thumb:bytes thumb_w:int thumb_h:int duration:int mime_type:string w:int h:int size:int key:bytes iv:bytes caption:string = DecryptedMessageMedia
public class DecryptedMessageMediaVideo : DecryptedMessageMedia
{
public byte[] thumb;
public int thumb_w;
public int thumb_h;
public int duration;
public string mime_type;
public int w;
public int h;
public int size;
public byte[] key;
public byte[] iv;
public string caption;
}
[TLDef(0x7AFE8AE2)] //decryptedMessageMediaDocument#7afe8ae2 thumb:bytes thumb_w:int thumb_h:int mime_type:string size:int key:bytes iv:bytes attributes:Vector<DocumentAttribute> caption:string = DecryptedMessageMedia
public class DecryptedMessageMediaDocument : DecryptedMessageMedia
{
public byte[] thumb;
public int thumb_w;
public int thumb_h;
public string mime_type;
public int size;
public byte[] key;
public byte[] iv;
public DocumentAttribute[] attributes;
public string caption;
}
[TLDef(0x8A0DF56F)] //decryptedMessageMediaVenue#8a0df56f lat:double long:double title:string address:string provider:string venue_id:string = DecryptedMessageMedia
public class DecryptedMessageMediaVenue : DecryptedMessageMedia
{
public double lat;
public double long_;
public string title;
public string address;
public string provider;
public string venue_id;
}
[TLDef(0xE50511D8)] //decryptedMessageMediaWebPage#e50511d8 url:string = DecryptedMessageMedia
public class DecryptedMessageMediaWebPage : DecryptedMessageMedia { public string url; }
[TLDef(0x3A556302)] //documentAttributeSticker#3a556302 alt:string stickerset:InputStickerSet = DocumentAttribute
public class DocumentAttributeSticker : DocumentAttribute
{
public string alt;
public InputStickerSet stickerset;
}
[TLDef(0xDED218E0)] //documentAttributeAudio#ded218e0 duration:int title:string performer:string = DocumentAttribute
public class DocumentAttributeAudio : DocumentAttribute
{
public int duration;
public string title;
public string performer;
}
}
namespace Layer46
{ } { }
namespace Layer66
{
[TLDef(0xBB718624)] //sendMessageUploadRoundAction#bb718624 = SendMessageAction
public class SendMessageUploadRoundAction : SendMessageAction { }
}
namespace Layer73
{
[TLDef(0x91CC4674)] //decryptedMessage#91cc4674 flags:# random_id:long ttl:int message:string media:flags.9?DecryptedMessageMedia entities:flags.7?Vector<MessageEntity> via_bot_name:flags.11?string reply_to_random_id:flags.3?long grouped_id:flags.17?long = DecryptedMessage
public class DecryptedMessage : ITLObject
{
[Flags] public enum Flags { has_reply_to_random_id = 0x8, has_entities = 0x80, has_media = 0x200, has_via_bot_name = 0x800,
has_grouped_id = 0x20000 }
public Flags flags;
public long random_id;
public int ttl;
public string message;
[IfFlag(9)] public Layer45.DecryptedMessageMedia media;
[IfFlag(7)] public MessageEntity[] entities;
[IfFlag(11)] public string via_bot_name;
[IfFlag(3)] public long reply_to_random_id;
[IfFlag(17)] public long grouped_id;
}
}
} }

File diff suppressed because it is too large Load diff

3
TL.cs
View file

@ -15,9 +15,6 @@ namespace TL
public static partial class Schema public static partial class Schema
{ {
public const int Layer = 121;
public const int VectorCtor = 0x1CB5C415;
internal static byte[] Serialize(ITLObject msg) internal static byte[] Serialize(ITLObject msg)
{ {
using var memStream = new MemoryStream(1024); using var memStream = new MemoryStream(1024);