Skip to content

Override uint64_t generated type for bit types #47

@cmilhaupt

Description

@cmilhaupt

Given the following KSY definition:

meta:
    id: bits_example
    endian: be
    bit-endian: be
seq:
- id: first_bit
  type: b2
- id: second_bit
  type: b2
- id: third_bit
  type: b2
- id: fourth_bit
  type: b2

The following C++ header is generated:

# kaitai-struct-compiler -t cpp_stl --cpp-standard 11 bit_example.ksy
# cat bits_example.h | grep uint64
    uint64_t m_first_bit;
    uint64_t m_second_bit;
    uint64_t m_third_bit;
    uint64_t m_fourth_bit;
    uint64_t first_bit() const { return m_first_bit; }
    uint64_t second_bit() const { return m_second_bit; }
    uint64_t third_bit() const { return m_third_bit; }
    uint64_t fourth_bit() const { return m_fourth_bit; }

Is there anyway in the KSY file definition to make these generate as a uint8_t to save some space? I tried type: b2.as<u1> seeing something similar for arrays, but this gives me the following error:

bit_example.ksy: /seq/0: error: parsing expression 'b2.as<[]u1>' failed on 1:3, expected "::" | CharsWhile(Set( , n)) | "\\\n" | End

Any help or clarifications would be appreciated.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions