mirror of
https://github.com/wiz0u/WTelegramClient.git
synced 2025-12-06 06:52:01 +01:00
ToBytes TL.Serialization helper.
Warning: do not use for long-term storage because TL structures can change in future layers and may not be deserializable
This commit is contained in:
parent
9ec2f31f72
commit
d6fdcab440
|
|
@ -181,11 +181,11 @@ public class MTProtoGenerator : IIncrementalGenerator
|
|||
break;
|
||||
case "System.Collections.Generic.Dictionary<long, TL.User>":
|
||||
readTL.AppendLine($"r.{member.Name} = reader.ReadTLDictionary<User>();");
|
||||
writeTl.AppendLine($"writer.WriteTLVector({member.Name}.Values.ToArray());");
|
||||
writeTl.AppendLine($"writer.WriteTLVector({member.Name}?.Values.ToArray());");
|
||||
break;
|
||||
case "System.Collections.Generic.Dictionary<long, TL.ChatBase>":
|
||||
readTL.AppendLine($"r.{member.Name} = reader.ReadTLDictionary<ChatBase>();");
|
||||
writeTl.AppendLine($"writer.WriteTLVector({member.Name}.Values.ToArray());");
|
||||
writeTl.AppendLine($"writer.WriteTLVector({member.Name}?.Values.ToArray());");
|
||||
break;
|
||||
case "object":
|
||||
readTL.AppendLine($"r.{member.Name} = reader.ReadTLObject();");
|
||||
|
|
|
|||
|
|
@ -1125,7 +1125,7 @@ namespace WTelegram
|
|||
{
|
||||
try
|
||||
{
|
||||
var users = await this.Users_GetUsers(InputUser.Self); // this calls also reenable incoming Updates
|
||||
var users = await this.Users_GetUsers(InputUser.Self); // this call also reenable incoming Updates
|
||||
var self = users[0] as User;
|
||||
if (self.id == long.Parse(botToken.Split(':')[0]))
|
||||
{
|
||||
|
|
|
|||
|
|
@ -247,10 +247,7 @@ namespace WTelegram
|
|||
var rsaParam = rsa.ExportParameters(false);
|
||||
if (rsaParam.Modulus[0] == 0) rsaParam.Modulus = rsaParam.Modulus[1..];
|
||||
var publicKey = new RSAPublicKey { n = rsaParam.Modulus, e = rsaParam.Exponent };
|
||||
using var memStream = new MemoryStream(280);
|
||||
using (var writer = new BinaryWriter(memStream))
|
||||
writer.WriteTLObject(publicKey);
|
||||
var bareData = memStream.ToArray();
|
||||
var bareData = publicKey.ToBytes();
|
||||
var fingerprint = BinaryPrimitives.ReadInt64LittleEndian(sha1.ComputeHash(bareData, 4, bareData.Length - 4).AsSpan(12)); // 64 lower-order bits of SHA1
|
||||
PublicKeys[fingerprint] = publicKey;
|
||||
Helpers.Log(1, $"Loaded a public key with fingerprint {fingerprint:X}");
|
||||
|
|
|
|||
10
src/TL.cs
10
src/TL.cs
|
|
@ -1,5 +1,6 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.IO;
|
||||
using System.IO.Compression;
|
||||
using System.Linq;
|
||||
|
|
@ -48,6 +49,15 @@ namespace TL
|
|||
|
||||
public static class Serialization
|
||||
{
|
||||
[EditorBrowsable(EditorBrowsableState.Never)]
|
||||
public static byte[] ToBytes<T>(this T obj) where T : IObject
|
||||
{
|
||||
using var ms = new MemoryStream(384);
|
||||
using var writer = new BinaryWriter(ms);
|
||||
writer.WriteTLObject(obj);
|
||||
return ms.ToArray();
|
||||
}
|
||||
|
||||
public static void WriteTLObject<T>(this BinaryWriter writer, T obj) where T : IObject
|
||||
{
|
||||
if (obj == null) { writer.WriteTLNull(typeof(T)); return; }
|
||||
|
|
|
|||
Loading…
Reference in a new issue