Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bitfield support #76

Open
kojix2 opened this issue Oct 25, 2021 · 2 comments
Open

Bitfield support #76

kojix2 opened this issue Oct 25, 2021 · 2 comments

Comments

@kojix2
Copy link

kojix2 commented Oct 25, 2021

Hello. Thanks for the great tool.
However, the tool seems to fail to parse structs with bit fields.
Please provide support for bit fields.

@kojix2
Copy link
Author

kojix2 commented Oct 25, 2021

struct BGZF {
    // Reserved bits should be written as 0; read as "don't care"
    unsigned errcode:16, reserved:1, is_write:1, no_eof_block:1, is_be:1;
    signed compress_level:9;
    unsigned last_block_eof:1, is_compressed:1, is_gzip:1;
    int cache_size;
    int block_length, block_clength, block_offset;
    int64_t block_address, uncompressed_address;
    void *uncompressed_block, *compressed_block;
    bgzf_cache_t *cache;
    struct hFILE *fp; // actual file handle
    struct bgzf_mtaux_t *mt; // only used for multi-threading
    bgzidx_t *idx;      // BGZF index
    int idx_build_otf;  // build index on the fly, set by bgzf_index_build_init()
    struct z_stream_s *gz_stream; // for gzip-compressed files
    int64_t seeked;     // virtual offset of last seek
};

Actual code generated by crystal_lib:

  struct Bgzf
    errcode : LibC::UInt
    reserved : LibC::UInt
    is_write : LibC::UInt
    no_eof_block : LibC::UInt
    is_be : LibC::UInt
    compress_level : LibC::Int
    last_block_eof : LibC::UInt
    is_compressed : LibC::UInt
    is_gzip : LibC::UInt
    cache_size : LibC::Int
    block_length : LibC::Int
    block_clength : LibC::Int
    block_offset : LibC::Int
    block_address : Int64T
    uncompressed_address : Int64T
    uncompressed_block : Void*
    compressed_block : Void*
    cache : BgzfCacheT
    fp : HFile*
    mt : BgzfMtauxT*
    idx : BgzidxT
    idx_build_otf : LibC::Int
    gz_stream : ZStreamS*
    seeked : Int64T
  end

Bad but somewhat better code:

    struct Bgzf
      bitfields : Uint32T # Fixme
      # errcode : LibC::UInt
      # reserved : LibC::UInt
      # is_write : LibC::UInt
      # no_eof_block : LibC::UInt
      # is_be : LibC::UInt
      # compress_level : LibC::Int
      # last_block_eof : LibC::UInt
      # is_compressed : LibC::UInt
      # is_gzip : LibC::UInt
      cache_size : LibC::Int
      block_length : LibC::Int
      block_clength : LibC::Int
      block_offset : LibC::Int
      block_address : Int64T
      uncompressed_address : Int64T
      uncompressed_block : Void*
      compressed_block : Void*
      cache : BgzfCacheT
      fp : HFile*
      mt : BgzfMtauxT*
      idx : BgzidxT
      idx_build_otf : LibC::Int
      gz_stream : ZStreamS*
      seeked : Int64T
    end

@kojix2
Copy link
Author

kojix2 commented Oct 31, 2021

It would be better if we could link bindings created with crystal_lib with this.
https://github.com/elorest/bitfields

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant