Class: Depix::U32Field

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

Constant Summary collapse

BLANK =
0xFFFFFFFF

Instance Attribute Summary

Attributes inherited from Field

#desc, #name, #req, #rtype

Instance Method Summary collapse

Methods inherited from Field

#consume!, emit_char, emit_r32, emit_u16, emit_u32, emit_u8, #explain, #initialize, #pack

Constructor Details

This class inherits a constructor from Depix::Field

Instance Method Details

#clean(value) ⇒ Object



115
116
117
# File 'lib/depix/dict.rb', line 115

def clean(value)
  value == BLANK ? nil : value
end

#lengthObject



111
112
113
# File 'lib/depix/dict.rb', line 111

def length
  4
end

#patternObject



107
108
109
# File 'lib/depix/dict.rb', line 107

def pattern
  "N"
end

#validate!(value) ⇒ Object

Override - might be Bignum although cast to Integer sometimes



120
121
122
123
124
# File 'lib/depix/dict.rb', line 120

def validate!(value)
  raise "#{name} value required, but got nil".strip if value.nil? && req?
  raise "#{name} value expected to be #{rtype} but was #{value.class}" if !value.nil? && (!value.is_a?(Integer) && !value.is_a?(Bignum))
  raise "#{name} value #{value} overflows" if !value.nil? && (value < 0 || value >= BLANK)
end