Class: GdbFlasher::IHex::Segment
- Inherits:
-
Object
- Object
- GdbFlasher::IHex::Segment
- Defined in:
- lib/gdbflasher/ihex.rb
Instance Attribute Summary collapse
-
#base ⇒ Object
Returns the value of attribute base.
-
#data ⇒ Object
Returns the value of attribute data.
Instance Method Summary collapse
-
#initialize ⇒ Segment
constructor
A new instance of Segment.
- #intersect(region_base, region_end) ⇒ Object
- #pad_segment!(psize, fill_byte = 0x00) ⇒ Object
- #size ⇒ Object
Constructor Details
#initialize ⇒ Segment
Returns a new instance of Segment.
52 53 54 55 |
# File 'lib/gdbflasher/ihex.rb', line 52 def initialize @base = 0 @data = "" end |
Instance Attribute Details
#base ⇒ Object
Returns the value of attribute base.
50 51 52 |
# File 'lib/gdbflasher/ihex.rb', line 50 def base @base end |
#data ⇒ Object
Returns the value of attribute data.
50 51 52 |
# File 'lib/gdbflasher/ihex.rb', line 50 def data @data end |
Instance Method Details
#intersect(region_base, region_end) ⇒ Object
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/gdbflasher/ihex.rb', line 61 def intersect(region_base, region_end) if region_base == region_end raise ArgumentError, "Region is empty" end segment_range = @base...@base + size region_range = region_base..region_end intersection_base = nil, intersection_end = nil if segment_range.cover? region_range.min intersection_base = region_range.min elsif region_range.cover? segment_range.min intersection_base = segment_range.min else return Segment.new end if segment_range.cover? region_range.max intersection_end = region_range.max elsif region_range.cover? segment_range.max intersection_end = segment_range.max else return Segment.new end segment = Segment.new segment.base = intersection_base segment.data = @data[intersection_base - @base..intersection_end - @base] segment end |
#pad_segment!(psize, fill_byte = 0x00) ⇒ Object
94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
# File 'lib/gdbflasher/ihex.rb', line 94 def pad_segment!(psize, fill_byte = 0x00) if @base % size != 0 padding = size - (@base % size) @base -= padding @data = ([ fill_byte ] * padding).pack("C*") + @data end if @data.size % size != 0 padding = size - (@data.size % size) @data += ([ fill_byte ] * padding).pack "C*" end end |
#size ⇒ Object
57 58 59 |
# File 'lib/gdbflasher/ihex.rb', line 57 def size @data.length end |