Я пытаюсь перебрать строку и получить контрольную сумму CRC32 каждого символа в массив.Я делаю это, используя метод .each_char
:
def calculate_signature(data)
signature = [] of UInt32
data.each_char do |c|
signature << CRC32.checksum(c)
end
end
Когда я запускаю это, я получаю очень длинное бесполезное сообщение об ошибке.
Error in sigwaf.cr:4: instantiating 'calculate_signature(String)'
calculate_signature("yrdy")
^~~~~~~~~~~~~~~~~~~
in lib/settings.cr:17: instantiating 'String#each_char()'
data.each_char do |c|
^~~~~~~~~
in /usr/local/Cellar/crystal/0.29.0/src/string.cr:3773: instantiating 'each_byte()'
each_byte do |byte|
^~~~~~~~~
in /usr/local/Cellar/crystal/0.29.0/src/string.cr:3881: instantiating 'Slice(UInt8)#each()'
to_slice.each do |byte|
^~~~
in /usr/local/Cellar/crystal/0.29.0/src/indexable.cr:187: instantiating 'each_index()'
each_index do |i|
^~~~~~~~~~
in /usr/local/Cellar/crystal/0.29.0/src/indexable.cr:187: instantiating 'each_index()'
each_index do |i|
^~~~~~~~~~
in /usr/local/Cellar/crystal/0.29.0/src/string.cr:3881: instantiating 'Slice(UInt8)#each()'
to_slice.each do |byte|
^~~~
in /usr/local/Cellar/crystal/0.29.0/src/string.cr:3773: instantiating 'each_byte()'
each_byte do |byte|
^~~~~~~~~
in lib/settings.cr:17: instantiating 'String#each_char()'
data.each_char do |c|
^~~~~~~~~
in lib/settings.cr:18: instantiating 'CRC32:Module#checksum(Char)'
signature >> CRC32.checksum(c)
^~~~~~~~
in /usr/local/Cellar/crystal/0.29.0/src/crc32/crc32.cr:9: instantiating 'update(Char, UInt32)'
update(data, initial)
^~~~~~
in /usr/local/Cellar/crystal/0.29.0/src/crc32/crc32.cr:13: undefined method 'to_slice' for Char
slice = data.to_slice
^~~~~~~~
Rerun with --error-trace to show a complete error trace.
Как успешно добавить контрольную сумму crc32 в массив?