Class: Depix::Binary::Fields::R32Field

Inherits:
Field
  • Object
show all
Defined in:
lib/depix/binary/fields.rb

Overview

real32 field. Now, there is some lap dancing to be done here. The DPX files in the wild define nonexistant data as a charfield with all it’s bits set (four times 0xFF byte). This is easy to verify with a string but practically useless once the charfield has been unpacked into a float. Therefore we first unpack the value as a charfield, then we check whether it’s all blanking, and if it is we return nil. If it’s not “all bits set” though what we will do is try to decode it again using the real float unpack pattern. The same dance happens reciprocally when repacking the data.

Constant Summary collapse

BLANK =
(0xFF.chr * 4)
PATTERN_BE =
"g"
PATTERN_LE =
"n"

Instance Attribute Summary

Attributes inherited from Field

#desc, #name, #req

Instance Method Summary collapse

Methods inherited from Field

#consume!, #explain, #initialize, #validate!

Constructor Details

This class inherits a constructor from Depix::Binary::Fields::Field

Instance Method Details

#clean(v) ⇒ Object



180
181
182
# File 'lib/depix/binary/fields.rb', line 180

def clean(v)
  (v.nil? || v.nan?) ? nil : v
end

#lengthObject



184
185
186
# File 'lib/depix/binary/fields.rb', line 184

def length
  4
end

#pack(value) ⇒ Object

The packing of NaN

12

pry(main)> value = 0 / 0.0

> NaN

13

pry(main)> [value].pack(“g”)

> “xFFxC0x00x00”

14

pry(main)> [value].pack(“g”)



198
199
200
# File 'lib/depix/binary/fields.rb', line 198

def pack(value)
  (value.nil? || value.nan? ) ? BLANK : [value].pack("g")
end

#patternObject



176
177
178
# File 'lib/depix/binary/fields.rb', line 176

def pattern
  "g"
end

#rtypeObject



188
189
190
# File 'lib/depix/binary/fields.rb', line 188

def rtype
  Float
end