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



137
138
139
# File 'lib/serialize.rb', line 137

def fmt
  @fmt
end

#idObject

Returns the value of attribute id

Returns:

  • (Object)

    the current value of id



137
138
139
# File 'lib/serialize.rb', line 137

def id
  @id
end

#namesObject

Returns the value of attribute names

Returns:

  • (Object)

    the current value of names



137
138
139
# File 'lib/serialize.rb', line 137

def names
  @names
end

#typesObject

Returns the value of attribute types

Returns:

  • (Object)

    the current value of types



137
138
139
# File 'lib/serialize.rb', line 137

def types
  @types
end

Class Method Details

.unpack_recipe(buf) ⇒ Object



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
165
166
167
168
169
170
# File 'lib/serialize.rb', line 138

def self.unpack_recipe(buf)
  rmd = DataConfig.new
  rmd.id = buf.unpack('C')[0]
  rmd.types = buf[1..-1].split(',')
  rmd.fmt = 'C'
  p rmd.types
  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 == '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



172
173
174
175
176
177
178
# File 'lib/serialize.rb', line 172

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

#unpack(data) ⇒ Object



180
181
182
183
# File 'lib/serialize.rb', line 180

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