Class: Std_msgs::ByteMultiArray

Inherits:
ROS::Message
  • Object
show all
Defined in:
lib/std_msgs/ByteMultiArray.rb

Constant Summary collapse

@@struct_L2 =
::ROS::Struct.new("L2")
@@struct_L =
::ROS::Struct.new("L")
@@slot_types =
['std_msgs/MultiArrayLayout','byte[]']

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args = {}) ⇒ ByteMultiArray

Constructor. You can set the default values using keyword operators.

Parameters:

  • args (Hash) (defaults to: {})

    keyword for initializing values

Options Hash (args):

  • :layout (std_msgs/MultiArrayLayout)

    initialize value

  • :data (byte[])

    initialize value



77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/std_msgs/ByteMultiArray.rb', line 77

def initialize(args={})
  # message fields cannot be None, assign default values for those that are
  if args[:layout]
    @layout = args[:layout]
  else
    @layout = Std_msgs::MultiArrayLayout.new
  end
  if args[:data]
    @data = args[:data]
  else
    @data = []
  end
end

Instance Attribute Details

#dataObject

Returns the value of attribute data.



65
66
67
# File 'lib/std_msgs/ByteMultiArray.rb', line 65

def data
  @data
end

#layoutObject

Returns the value of attribute layout.



65
66
67
# File 'lib/std_msgs/ByteMultiArray.rb', line 65

def layout
  @layout
end

Class Method Details

.md5sumObject



10
11
12
# File 'lib/std_msgs/ByteMultiArray.rb', line 10

def self.md5sum
  "70ea476cbcfd65ac2f68f3cda1e891fe"
end

.typeObject



14
15
16
# File 'lib/std_msgs/ByteMultiArray.rb', line 14

def self.type
  "std_msgs/ByteMultiArray"
end

Instance Method Details

#_get_typesString

internal API method

Returns:

  • (String)

    Message type string.



93
94
95
# File 'lib/std_msgs/ByteMultiArray.rb', line 93

def _get_types
  @slot_types
end

#deserialize(str) ⇒ Object

unpack serialized message in str into this message instance

@param [String] str: byte array of serialized message


123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
# File 'lib/std_msgs/ByteMultiArray.rb', line 123

def deserialize(str)

  begin
    if @layout == nil
      @layout = Std_msgs::MultiArrayLayout.new
    end
    end_point = 0
    start = end_point
    end_point += 4
    (length,) = @@struct_L.unpack(str[start..(end_point-1)])
    @layout.dim = []
    length.times do
      val1 = Std_msgs::MultiArrayDimension.new
      start = end_point
      end_point += 4
      (length,) = @@struct_L.unpack(str[start..(end_point-1)])
      start = end_point
      end_point += length
      val1.label = str[start..(end_point-1)]
      _x = val1
      start = end_point
      end_point += ROS::Struct::calc_size('L2')
      (_x.size, _x.stride,) = @@struct_L2.unpack(str[start..(end_point-1)])
      @layout.dim.push(val1)
    end
    start = end_point
    end_point += ROS::Struct::calc_size('L')
    (@layout.data_offset,) = @@struct_L.unpack(str[start..(end_point-1)])
    start = end_point
    end_point += 4
    (length,) = @@struct_L.unpack(str[start..(end_point-1)])
    pattern = "c#{length}"
    start = end_point
    end_point += ROS::Struct::calc_size("#{pattern}")
    @data = str[start..(end_point-1)].unpack(pattern)
    return self
  rescue => exception
    raise "message DeserializationError: #{exception}" #most likely buffer underfill
  end
end

#has_header?Boolean

Returns:

  • (Boolean)


18
19
20
# File 'lib/std_msgs/ByteMultiArray.rb', line 18

def has_header?
  false
end

#message_definitionObject



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/std_msgs/ByteMultiArray.rb', line 22

def message_definition
  "# Please look at the MultiArrayLayout message definition for
# documentation on all multiarrays.

MultiArrayLayout  layout        # specification of data layout
byte[]            data          # array of data


================================================================================
MSG: std_msgs/MultiArrayLayout
# The multiarray declares a generic multi-dimensional array of a
# particular data type.  Dimensions are ordered from outer most
# to inner most.

MultiArrayDimension[] dim # Array of dimension properties
uint32 data_offset        # padding bytes at front of data

# Accessors should ALWAYS be written in terms of dimension stride
# and specified outer-most dimension first.
# 
# multiarray(i,j,k) = data[data_offset + dim_stride[1]*i + dim_stride[2]*j + k]
#
# A standard, 3-channel 640x480 image with interleaved color channels
# would be specified as:
#
# dim[0].label  = \"height\"
# dim[0].size   = 480
# dim[0].stride = 3*640*480 = 921600  (note dim[0] stride is just size of image)
# dim[1].label  = \"width\"
# dim[1].size   = 640
# dim[1].stride = 3*640 = 1920
# dim[2].label  = \"channel\"
# dim[2].size   = 3
# dim[2].stride = 3
#
# multiarray(i,j,k) refers to the ith row, jth column, and kth channel.
================================================================================
MSG: std_msgs/MultiArrayDimension
string label   # label of given dimension
uint32 size    # size of given dimension (in type units)
uint32 stride  # stride of given dimension
"
end

#serialize(buff) ⇒ Object

serialize message into buffer

Parameters:

  • buff (IO)

    buffer



99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
# File 'lib/std_msgs/ByteMultiArray.rb', line 99

def serialize(buff)
  begin
    length = @layout.dim.length
    buff.write(@@struct_L.pack(length))
    for val1 in @layout.dim
      _x = val1.label
      length = _x.length
      buff.write([length, _x].pack("La#{length}"))
      _x = val1
      buff.write(@@struct_L2.pack(_x.size, _x.stride))
    end
    buff.write(@@struct_L.pack(@layout.data_offset))
    length = @data.length
    buff.write(@@struct_L.pack(length))
    pattern = "c#{length}"
    buff.write(*@data.pack(pattern))
  rescue => exception
    raise "some erro in serialize: #{exception}"

  end
end