Class: ROS::Struct
- Inherits:
-
Object
- Object
- ROS::Struct
- Defined in:
- lib/ros/message.rb
Overview
used for serialization (for python like grammar) this is used by msg/srv converted *.rb files it can be removed, if there are more effective genmsg_ruby.
Instance Attribute Summary collapse
-
#format ⇒ Object
readonly
Returns the value of attribute format.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(format) ⇒ Struct
constructor
A new instance of Struct.
-
#pack(*args) ⇒ Object
pack the data.
-
#unpack(arg) ⇒ Array
unpack from string.
Constructor Details
#initialize(format) ⇒ Struct
Returns a new instance of Struct.
26 27 28 |
# File 'lib/ros/message.rb', line 26 def initialize(format) @format = format end |
Instance Attribute Details
#format ⇒ Object (readonly)
Returns the value of attribute format.
30 31 32 |
# File 'lib/ros/message.rb', line 30 def format @format end |
Class Method Details
.calc_size(format) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/ros/message.rb', line 32 def self.calc_size(format) array = [] start = 0 while start < format.length re = /(\w)(\d*)/ re =~ format[start..(format.length-1)] number = $2.to_i if number == 0 array.push(0) else for i in 1..number array.push(0) end end start += $&.length end array.pack(format).length end |
Instance Method Details
#pack(*args) ⇒ Object
pack the data
53 54 55 |
# File 'lib/ros/message.rb', line 53 def pack(*args) args.pack(@format) end |
#unpack(arg) ⇒ Array
unpack from string
60 61 62 |
# File 'lib/ros/message.rb', line 60 def unpack(arg) arg.unpack(@format) end |