Class: Cosmos::Crc
- Defined in:
- lib/cosmos/utilities/crc.rb,
ext/cosmos/ext/crc/crc.c
Overview
Instance Attribute Summary collapse
-
#poly ⇒ Integer
readonly
The polynomial used when calcuating the CRC.
-
#reflect ⇒ Boolean
readonly
Whether to bit reverse each byte.
-
#seed ⇒ Integer
readonly
Seed value used to start the calulation.
-
#table ⇒ String
readonly
Binary lookup table used to perform the calculation.
-
#xor ⇒ Boolean
readonly
Whether the result is XORed with 0xFFFF.
Instance Method Summary collapse
-
#initialize(poly, seed, xor, reflect) ⇒ Crc
constructor
Creates a CRC algorithm instance.
Constructor Details
#initialize(poly, seed, xor, reflect) ⇒ Crc
Creates a CRC algorithm instance.
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/cosmos/utilities/crc.rb', line 36 def initialize(poly, seed, xor, reflect) @poly = poly @seed = seed @xor = xor @reflect = reflect @table = '' # Determine which class we're using: Crc16, Crc32, Crc64 digits = self.class.name[-2..-1].to_i case digits when 16 pack = 'S' when 32 pack = 'I' when 64 pack = 'Q' end (0..255).each do |index| @table << [compute_table_entry(index, digits)].pack(pack) end end |
Instance Attribute Details
#poly ⇒ Integer (readonly)
Returns The polynomial used when calcuating the CRC.
19 20 21 |
# File 'lib/cosmos/utilities/crc.rb', line 19 def poly @poly end |
#reflect ⇒ Boolean (readonly)
Returns Whether to bit reverse each byte.
25 26 27 |
# File 'lib/cosmos/utilities/crc.rb', line 25 def reflect @reflect end |
#seed ⇒ Integer (readonly)
Returns Seed value used to start the calulation.
21 22 23 |
# File 'lib/cosmos/utilities/crc.rb', line 21 def seed @seed end |
#table ⇒ String (readonly)
Returns Binary lookup table used to perform the calculation.
27 28 29 |
# File 'lib/cosmos/utilities/crc.rb', line 27 def table @table end |
#xor ⇒ Boolean (readonly)
Returns Whether the result is XORed with 0xFFFF.
23 24 25 |
# File 'lib/cosmos/utilities/crc.rb', line 23 def xor @xor end |