Class: FFI::BitStruct

Inherits:
Struct
  • Object
show all
Defined in:
lib/hts/libhts.rb

Overview

Struct that support bit fields. Currently readonly.

Class Attribute Summary collapse

Class Method Summary collapse

Methods inherited from Struct

struct_layout, union_layout

Class Attribute Details

.bit_fields_hash_tableObject (readonly)

Returns the value of attribute bit_fields_hash_table.



79
80
81
# File 'lib/hts/libhts.rb', line 79

def bit_fields_hash_table
  @bit_fields_hash_table
end

Class Method Details

.bit_fields(*args) ⇒ Object

Examples:

Bcf1

class Bcf1 < FFI::BitStruct
  layout \
    :pos,            :hts_pos_t,
    :rlen,           :hts_pos_t,
    :rid,            :int32_t,
    :qual,           :float,
    :_n_info_allele, :uint32_t,
    :_n_fmt_sample,  :uint32_t,
    :shared,         KString,
    :indiv,          KString,
    :d,              BcfDec,
    :max_unpack,     :int,
    :unpacked,       :int,
    :unpack_size,    [:int, 3],
    :errcode,        :int

  bit_fields :_n_info_allele,
             :n_info,   16,
             :n_allele, 16

  bit_fields :_n_fmt_sample,
             :n_fmt,    8,
             :n_sample, 24
end


107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
# File 'lib/hts/libhts.rb', line 107

def bit_fields(*args)
  unless instance_variable_defined?(:@bit_fields_hash_table)
    @bit_fields_hash_table = {}
    prepend BitFieldsModule
  end

  parent = args.shift
  labels = []
  widths = []
  args.each_slice(2) do |l, w|
    labels << l
    widths << w
  end
  starts = widths.inject([0]) do |result, w|
    result << (result.last + w)
  end
  labels.zip(starts, widths).each do |l, s, w|
    @bit_fields_hash_table[l] = [parent, s, w]
  end
end