mc_protocol_e 0.2.0 → 0.2.1
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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6f1eb81025fec386b36239f57a0271e0261937f7e69d25de0765be4a409672b0
|
4
|
+
data.tar.gz: dca38db8e93cb622a50574d6785be2fc82b1973b4d4ba44a978195eb70e2744b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 01c3e7fb163f167afd923518aafd6bb8b0f71292ad50b582e84dcffc9088801820c66ea7a5c6dc1f2c7e36f19220e2b7530423e42b41e633d9475c7df854834c
|
7
|
+
data.tar.gz: c31e38139f275da1f834be0b213dd746200d022bf4ec1fa308133bcb9ef39e91b372581102b83f157208d742410a00e4ce756de8c8fe01adc5ff6f39ae96f94f
|
@@ -7,19 +7,20 @@ module McProtocolE
|
|
7
7
|
# This class shows a responce of MC protocol.
|
8
8
|
class Response
|
9
9
|
|
10
|
-
class
|
10
|
+
class ReadTimeoutError < Timeout::Error; end
|
11
|
+
class InvalidResponseError < StandardError; end
|
11
12
|
|
12
13
|
DEFAULT_READ_TIMEOUT = 3
|
13
14
|
MAX_RECV_LEN = 1024 * 1024
|
14
15
|
SUCCEED_CODE = 0
|
15
16
|
|
16
|
-
attr_reader :data
|
17
|
+
attr_reader :code, :data
|
17
18
|
|
18
19
|
# Constructor.
|
19
20
|
# @param [String] raw_res binary string of response
|
20
21
|
def initialize(raw_res)
|
21
22
|
@sub_header = raw_res[0]
|
22
|
-
@code = raw_res[1]
|
23
|
+
@code = raw_res[1]&.unpack1("C")
|
23
24
|
@data = raw_res[2..-1] || ""
|
24
25
|
end
|
25
26
|
|
@@ -27,12 +28,16 @@ module McProtocolE
|
|
27
28
|
# @param [IO] socket TCP socket
|
28
29
|
# @param [Integer] read_timeout read timeout second
|
29
30
|
# @return [Responce] received a response
|
31
|
+
# @raise [ReadTimeoutError] occurred timeout when response read
|
32
|
+
# @raise [InvalidResponseError] when response is invalid mc protocol format
|
30
33
|
def self.recv(socket, read_timeout = DEFAULT_READ_TIMEOUT)
|
31
34
|
selected = IO.select([socket], nil, nil, read_timeout)
|
32
|
-
raise
|
35
|
+
raise ReadTimeoutError unless selected
|
33
36
|
|
34
37
|
raw_res = socket.recv(MAX_RECV_LEN)
|
35
|
-
new(raw_res)
|
38
|
+
res = new(raw_res)
|
39
|
+
raise InvalidResponseError if res.code.nil?
|
40
|
+
res
|
36
41
|
end
|
37
42
|
|
38
43
|
# Returns true if a command succeed.
|
@@ -45,10 +50,6 @@ module McProtocolE
|
|
45
50
|
!succeed?
|
46
51
|
end
|
47
52
|
|
48
|
-
private
|
49
|
-
|
50
|
-
attr_reader :code
|
51
|
-
|
52
53
|
end
|
53
54
|
end
|
54
55
|
end
|
@@ -7,7 +7,8 @@ module McProtocolE
|
|
7
7
|
# This class shows a responce of MC protocol.
|
8
8
|
class Response
|
9
9
|
|
10
|
-
class
|
10
|
+
class ReadTimeoutError < Timeout::Error; end
|
11
|
+
class InvalidResponseError < StandardError; end
|
11
12
|
|
12
13
|
DEFAULT_READ_TIMEOUT = 3
|
13
14
|
SUB_HEADER = "\xD0\x00".b
|
@@ -22,7 +23,7 @@ module McProtocolE
|
|
22
23
|
@sub_header = raw_res[0..1]
|
23
24
|
@access_route = raw_res[2..6]
|
24
25
|
@response_len = raw_res[7..8]
|
25
|
-
@code = raw_res[9..10]
|
26
|
+
@code = raw_res[9..10]&.unpack1("v")
|
26
27
|
@data = raw_res[11..-1] || ""
|
27
28
|
end
|
28
29
|
|
@@ -30,12 +31,16 @@ module McProtocolE
|
|
30
31
|
# @param [IO] socket TCP socket
|
31
32
|
# @param [Integer] read_timeout read timeout second
|
32
33
|
# @return [Responce] received a response
|
34
|
+
# @raise [ReadTimeoutError] occurred timeout when response read
|
35
|
+
# @raise [InvalidResponseError] when response is invalid mc protocol format
|
33
36
|
def self.recv(socket, read_timeout = DEFAULT_READ_TIMEOUT)
|
34
37
|
selected = IO.select([socket], nil, nil, read_timeout)
|
35
|
-
raise
|
38
|
+
raise ReadTimeoutError unless selected
|
36
39
|
|
37
40
|
raw_res = socket.recv(MAX_RECV_LEN)
|
38
|
-
new(raw_res)
|
41
|
+
res = new(raw_res)
|
42
|
+
raise InvalidResponseError if res.code.nil?
|
43
|
+
res
|
39
44
|
end
|
40
45
|
|
41
46
|
# Returns true if a command succeed.
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mc_protocol_e
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- commis1059
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-09-
|
11
|
+
date: 2019-09-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|