Class: ROS::Struct

Inherits:
Object
  • Object
show all
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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(format) ⇒ Struct

Returns a new instance of Struct.

Parameters:

  • format (String)


26
27
28
# File 'lib/ros/message.rb', line 26

def initialize(format)
  @format = format
end

Instance Attribute Details

#formatObject (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

Parameters:

  • args (Array)


53
54
55
# File 'lib/ros/message.rb', line 53

def pack(*args)
  args.pack(@format)
end

#unpack(arg) ⇒ Array

unpack from string

Parameters:

  • arg (String)

Returns:

  • (Array)

    unpacked data



60
61
62
# File 'lib/ros/message.rb', line 60

def unpack(arg)
  arg.unpack(@format)
end