Class: Avro::Schema

Inherits:
Object
  • Object
show all
Defined in:
lib/ext/avro_patches.rb

Constant Summary collapse

CRC_EMPTY =
0xc15d213aa4d7a795
@@fp_table =

The java library caches this value after initialized, so this pattern mimics that.

nil

Instance Method Summary collapse

Instance Method Details

#crc_64_avro_fingerprintObject



24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/ext/avro_patches.rb', line 24

def crc_64_avro_fingerprint
  parsing_form = Avro::SchemaNormalization.to_parsing_form(self)
  data_bytes = parsing_form.unpack("C*")

  initFPTable unless @@fp_table

  fp = CRC_EMPTY
  data_bytes.each do |b|
    fp = (fp >> 8) ^ @@fp_table[ (fp ^ b) & 0xff ]
  end
  fp
end

#initFPTableObject



13
14
15
16
17
18
19
20
21
22
# File 'lib/ext/avro_patches.rb', line 13

def initFPTable
  @@fp_table = Array.new(256)
  256.times do |i|
    fp = i
    8.times do |j|
      fp = (fp >> 1) ^ ( CRC_EMPTY & -( fp & 1 ) )
    end
    @@fp_table[i] = fp
  end
end