Class: McProtocolE::Frame1e::Response
- Inherits:
-
Object
- Object
- McProtocolE::Frame1e::Response
- Defined in:
- lib/mc_protocol_e/frame_1e/response.rb
Overview
This class shows a responce of MC protocol.
Defined Under Namespace
Classes: InvalidResponseError, ReadTimeoutError
Constant Summary collapse
- DEFAULT_READ_TIMEOUT =
3- MAX_RECV_LEN =
1024 * 1024
- SUCCEED_CODE =
0
Instance Attribute Summary collapse
-
#code ⇒ Object
readonly
Returns the value of attribute code.
-
#data ⇒ Object
readonly
Returns the value of attribute data.
Class Method Summary collapse
-
.recv(socket, read_timeout = DEFAULT_READ_TIMEOUT) ⇒ Responce
Receives responce and returns.
Instance Method Summary collapse
-
#failed? ⇒ Boolean
Returns true if a command failed.
-
#initialize(raw_res) ⇒ Response
constructor
Constructor.
-
#succeed? ⇒ Boolean
Returns true if a command succeed.
Constructor Details
#initialize(raw_res) ⇒ Response
Constructor.
21 22 23 24 25 |
# File 'lib/mc_protocol_e/frame_1e/response.rb', line 21 def initialize(raw_res) @sub_header = raw_res[0] @code = raw_res[1]&.unpack1("C") @data = raw_res[2..-1] || "" end |
Instance Attribute Details
#code ⇒ Object (readonly)
Returns the value of attribute code.
17 18 19 |
# File 'lib/mc_protocol_e/frame_1e/response.rb', line 17 def code @code end |
#data ⇒ Object (readonly)
Returns the value of attribute data.
17 18 19 |
# File 'lib/mc_protocol_e/frame_1e/response.rb', line 17 def data @data end |
Class Method Details
.recv(socket, read_timeout = DEFAULT_READ_TIMEOUT) ⇒ Responce
Receives responce and returns.
33 34 35 36 37 38 39 40 41 |
# File 'lib/mc_protocol_e/frame_1e/response.rb', line 33 def self.recv(socket, read_timeout = DEFAULT_READ_TIMEOUT) selected = IO.select([socket], nil, nil, read_timeout) raise ReadTimeoutError unless selected raw_res = socket.recv(MAX_RECV_LEN) res = new(raw_res) raise InvalidResponseError if res.code.nil? res end |
Instance Method Details
#failed? ⇒ Boolean
Returns true if a command failed.
49 50 51 |
# File 'lib/mc_protocol_e/frame_1e/response.rb', line 49 def failed? !succeed? end |
#succeed? ⇒ Boolean
Returns true if a command succeed.
44 45 46 |
# File 'lib/mc_protocol_e/frame_1e/response.rb', line 44 def succeed? code == SUCCEED_CODE end |