Class: MrbParser::Header
- Inherits:
-
Object
- Object
- MrbParser::Header
- Defined in:
- lib/mrb_parser/header.rb
Instance Attribute Summary collapse
-
#compiler_name ⇒ Object
readonly
Returns the value of attribute compiler_name.
-
#compiler_version ⇒ Object
readonly
Returns the value of attribute compiler_version.
-
#crc ⇒ Object
readonly
Returns the value of attribute crc.
-
#signature ⇒ Object
readonly
Returns the value of attribute signature.
-
#size ⇒ Object
readonly
Returns the value of attribute size.
-
#version ⇒ Object
readonly
Returns the value of attribute version.
Class Method Summary collapse
Instance Method Summary collapse
- #check_crc(parser) ⇒ Object
- #dump ⇒ Object
-
#initialize ⇒ Header
constructor
A new instance of Header.
- #parse(parser) ⇒ Object
- #valid? ⇒ Boolean
Constructor Details
#initialize ⇒ Header
Returns a new instance of Header.
13 14 |
# File 'lib/mrb_parser/header.rb', line 13 def initialize end |
Instance Attribute Details
#compiler_name ⇒ Object (readonly)
Returns the value of attribute compiler_name.
5 6 7 |
# File 'lib/mrb_parser/header.rb', line 5 def compiler_name @compiler_name end |
#compiler_version ⇒ Object (readonly)
Returns the value of attribute compiler_version.
5 6 7 |
# File 'lib/mrb_parser/header.rb', line 5 def compiler_version @compiler_version end |
#crc ⇒ Object (readonly)
Returns the value of attribute crc.
5 6 7 |
# File 'lib/mrb_parser/header.rb', line 5 def crc @crc end |
#signature ⇒ Object (readonly)
Returns the value of attribute signature.
5 6 7 |
# File 'lib/mrb_parser/header.rb', line 5 def signature @signature end |
#size ⇒ Object (readonly)
Returns the value of attribute size.
5 6 7 |
# File 'lib/mrb_parser/header.rb', line 5 def size @size end |
#version ⇒ Object (readonly)
Returns the value of attribute version.
5 6 7 |
# File 'lib/mrb_parser/header.rb', line 5 def version @version end |
Class Method Details
Instance Method Details
#check_crc(parser) ⇒ Object
34 35 36 37 38 39 40 |
# 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 ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 |
# 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) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# 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? ⇒ Boolean
43 44 45 |
# File 'lib/mrb_parser/header.rb', line 43 def valid? @signature == "RITE" && @version == "0002" && @crc_verified end |