bstruct_OTPChecker.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. /*
  2. DO NOT EDIT THIS FILE!
  3. This file was automatically generated by the bstruct generator.
  4. */
  5. #include <stdint.h>
  6. #include <misc/balign.h>
  7. typedef struct oc_table_struct oc_table;
  8. typedef struct {
  9. int id_off;
  10. int id_size;
  11. #ifndef NDEBUG
  12. int id_count;
  13. #endif
  14. int entries_off;
  15. int entries_size;
  16. #ifndef NDEBUG
  17. int entries_count;
  18. #endif
  19. int len;
  20. int align;
  21. } oc_tableParams;
  22. static void oc_tableParams_Init (oc_tableParams *o, int num_entries)
  23. {
  24. int cur_size;
  25. int cur_align;
  26. int cur_count;
  27. o->len = 0;
  28. o->align = 1;
  29. cur_size = (sizeof(uint16_t));
  30. cur_align = (__alignof__(uint16_t));
  31. cur_count = (1);
  32. o->id_off = balign_up(o->len, cur_align);
  33. o->id_size = cur_size;
  34. #ifndef NDEBUG
  35. o->id_count = cur_count;
  36. #endif
  37. o->len = o->id_off + (cur_count * cur_size);
  38. o->align = (cur_align > o->align ? cur_align : o->align);
  39. cur_size = (sizeof(struct OTPChecker_entry));
  40. cur_align = (__alignof__(struct OTPChecker_entry));
  41. cur_count = (num_entries);
  42. o->entries_off = balign_up(o->len, cur_align);
  43. o->entries_size = cur_size;
  44. #ifndef NDEBUG
  45. o->entries_count = cur_count;
  46. #endif
  47. o->len = o->entries_off + (cur_count * cur_size);
  48. o->align = (cur_align > o->align ? cur_align : o->align);
  49. }
  50. static uint16_t * oc_table_id (oc_tableParams *o, oc_table *s)
  51. {
  52. return (uint16_t *)((uint8_t *)s + o->id_off);
  53. }
  54. static uint16_t * oc_table_id_at (oc_tableParams *o, oc_table *s, int i)
  55. {
  56. ASSERT(i >= 0)
  57. ASSERT(i < o->id_count)
  58. return (uint16_t *)((uint8_t *)s + o->id_off + i * o->id_size);
  59. }
  60. static struct OTPChecker_entry * oc_table_entries (oc_tableParams *o, oc_table *s)
  61. {
  62. return (struct OTPChecker_entry *)((uint8_t *)s + o->entries_off);
  63. }
  64. static struct OTPChecker_entry * oc_table_entries_at (oc_tableParams *o, oc_table *s, int i)
  65. {
  66. ASSERT(i >= 0)
  67. ASSERT(i < o->entries_count)
  68. return (struct OTPChecker_entry *)((uint8_t *)s + o->entries_off + i * o->entries_size);
  69. }
  70. typedef struct oc_tables_struct oc_tables;
  71. typedef struct {
  72. oc_tableParams tables_params;
  73. int tables_off;
  74. int tables_size;
  75. #ifndef NDEBUG
  76. int tables_count;
  77. #endif
  78. int len;
  79. int align;
  80. } oc_tablesParams;
  81. static void oc_tablesParams_Init (oc_tablesParams *o, int num_tables, int num_entries)
  82. {
  83. int cur_size;
  84. int cur_align;
  85. int cur_count;
  86. o->len = 0;
  87. o->align = 1;
  88. oc_tableParams_Init(&o->tables_params, num_entries);
  89. cur_size = o->tables_params.len;
  90. cur_align = o->tables_params.align;
  91. cur_count = (num_tables);
  92. o->tables_off = balign_up(o->len, cur_align);
  93. o->tables_size = cur_size;
  94. #ifndef NDEBUG
  95. o->tables_count = cur_count;
  96. #endif
  97. o->len = o->tables_off + (cur_count * cur_size);
  98. o->align = (cur_align > o->align ? cur_align : o->align);
  99. }
  100. static oc_table * oc_tables_tables (oc_tablesParams *o, oc_tables *s)
  101. {
  102. return (oc_table *)((uint8_t *)s + o->tables_off);
  103. }
  104. static oc_table * oc_tables_tables_at (oc_tablesParams *o, oc_tables *s, int i)
  105. {
  106. ASSERT(i >= 0)
  107. ASSERT(i < o->tables_count)
  108. return (oc_table *)((uint8_t *)s + o->tables_off + i * o->tables_size);
  109. }