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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c498fa937d08bb1896de2e69cfa96130b5d4fb6b1dae44761f8251ef426a03b5
4
- data.tar.gz: ffc71857dcdf59248a9fd41750110a632db075558a8362780439fba2fc751d56
3
+ metadata.gz: f4f29435603981ebe49a049987b68aa7423336b2ed6831ee8831dc40e84fa4dc
4
+ data.tar.gz: e1cc58e26a988579389807bf8a7e5c03a5c7ba758d7eb0193e961e7ebf78b412
5
5
  SHA512:
6
- metadata.gz: 88b02a01b90bbfe65077bf9b0318ad95559a3933cd735f4e9bb11eee254864479f20cb15edb52b3f3ba6b972e779f4367318742b2d165498161779628ec64643
7
- data.tar.gz: 30c8ea708f0b32d17c0a621cb7251a7eb1ea34450ceb3036340bd9989a86dc294aedab892030b72def482e3690fc16669457233b60471d2c4a6eb325d15b1b4f
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module MTProto
4
- VERSION = '0.0.1'
5
- end
4
+ VERSION = '0.0.2'
5
+ end
data/lib/mtproto.rb ADDED
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'mtproto/version'
4
+ require_relative 'mtproto/transport/abridged_packet_codec'
5
+
6
+ module MTProto
7
+ end
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.1
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: