class PackfileReader::Hunk

Constants

HUNK_SIZE_4_MASK
HUNK_SIZE_7_MASK
HUNK_TYPE_MASK
TYPE_MAP

Attributes

offset_size[R]
size[R]
type[R]

Public Class Methods

new(continuation, size, offset_size, type=nil) click to toggle source
# File lib/packfile_reader/packfile_hunk.rb, line 42
def initialize(continuation, size, offset_size, type=nil)
  @continuation = continuation
  @size = size
  @offset_size = offset_size
  @type = type
end
new_with_type(packfile_io) click to toggle source
# 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) click to toggle source
# 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

Public Instance Methods

continuation?() click to toggle source
# File lib/packfile_reader/packfile_hunk.rb, line 37
def continuation?
  @continuation
end