Class: Depix::Binary::Fields::U32Field

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

Overview

unit32 field

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!, #explain, #initialize, #pack

Constructor Details

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

Instance Method Details

#clean(value) ⇒ Object



76
77
78
# File 'lib/depix/binary/fields.rb', line 76

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

#lengthObject



72
73
74
# File 'lib/depix/binary/fields.rb', line 72

def length
  4
end

#patternObject



68
69
70
# File 'lib/depix/binary/fields.rb', line 68

def pattern
  "N"
end

#validate!(value) ⇒ Object

Override - might be Bignum although cast to Integer sometimes



81
82
83
84
85
# File 'lib/depix/binary/fields.rb', line 81

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