/*
    DO NOT EDIT THIS FILE!
    This file was automatically generated by the bstruct generator.
*/

#include <stdint.h>

#include <misc/balign.h>


typedef struct oc_table_struct oc_table;

typedef struct {
    int id_off;
    int id_size;
    #ifndef NDEBUG
    int id_count;
    #endif

    int entries_off;
    int entries_size;
    #ifndef NDEBUG
    int entries_count;
    #endif

    int len;
    int align;
} oc_tableParams;

static void oc_tableParams_Init (oc_tableParams *o, int num_entries)
{
    int cur_size;
    int cur_align;
    int cur_count;

    o->len = 0;
    o->align = 1;

    cur_size = (sizeof(uint16_t));
    cur_align = (__alignof__(uint16_t));
    cur_count = (1);
    o->id_off = BALIGN_UP_N(o->len, cur_align);
    o->id_size = cur_size;
    #ifndef NDEBUG
    o->id_count = cur_count;
    #endif
    o->len = o->id_off + (cur_count * cur_size);
    o->align = (cur_align > o->align ? cur_align : o->align);

    cur_size = (sizeof(struct OTPChecker_entry));
    cur_align = (__alignof__(struct OTPChecker_entry));
    cur_count = (num_entries);
    o->entries_off = BALIGN_UP_N(o->len, cur_align);
    o->entries_size = cur_size;
    #ifndef NDEBUG
    o->entries_count = cur_count;
    #endif
    o->len = o->entries_off + (cur_count * cur_size);
    o->align = (cur_align > o->align ? cur_align : o->align);

}

static uint16_t * oc_table_id (oc_tableParams *o, oc_table *s)
{
    return (uint16_t *)((uint8_t *)s + o->id_off);
}

static uint16_t * oc_table_id_at (oc_tableParams *o, oc_table *s, int i)
{
    ASSERT(i >= 0)
    ASSERT(i < o->id_count)

    return (uint16_t *)((uint8_t *)s + o->id_off + i * o->id_size);
}

static struct OTPChecker_entry * oc_table_entries (oc_tableParams *o, oc_table *s)
{
    return (struct OTPChecker_entry *)((uint8_t *)s + o->entries_off);
}

static struct OTPChecker_entry * oc_table_entries_at (oc_tableParams *o, oc_table *s, int i)
{
    ASSERT(i >= 0)
    ASSERT(i < o->entries_count)

    return (struct OTPChecker_entry *)((uint8_t *)s + o->entries_off + i * o->entries_size);
}

typedef struct oc_tables_struct oc_tables;

typedef struct {
    oc_tableParams tables_params;
    int tables_off;
    int tables_size;
    #ifndef NDEBUG
    int tables_count;
    #endif

    int len;
    int align;
} oc_tablesParams;

static void oc_tablesParams_Init (oc_tablesParams *o, int num_tables, int num_entries)
{
    int cur_size;
    int cur_align;
    int cur_count;

    o->len = 0;
    o->align = 1;

    oc_tableParams_Init(&o->tables_params, num_entries);
    cur_size = o->tables_params.len;
    cur_align = o->tables_params.align;
    cur_count = (num_tables);
    o->tables_off = BALIGN_UP_N(o->len, cur_align);
    o->tables_size = cur_size;
    #ifndef NDEBUG
    o->tables_count = cur_count;
    #endif
    o->len = o->tables_off + (cur_count * cur_size);
    o->align = (cur_align > o->align ? cur_align : o->align);

}

static oc_table * oc_tables_tables (oc_tablesParams *o, oc_tables *s)
{
    return (oc_table *)((uint8_t *)s + o->tables_off);
}

static oc_table * oc_tables_tables_at (oc_tablesParams *o, oc_tables *s, int i)
{
    ASSERT(i >= 0)
    ASSERT(i < o->tables_count)

    return (oc_table *)((uint8_t *)s + o->tables_off + i * o->tables_size);
}

