mirror of
https://github.com/wiz0u/WTelegramClient.git
synced 2025-12-06 06:52:01 +01:00
support TL bare vectors
This commit is contained in:
parent
be4d1aca6b
commit
c570f3d8d0
26
src/TL.cs
26
src/TL.cs
|
|
@ -154,14 +154,26 @@ namespace TL
|
|||
|
||||
internal static Array ReadTLVector(this BinaryReader reader, Type type)
|
||||
{
|
||||
var ctorNb = reader.ReadUInt32();
|
||||
if (ctorNb != Layer.VectorCtor) throw new ApplicationException($"Cannot deserialize {type.Name} with ctor #{ctorNb:x}");
|
||||
var elementType = type.GetElementType();
|
||||
int count = reader.ReadInt32();
|
||||
Array array = (Array)Activator.CreateInstance(type, count);
|
||||
for (int i = 0; i < count; i++)
|
||||
array.SetValue(reader.ReadTLValue(elementType), i);
|
||||
return array;
|
||||
uint ctorNb = reader.ReadUInt32();
|
||||
if (ctorNb == Layer.VectorCtor)
|
||||
{
|
||||
int count = reader.ReadInt32();
|
||||
Array array = (Array)Activator.CreateInstance(type, count);
|
||||
for (int i = 0; i < count; i++)
|
||||
array.SetValue(reader.ReadTLValue(elementType), i);
|
||||
return array;
|
||||
}
|
||||
else if (ctorNb < 1024 && !elementType.IsAbstract && elementType.GetCustomAttribute<TLDefAttribute>() is TLDefAttribute attr)
|
||||
{
|
||||
int count = (int)ctorNb;
|
||||
Array array = (Array)Activator.CreateInstance(type, count);
|
||||
for (int i = 0; i < count; i++)
|
||||
array.SetValue(reader.ReadTLObject(attr.CtorNb), i);
|
||||
return array;
|
||||
}
|
||||
else
|
||||
throw new ApplicationException($"Cannot deserialize {type.Name} with ctor #{ctorNb:x}");
|
||||
}
|
||||
|
||||
internal static void WriteTLStamp(this BinaryWriter writer, DateTime datetime)
|
||||
|
|
|
|||
Loading…
Reference in a new issue