Class: UR::Serialize::DataConfig

Inherits:
Struct
  • Object
show all
Defined in:
lib/serialize.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#fmtObject

Returns the value of attribute fmt

Returns:

  • (Object)

    the current value of fmt



130
131
132
# File 'lib/serialize.rb', line 130

def fmt
  @fmt
end

#idObject

Returns the value of attribute id

Returns:

  • (Object)

    the current value of id



130
131
132
# File 'lib/serialize.rb', line 130

def id
  @id
end

#namesObject

Returns the value of attribute names

Returns:

  • (Object)

    the current value of names



130
131
132
# File 'lib/serialize.rb', line 130

def names
  @names
end

#typesObject

Returns the value of attribute types

Returns:

  • (Object)

    the current value of types



130
131
132
# File 'lib/serialize.rb', line 130

def types
  @types
end

Class Method Details

.unpack_recipe(buf) ⇒ Object



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
163
164
# File 'lib/serialize.rb', line 131

def self.unpack_recipe(buf)
  rmd = DataConfig.new
  rmd.id = buf.unpack('C')[0]
  rmd.types = buf[1..-1].split(',')
  rmd.fmt = 'C'
  rmd.types.each do |i|
    if i == 'INT32'
      rmd.fmt += 'i>'
    elsif i == 'UINT32'
      rmd.fmt += 'I>'
    elsif i == 'VECTOR6D'
      rmd.fmt += 'G'*6
    elsif i == 'VECTOR3D'
      rmd.fmt += 'G'*3
    elsif i == 'VECTOR6INT32'
      rmd.fmt += 'i>'*6
    elsif i == 'VECTOR6UINT32'
      rmd.fmt += 'I>'*6
    elsif i == 'DOUBLE'
      rmd.fmt += 'G'
    elsif i == 'UINT64'
      rmd.fmt += 'Q>'
    elsif i == 'UINT8'
      rmd.fmt += 'C'
    elsif i == 'BOOL'
      rmd.fmt += '?'
    elsif i == 'IN_USE'
      #raise TypeError 'An input parameter is already in use.'
    else
      #raise TypeError 'Unknown data type: ' + i
    end
  end
  rmd
end

Instance Method Details

#pack(state) ⇒ Object



166
167
168
169
# File 'lib/serialize.rb', line 166

def pack(state)
  l = state.pack(self.names, self.types)
  l.pack(self.fmt)
end

#unpack(data) ⇒ Object



171
172
173
174
# File 'lib/serialize.rb', line 171

def unpack(data)
  li = data.unpack(self.fmt)
  DataObject.unpack(li, self.names, self.types)
end