Class: Samsung::Protocol::Frame
- Inherits:
-
Object
- Object
- Samsung::Protocol::Frame
- Defined in:
- lib/samsung/protocol/frame.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#data ⇒ Object
Returns the value of attribute data.
Instance Method Summary collapse
- #hex ⇒ Object
-
#initialize(data = '') ⇒ Frame
constructor
A new instance of Frame.
- #pop_frame ⇒ Object
- #pop_int16 ⇒ Object
- #pop_int32 ⇒ Object
- #pop_int8 ⇒ Object
- #pop_string ⇒ Object
- #pop_string64 ⇒ Object
-
#push_frame(frame) ⇒ Object
Frames.
-
#push_int16(v) ⇒ Object
16-bit integer.
-
#push_int32(v) ⇒ Object
32-bit integer.
-
#push_int8(v) ⇒ Object
8-bit integer.
-
#push_string(s) ⇒ Object
String.
-
#push_string64(s) ⇒ Object
Base64 string.
- #size ⇒ Object
Constructor Details
#initialize(data = '') ⇒ Frame
Returns a new instance of Frame.
8 9 10 |
# File 'lib/samsung/protocol/frame.rb', line 8 def initialize data = '' @data = data end |
Instance Attribute Details
#data ⇒ Object
Returns the value of attribute data.
6 7 8 |
# File 'lib/samsung/protocol/frame.rb', line 6 def data @data end |
Instance Method Details
#hex ⇒ Object
16 17 18 19 20 |
# File 'lib/samsung/protocol/frame.rb', line 16 def hex data.split('').map do |c| "0x%.2x" % c.ord end.join(' ') end |
#pop_frame ⇒ Object
82 83 84 85 |
# File 'lib/samsung/protocol/frame.rb', line 82 def pop_frame frame_size = pop_int16 Frame.new(data.slice!(0..frame_size-1)) end |
#pop_int16 ⇒ Object
61 62 63 |
# File 'lib/samsung/protocol/frame.rb', line 61 def pop_int16 data.slice!(0..1).unpack('S<').first end |
#pop_int32 ⇒ Object
71 72 73 |
# File 'lib/samsung/protocol/frame.rb', line 71 def pop_int32 data.slice!(0..1).unpack('L<').first end |
#pop_int8 ⇒ Object
51 52 53 |
# File 'lib/samsung/protocol/frame.rb', line 51 def pop_int8 data.slice!(0).unpack('C').first end |
#pop_string ⇒ Object
29 30 31 32 |
# File 'lib/samsung/protocol/frame.rb', line 29 def pop_string len = pop_int16 data.slice!(0..len-1) end |
#pop_string64 ⇒ Object
40 41 42 43 |
# File 'lib/samsung/protocol/frame.rb', line 40 def pop_string64 len = pop_int16 Base64.decode64(data.slice!(0..len-1)) end |
#push_frame(frame) ⇒ Object
Frames
77 78 79 80 |
# File 'lib/samsung/protocol/frame.rb', line 77 def push_frame(frame) push_int16(frame.size) self.data += frame.data end |
#push_int16(v) ⇒ Object
16-bit integer
57 58 59 |
# File 'lib/samsung/protocol/frame.rb', line 57 def push_int16(v) self.data += [v].pack('S<') end |
#push_int32(v) ⇒ Object
32-bit integer
67 68 69 |
# File 'lib/samsung/protocol/frame.rb', line 67 def push_int32(v) self.data += [v].pack('L<') end |
#push_int8(v) ⇒ Object
8-bit integer
47 48 49 |
# File 'lib/samsung/protocol/frame.rb', line 47 def push_int8(v) self.data += [v].pack('C') end |
#push_string(s) ⇒ Object
String
24 25 26 27 |
# File 'lib/samsung/protocol/frame.rb', line 24 def push_string(s) push_int16(s.size) self.data += s end |
#push_string64(s) ⇒ Object
Base64 string
36 37 38 |
# File 'lib/samsung/protocol/frame.rb', line 36 def push_string64(s) push_string(Base64.encode64(s)) end |
#size ⇒ Object
12 13 14 |
# File 'lib/samsung/protocol/frame.rb', line 12 def size @data.size end |