mtproto 0.0.1 → 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/mtproto/transport/abridged_packet_codec.rb +35 -0
- data/lib/mtproto/version.rb +2 -2
- data/lib/mtproto.rb +7 -0
- metadata +3 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: f4f29435603981ebe49a049987b68aa7423336b2ed6831ee8831dc40e84fa4dc
|
|
4
|
+
data.tar.gz: e1cc58e26a988579389807bf8a7e5c03a5c7ba758d7eb0193e961e7ebf78b412
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 419f2ae43af6c8248c45d4e80d6e1451e9767018a236df01f67765feb16dae45d2d9f0c4563735dda5afca3daf135d1cd4bbce4423262e4631914b7624c50230
|
|
7
|
+
data.tar.gz: '032386a5ae69e7126a7047b427f67c0fb533cb6ac7f7a19193292c4185f5efca126d967329b50dc6476d1a1655f675e1079312104113d9cf328683cfb038a0f5'
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module MTProto
|
|
4
|
+
module Transport
|
|
5
|
+
class AbridgedPacketCodec
|
|
6
|
+
TAG = "\xef".b
|
|
7
|
+
OBFUSCATE_TAG = "\xef\xef\xef\xef".b
|
|
8
|
+
|
|
9
|
+
def encode_packet(data)
|
|
10
|
+
length = data.bytesize >> 2
|
|
11
|
+
|
|
12
|
+
length_prefix = if length < 127
|
|
13
|
+
[length].pack('C')
|
|
14
|
+
else
|
|
15
|
+
"\x7f".b + [length].pack('L<')[0, 3]
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
length_prefix + data
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def decode_packet(data)
|
|
22
|
+
length = data.unpack1('C')
|
|
23
|
+
offset = 1
|
|
24
|
+
|
|
25
|
+
if length >= 127
|
|
26
|
+
length = (data[1, 3] + "\x00").unpack1('L<')
|
|
27
|
+
offset = 4
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
actual_length = length << 2
|
|
31
|
+
data[offset, actual_length]
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
end
|
data/lib/mtproto/version.rb
CHANGED
data/lib/mtproto.rb
ADDED
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: mtproto
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.0.
|
|
4
|
+
version: 0.0.2
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Artem Levenkov
|
|
@@ -19,6 +19,8 @@ extra_rdoc_files: []
|
|
|
19
19
|
files:
|
|
20
20
|
- ".ruby-version"
|
|
21
21
|
- Rakefile
|
|
22
|
+
- lib/mtproto.rb
|
|
23
|
+
- lib/mtproto/transport/abridged_packet_codec.rb
|
|
22
24
|
- lib/mtproto/version.rb
|
|
23
25
|
homepage: https://github.com/alev-pro/mtproto-ruby
|
|
24
26
|
licenses:
|