module CRC::Extensions

Public Instance Methods

__cached_magic_code__() click to toggle source
# File lib/crc/_magic.rb, line 53
def __cached_magic_code__
  @__cached_magic_code__ = initial_crc.to_magicdigest_for(self).freeze
  singleton_class.class_eval { attr_reader :__cached_magic_code__ }
  @__cached_magic_code__
end
bitsize_to_bytesize() click to toggle source
# File lib/crc/_extensions.rb, line 145
def bitsize_to_bytesize
  (self + 7) / 8
end
bitsize_to_intsize() click to toggle source
# File lib/crc/_extensions.rb, line 149
def bitsize_to_intsize
  bitsize = 8
  intsize = 1
  10.times do
    return intsize if self <= bitsize
    bitsize <<= 1
    intsize <<= 1
  end

  raise "数値が巨大すぎるため、intsize が決定できません - #{inspect}"
end
byte_paddingsize() click to toggle source
# File lib/crc/_extensions.rb, line 161
def byte_paddingsize
  (bitsize_to_bytesize * 8) - bitsize
end
convert_internal_state_for(crc) click to toggle source
# File lib/crc/_extensions.rb, line 56
def convert_internal_state_for(crc)
  raise TypeError, "cant convertion to #{crc.to_s} (for #{inspect})"
end
convert_target_state_for(crc) click to toggle source
# File lib/crc/_extensions.rb, line 60
def convert_target_state_for(crc)
  raise TypeError, "cant convertion to #{crc.to_s} (for #{inspect})"
end
each_byte() { |0xff & ch| ... } click to toggle source
# File lib/crc/_extensions.rb, line 9
def each_byte
  return to_enum(:each_byte) unless block_given?
  each { |ch| yield 0xff & ch }
  self
end
get_crc_model() click to toggle source
# File lib/crc/_extensions.rb, line 176
def get_crc_model
  nil
end
int_paddingsize() click to toggle source
# File lib/crc/_extensions.rb, line 165
def int_paddingsize
  (bitsize_to_intsize * 8) - bitsize
end
pushbyte(ch) click to toggle source
# File lib/crc/_extensions.rb, line 126
def pushbyte(ch)
  self << (0xff & ch).chr(Encoding::BINARY)
end
reverse_each_byte() { |0xff & ch| ... } click to toggle source
# File lib/crc/_extensions.rb, line 15
def reverse_each_byte
  return to_enum(:reverse_each_byte) unless block_given?
  reverse_each { |ch| yield 0xff & ch }
  self
end
splitbytes(bucket, bytes, is_little_endian) click to toggle source
# File lib/crc/_extensions.rb, line 114
def splitbytes(bucket, bytes, is_little_endian)
  if is_little_endian
    bytes.times { |i| bucket.pushbyte self >> (i * 8) }
  else
    (bytes - 1).downto(0) { |i| bucket.pushbyte self >> (i * 8) }
  end

  bucket
end
to_magicdigest_for(m, bytesize = m.bitsize.bitsize_to_bytesize) click to toggle source
# File lib/crc/_magic.rb, line 4
def to_magicdigest_for(m, bytesize = m.bitsize.bitsize_to_bytesize)
  if m.reflect_input? ^ m.reflect_output?
    tmp = CRC.bitreflect(self, m.bitsize)
  else
    tmp = self
  end

  if m.reflect_input?
    magic = tmp.splitbytes("".b, bytesize, true)
  else
    tmp <<= ((bytesize * 8) - m.bitsize)
    magic = tmp.splitbytes("".b, bytesize, false)
  end
end
variant_for?(m) click to toggle source
# File lib/crc/_extensions.rb, line 180
def variant_for?(m)
  false
end