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: TimeoutError
Constant Summary collapse
- DEFAULT_READ_TIMEOUT =
3- MAX_RECV_LEN =
1024 * 1024
- SUCCEED_CODE =
0
Instance Attribute Summary collapse
-
#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.
20 21 22 23 24 |
# File 'lib/mc_protocol_e/frame_1e/response.rb', line 20 def initialize(raw_res) @sub_header = raw_res[0] @code = raw_res[1].unpack1("C") @data = raw_res[2..-1] || "" end |
Instance Attribute Details
#data ⇒ Object (readonly)
Returns the value of attribute data.
16 17 18 |
# File 'lib/mc_protocol_e/frame_1e/response.rb', line 16 def data @data end |
Class Method Details
.recv(socket, read_timeout = DEFAULT_READ_TIMEOUT) ⇒ Responce
Receives responce and returns.
30 31 32 33 34 35 36 |
# File 'lib/mc_protocol_e/frame_1e/response.rb', line 30 def self.recv(socket, read_timeout = DEFAULT_READ_TIMEOUT) selected = IO.select([socket], nil, nil, read_timeout) raise TimeoutError unless selected raw_res = socket.recv(MAX_RECV_LEN) new(raw_res) end |
Instance Method Details
#failed? ⇒ Boolean
Returns true if a command failed.
44 45 46 |
# File 'lib/mc_protocol_e/frame_1e/response.rb', line 44 def failed? !succeed? end |
#succeed? ⇒ Boolean
Returns true if a command succeed.
39 40 41 |
# File 'lib/mc_protocol_e/frame_1e/response.rb', line 39 def succeed? code == SUCCEED_CODE end |