module M2TSParser::Appendix::CRC32Decoder

Constants

CRC32_TABLE

Public Instance Methods

calc_crc32(bytes, length) click to toggle source
# File lib/m2ts_parser/appendix/crc32.rb, line 56
def calc_crc32(bytes, length)
  crc = 0xffffffff
  length.times do |i|
    crc = ((crc << 8) & 0xffffffff) ^ CRC32_TABLE[((crc >> 24) ^ bytes[i]) & 0xff]
  end
  return crc
end
check_crc32() click to toggle source
# File lib/m2ts_parser/appendix/crc32.rb, line 64
def check_crc32
  if structure_bit_length % 8 != 0
    raise "binary's length should be multiple of 8bit to check CRC32."
  end
  return calc_crc32(to_chars, structure_bit_length / 8) == 0
end