forked from sochix/TLSharp
-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathMessage.cs
More file actions
46 lines (40 loc) · 1.17 KB
/
Message.cs
File metadata and controls
46 lines (40 loc) · 1.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
using System;
using System.IO;
using System.Linq;
using TgSharp.Core.MTProto.Crypto;
namespace TgSharp.Core.Network
{
internal class Message
{
internal byte[] Body { get; private set; }
internal Message(byte[] body)
{
if (body == null)
throw new ArgumentNullException(nameof(body));
Body = body;
}
internal static Message Decode(byte[] body)
{
using (var memoryStream = new MemoryStream(body))
{
using (var binaryReader = new BinaryReader(memoryStream))
{
int length = binaryReader.ReadInt32();
return new Message(binaryReader.ReadBytes(length));
}
}
}
internal byte[] Encode()
{
using (var memoryStream = new MemoryStream())
{
using (var binaryWriter = new BinaryWriter(memoryStream))
{
binaryWriter.Write(Body.Length);
binaryWriter.Write(Body);
return memoryStream.ToArray();
}
}
}
}
}