Class: Takagi::Message::Base
- Inherits:
-
Object
- Object
- Takagi::Message::Base
- Defined in:
- lib/takagi/message/base.rb
Overview
Base class for message
Instance Attribute Summary collapse
-
#code ⇒ Object
readonly
Returns the value of attribute code.
-
#message_id ⇒ Object
readonly
Returns the value of attribute message_id.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#payload ⇒ Object
readonly
Returns the value of attribute payload.
-
#token ⇒ Object
readonly
Returns the value of attribute token.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
-
#version ⇒ Object
readonly
Returns the value of attribute version.
Instance Method Summary collapse
-
#coap_code_to_method(code) ⇒ String
Convert CoAP code number to method name using registry.
-
#coap_method_to_code(method) ⇒ Integer
Convert method name to CoAP code number using registry.
-
#initialize(data = nil, transport: :udp) ⇒ Base
constructor
A new instance of Base.
Constructor Details
#initialize(data = nil, transport: :udp) ⇒ Base
Returns a new instance of Base.
9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/takagi/message/base.rb', line 9 def initialize(data = nil, transport: :udp) @transport = transport if data.is_a?(String) || data.is_a?(IO) case transport when :tcp parse_tcp(data) else parse(data) end end @data = data @logger = Takagi.logger end |
Instance Attribute Details
#code ⇒ Object (readonly)
Returns the value of attribute code.
7 8 9 |
# File 'lib/takagi/message/base.rb', line 7 def code @code end |
#message_id ⇒ Object (readonly)
Returns the value of attribute message_id.
7 8 9 |
# File 'lib/takagi/message/base.rb', line 7 def @message_id end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
7 8 9 |
# File 'lib/takagi/message/base.rb', line 7 def @options end |
#payload ⇒ Object (readonly)
Returns the value of attribute payload.
7 8 9 |
# File 'lib/takagi/message/base.rb', line 7 def payload @payload end |
#token ⇒ Object (readonly)
Returns the value of attribute token.
7 8 9 |
# File 'lib/takagi/message/base.rb', line 7 def token @token end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
7 8 9 |
# File 'lib/takagi/message/base.rb', line 7 def type @type end |
#version ⇒ Object (readonly)
Returns the value of attribute version.
7 8 9 |
# File 'lib/takagi/message/base.rb', line 7 def version @version end |
Instance Method Details
#coap_code_to_method(code) ⇒ String
Convert CoAP code number to method name using registry
26 27 28 29 30 31 32 33 34 |
# File 'lib/takagi/message/base.rb', line 26 def coap_code_to_method(code) # Check if it's an OBSERVE request (GET with Observe option) if code == CoAP::Registries::Method::GET && @options && @options[CoAP::Registries::Option::OBSERVE] 'OBSERVE' else # Use CoAP registry to convert code to string CoAP::CodeHelpers.to_string(code) end end |
#coap_method_to_code(method) ⇒ Integer
Convert method name to CoAP code number using registry
39 40 41 |
# File 'lib/takagi/message/base.rb', line 39 def coap_method_to_code(method) CoAP::CodeHelpers.to_numeric(method) end |