Class: PackfileReader::Hunk
- Inherits:
-
Object
- Object
- PackfileReader::Hunk
- Defined in:
- lib/packfile_reader/packfile_hunk.rb
Constant Summary collapse
- TYPE_MAP =
{ 1 => :OBJ_COMMIT, 2 => :OBJ_TREE, 3 => :OBJ_BLOB, 4 => :OBJ_TAG, 6 => :OBJ_OFS_DELTA, 7 => :OBJ_REF_DELTA, }
- HUNK_TYPE_MASK =
0b01110000
- HUNK_SIZE_4_MASK =
0b00001111
- HUNK_SIZE_7_MASK =
0b01111111
Instance Attribute Summary collapse
-
#offset_size ⇒ Object
readonly
Returns the value of attribute offset_size.
-
#size ⇒ Object
readonly
Returns the value of attribute size.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Class Method Summary collapse
Instance Method Summary collapse
Instance Attribute Details
#offset_size ⇒ Object (readonly)
Returns the value of attribute offset_size.
5 6 7 |
# File 'lib/packfile_reader/packfile_hunk.rb', line 5 def offset_size @offset_size end |
#size ⇒ Object (readonly)
Returns the value of attribute size.
3 4 5 |
# File 'lib/packfile_reader/packfile_hunk.rb', line 3 def size @size end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
4 5 6 |
# File 'lib/packfile_reader/packfile_hunk.rb', line 4 def type @type end |
Class Method Details
.new_with_type(packfile_io) ⇒ Object
20 21 22 23 24 25 26 27 |
# File 'lib/packfile_reader/packfile_hunk.rb', line 20 def self.new_with_type(packfile_io) hunk_bytes = packfile_io.read(1).unpack('C')[0] continuation = hunk_bytes[7] # First representative bit of the byte type = (hunk_bytes & HUNK_TYPE_MASK) >> 4 # Adjust type position (remove the extra 4 bits at the end) size = (hunk_bytes & HUNK_SIZE_4_MASK) # We only have 4 bits in a hunk with type for size Hunk.new(continuation == 1, size, 4, TYPE_MAP[type]) end |
.new_without_type(packfile_io) ⇒ Object
29 30 31 32 33 34 35 |
# File 'lib/packfile_reader/packfile_hunk.rb', line 29 def self.new_without_type(packfile_io) hunk_bytes = packfile_io.read(1).unpack('C')[0] continuation = hunk_bytes[7] # First representative bit of the byte size = (hunk_bytes & HUNK_SIZE_7_MASK) # We only have 7 bits in a hunk with type for size Hunk.new(continuation == 1, size, 7) end |
Instance Method Details
#continuation? ⇒ Boolean
37 38 39 |
# File 'lib/packfile_reader/packfile_hunk.rb', line 37 def continuation? @continuation end |