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

- (Struct) initialize(format)

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

- (String) format (readonly)

get the format string.

Returns:

  • (String)

    format string.



33
34
35
# File 'lib/ros/message.rb', line 33

def format
  @format
end

Class Method Details

+ (Integer) calc_size(format)

Calc the size

Parameters:

  • format (String)

    format string to calculate.

Returns:

  • (Integer)

    size of this format (byte).



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/ros/message.rb', line 39

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

- (Object) pack(*args)

pack the data

Parameters:

  • args (Array)


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

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

- (Array) unpack(arg)

unpack from string

Parameters:

  • arg (String)

Returns:

  • (Array)

    unpacked data



67
68
69
# File 'lib/ros/message.rb', line 67

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