class MrbParser::Header
Attributes
compiler_name[R]
compiler_version[R]
crc[R]
signature[R]
size[R]
version[R]
Public Class Methods
new()
click to toggle source
# File lib/mrb_parser/header.rb, line 13 def initialize end
parse(parser)
click to toggle source
# File lib/mrb_parser/header.rb, line 8 def self.parse(parser) header = Header.new() header.parse(parser) end
Public Instance Methods
check_crc(parser)
click to toggle source
# File lib/mrb_parser/header.rb, line 34 def check_crc(parser) pos = parser.pos rest_data = parser.read(nil) parser.seek(pos) checksum = MrbParser::CRC.calc_crc_16_ccitt(rest_data, rest_data.size, 0) @crc == checksum end
dump()
click to toggle source
# File lib/mrb_parser/header.rb, line 47 def dump printf "*** BINARY HEADER ***\n" printf "secID: %s\n", @signature printf "ver : %s\n", @version printf "crc : 0x%04x (%s)\n", @crc, @crc_verified printf "size : 0x%08x\n", @size printf "compiler:\n" printf " name: %s\n", @compiler_name printf " ver : %s\n", @compiler_version printf "*** ***\n" end
parse(parser)
click to toggle source
# File lib/mrb_parser/header.rb, line 16 def parse(parser) @signature = parser.read_chars(4) @version = parser.read_chars(4) @crc = parser.read_uint16 @crc_verified = check_crc(parser) @size = parser.read_uint32 @compiler_name = parser.read_chars(4) @compiler_version = parser.read_chars(4) if parser.verbose if !valid? STDERR.print "** [WARN] This header seems to be invalid. **\n" end end self end
valid?()
click to toggle source
# File lib/mrb_parser/header.rb, line 43 def valid? @signature == "RITE" && @version == "0002" && @crc_verified end