#pragma once
#include "../Auxiliary/bits.hpp"

namespace JabyEngine {
    #define __jabyengine_start_lba_request
    #define __jabyengine_request_lba_for(name, file) name
    #define __jabyengine_end_lba_request EndOfRequest

    struct __attribute__((packed)) AutoLBAEntry {
        // This layout should make it a bit easier to read the "BitRange" values
        static constexpr auto SizeInSectors   = BitRange::from_to(22, 31);
        static constexpr auto IsLZ4Compressed = Bit(19);
        static constexpr auto LBAValue        = BitRange::from_to(0, 18);

        uint32_t value;

        constexpr uint32_t get_lba() const {
            return bit::value::get_normalized(this->value, AutoLBAEntry::LBAValue);
        }

        constexpr uint32_t get_lba() const volatile {
            return const_cast<const AutoLBAEntry*>(this)->get_lba();
        }

        constexpr uint32_t get_size_in_sectors() const {
            return this->value >> SizeInSectors.pos;
        }

        constexpr uint32_t get_size_in_sectors() const volatile {
            return const_cast<const AutoLBAEntry*>(this)->get_size_in_sectors();
        }

        constexpr bool is_lz4() const {
            return bit::is_set(this->value, AutoLBAEntry::IsLZ4Compressed);
        }
         
        constexpr bool is_lz4() const volatile {
            return const_cast<const AutoLBAEntry*>(this)->is_lz4();
        }
    };
}