Class: David::Exchange
- Inherits:
-
Struct
- Object
- Struct
- David::Exchange
- Includes:
- Registry
- Defined in:
- lib/david/exchange.rb
Instance Attribute Summary collapse
-
#ancillary ⇒ Object
Returns the value of attribute ancillary.
-
#host ⇒ Object
Returns the value of attribute host.
-
#message ⇒ Object
Returns the value of attribute message.
-
#options ⇒ Object
Returns the value of attribute options.
-
#port ⇒ Object
Returns the value of attribute port.
Instance Method Summary collapse
- #accept ⇒ Object
- #ack? ⇒ Boolean
- #block ⇒ Object
- #cbor? ⇒ Boolean
- #con? ⇒ Boolean
- #delete? ⇒ Boolean
- #etag ⇒ Object
- #get? ⇒ Boolean
- #get_etag? ⇒ Boolean
- #idempotent? ⇒ Boolean
- #key ⇒ Object
- #mid ⇒ Object
- #multicast? ⇒ Boolean
- #non? ⇒ Boolean
- #observe? ⇒ Boolean
- #ping? ⇒ Boolean
- #post? ⇒ Boolean
- #proxy? ⇒ Boolean
- #put? ⇒ Boolean
- #reliable? ⇒ Boolean
- #request? ⇒ Boolean
- #response? ⇒ Boolean
- #rst? ⇒ Boolean
- #separate? ⇒ Boolean
- #to_s ⇒ Object
- #token ⇒ Object
- #valid_method? ⇒ Boolean
Instance Attribute Details
#ancillary ⇒ Object
Returns the value of attribute ancillary
2 3 4 |
# File 'lib/david/exchange.rb', line 2 def ancillary @ancillary end |
#host ⇒ Object
Returns the value of attribute host
2 3 4 |
# File 'lib/david/exchange.rb', line 2 def host @host end |
#message ⇒ Object
Returns the value of attribute message
2 3 4 |
# File 'lib/david/exchange.rb', line 2 def @message end |
#options ⇒ Object
Returns the value of attribute options
2 3 4 |
# File 'lib/david/exchange.rb', line 2 def @options end |
#port ⇒ Object
Returns the value of attribute port
2 3 4 |
# File 'lib/david/exchange.rb', line 2 def port @port end |
Instance Method Details
#accept ⇒ Object
5 6 7 |
# File 'lib/david/exchange.rb', line 5 def accept .[:accept] end |
#ack? ⇒ Boolean
9 10 11 |
# File 'lib/david/exchange.rb', line 9 def ack? .tt == :ack end |
#block ⇒ Object
13 14 15 16 17 18 19 |
# File 'lib/david/exchange.rb', line 13 def block @block ||= if .[:block2].nil? CoAP::Block.new(0, false, 1024) else CoAP::Block.new(.[:block2]).decode end end |
#cbor? ⇒ Boolean
21 22 23 |
# File 'lib/david/exchange.rb', line 21 def cbor? .[:content_format] == 60 end |
#con? ⇒ Boolean
25 26 27 |
# File 'lib/david/exchange.rb', line 25 def con? .tt == :con end |
#delete? ⇒ Boolean
29 30 31 |
# File 'lib/david/exchange.rb', line 29 def delete? .mcode == :delete end |
#etag ⇒ Object
33 34 35 |
# File 'lib/david/exchange.rb', line 33 def etag .[:etag] end |
#get? ⇒ Boolean
41 42 43 |
# File 'lib/david/exchange.rb', line 41 def get? .mcode == :get end |
#get_etag? ⇒ Boolean
37 38 39 |
# File 'lib/david/exchange.rb', line 37 def get_etag? .[:etag].nil? && get? end |
#idempotent? ⇒ Boolean
45 46 47 |
# File 'lib/david/exchange.rb', line 45 def idempotent? get? || put? || delete? end |
#key ⇒ Object
49 50 51 |
# File 'lib/david/exchange.rb', line 49 def key [host, mid] end |
#mid ⇒ Object
53 54 55 |
# File 'lib/david/exchange.rb', line 53 def mid .mid end |
#multicast? ⇒ Boolean
57 58 59 60 61 62 63 64 65 66 |
# File 'lib/david/exchange.rb', line 57 def multicast? a = ancillary return false if a.nil? return @multicast unless @multicast.nil? @multicast = a.cmsg_is?(:IP, :PKTINFO) && a.ip_pktinfo[0].ipv4_multicast? || a.cmsg_is?(:IPV6, :PKTINFO) && a.ipv6_pktinfo[0].ipv6_multicast? end |
#non? ⇒ Boolean
68 69 70 |
# File 'lib/david/exchange.rb', line 68 def non? .tt == :non end |
#observe? ⇒ Boolean
72 73 74 |
# File 'lib/david/exchange.rb', line 72 def observe? !.[:observe].nil? end |
#ping? ⇒ Boolean
76 77 78 |
# File 'lib/david/exchange.rb', line 76 def ping? con? && .mcode == [0, 0] end |
#post? ⇒ Boolean
80 81 82 |
# File 'lib/david/exchange.rb', line 80 def post? .mcode == :post end |
#proxy? ⇒ Boolean
84 85 86 |
# File 'lib/david/exchange.rb', line 84 def proxy? !(.[:proxy_uri].nil? && .[:proxy_scheme].nil?) end |
#put? ⇒ Boolean
88 89 90 |
# File 'lib/david/exchange.rb', line 88 def put? .mcode == :put end |
#reliable? ⇒ Boolean
92 93 94 |
# File 'lib/david/exchange.rb', line 92 def reliable? con? || ack? end |
#request? ⇒ Boolean
96 97 98 |
# File 'lib/david/exchange.rb', line 96 def request? con? || non? end |
#response? ⇒ Boolean
100 101 102 |
# File 'lib/david/exchange.rb', line 100 def response? ack? || rst? end |
#rst? ⇒ Boolean
104 105 106 |
# File 'lib/david/exchange.rb', line 104 def rst? .tt == :rst end |
#separate? ⇒ Boolean
108 109 110 |
# File 'lib/david/exchange.rb', line 108 def separate? ack? && .payload.empty? && .mcode == [0, 0] end |
#to_s ⇒ Object
112 113 114 |
# File 'lib/david/exchange.rb', line 112 def to_s "[#{host}]:#{port}: #{} (block #{block.num})" end |
#token ⇒ Object
116 117 118 |
# File 'lib/david/exchange.rb', line 116 def token .[:token] end |
#valid_method? ⇒ Boolean
120 121 122 |
# File 'lib/david/exchange.rb', line 120 def valid_method? CoAP::METHODS.include?(.mcode) end |