Class: UR::Serialize::DataConfig
- Inherits:
-
Struct
- Object
- Struct
- UR::Serialize::DataConfig
- Defined in:
- lib/serialize.rb
Instance Attribute Summary collapse
-
#fmt ⇒ Object
Returns the value of attribute fmt.
-
#id ⇒ Object
Returns the value of attribute id.
-
#names ⇒ Object
Returns the value of attribute names.
-
#types ⇒ Object
Returns the value of attribute types.
Class Method Summary collapse
Instance Method Summary collapse
Instance Attribute Details
#fmt ⇒ Object
Returns the value of attribute fmt
137 138 139 |
# File 'lib/serialize.rb', line 137 def fmt @fmt end |
#id ⇒ Object
Returns the value of attribute id
137 138 139 |
# File 'lib/serialize.rb', line 137 def id @id end |
#names ⇒ Object
Returns the value of attribute names
137 138 139 |
# File 'lib/serialize.rb', line 137 def names @names end |
#types ⇒ Object
Returns the value of attribute 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 |