mirror of
https://github.com/wiz0u/WTelegramClient.git
synced 2026-01-07 09:10:02 +01:00
Serialize null values correctly
This commit is contained in:
parent
8ecf2e1a53
commit
9c76112be1
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
|
|
|
|||
|
|
@ -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<uint, Type> Table = new()
|
||||
{
|
||||
|
|
|
|||
14
TL.cs
14
TL.cs
|
|
@ -55,7 +55,10 @@ namespace TL
|
|||
{
|
||||
if (((ifFlag = field.GetCustomAttribute<IfFlagAttribute>()) != 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();
|
||||
|
|
|
|||
Loading…
Reference in a new issue