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
128 129 130 |
# File 'lib/serialize.rb', line 128 def fmt @fmt end |
#id ⇒ Object
Returns the value of attribute id
128 129 130 |
# File 'lib/serialize.rb', line 128 def id @id end |
#names ⇒ Object
Returns the value of attribute names
128 129 130 |
# File 'lib/serialize.rb', line 128 def names @names end |
#types ⇒ Object
Returns the value of attribute types
128 129 130 |
# File 'lib/serialize.rb', line 128 def types @types end |
Class Method Details
.unpack_recipe(buf) ⇒ Object
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 |
# File 'lib/serialize.rb', line 129 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
163 164 165 166 |
# File 'lib/serialize.rb', line 163 def pack(state) l = state.pack(self.names, self.types) l.pack(self.fmt) end |
#unpack(data) ⇒ Object
168 169 170 171 |
# File 'lib/serialize.rb', line 168 def unpack(data) li = data.unpack(self.fmt) DataObject.unpack(li, self.names, self.types) end |