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
130 131 132 |
# File 'lib/serialize.rb', line 130 def fmt @fmt end |
#id ⇒ Object
Returns the value of attribute id
130 131 132 |
# File 'lib/serialize.rb', line 130 def id @id end |
#names ⇒ Object
Returns the value of attribute names
130 131 132 |
# File 'lib/serialize.rb', line 130 def names @names end |
#types ⇒ Object
Returns the value of attribute 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 |