diff --git a/Generator.cs b/Generator.cs index 0fa7403..f5f9e14 100644 --- a/Generator.cs +++ b/Generator.cs @@ -293,7 +293,7 @@ namespace WTelegram 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}"); + sw.WriteLine($"\t\tpublic const int Layer = {currentLayer};\t\t\t\t\t// fetched {DateTime.UtcNow}"); else sw.WriteLine(line); if (line == myTag) diff --git a/Helpers.cs b/Helpers.cs index c38cf66..a39348c 100644 --- a/Helpers.cs +++ b/Helpers.cs @@ -47,7 +47,7 @@ namespace WTelegram return result; } - public static ulong PQFactorize(ulong pq) // ported from https://github.com/tdlib/td/blob/master/tdutils/td/utils/crypto.cpp#L90 + internal static ulong PQFactorize(ulong pq) // ported from https://github.com/tdlib/td/blob/master/tdutils/td/utils/crypto.cpp#L90 { if (pq < 2) return 1; var random = new Random(); diff --git a/TL.Table.cs b/TL.Table.cs index 60db95a..bacc29b 100644 --- a/TL.Table.cs +++ b/TL.Table.cs @@ -7,6 +7,7 @@ namespace TL { public const int Layer = 121; // fetched 07/08/2021 01:34:33 public const int VectorCtor = 0x1CB5C415; + public const int NullCtor = 0x56730BCC; internal readonly static Dictionary Table = new() { diff --git a/TL.cs b/TL.cs index 342e022..a23b18e 100644 --- a/TL.cs +++ b/TL.cs @@ -55,7 +55,10 @@ namespace TL { if (((ifFlag = field.GetCustomAttribute()) != null) && (flags & (1 << ifFlag.Bit)) == 0) continue; object value = field.GetValue(obj); - SerializeValue(writer, value); + if (value == null) + SerializeNull(writer, field.FieldType); + else + SerializeValue(writer, value); if (field.Name.Equals("Flags", StringComparison.OrdinalIgnoreCase)) flags = (int)value; } } @@ -207,6 +210,15 @@ namespace TL return bytes; } + internal static void SerializeNull(BinaryWriter writer, Type type) + { + if (!type.IsArray) + writer.Write(NullCtor); + else if (type != typeof(byte[])) // null arrays are serialized as empty + writer.Write(VectorCtor); + writer.Write(0); + } + private static _Message[] DeserializeMessages(BinaryReader reader) { int count = reader.ReadInt32();