Verify struct sizing at build time.
This commit is contained in:
parent
3730ddacac
commit
d17aed8e82
4 changed files with 15 additions and 0 deletions
|
@ -142,6 +142,7 @@
|
|||
name: Request Header
|
||||
description: Packet format for inbound data.
|
||||
type: struct
|
||||
struct_length: 3
|
||||
struct_members: [
|
||||
{
|
||||
type: token
|
||||
|
@ -158,6 +159,7 @@
|
|||
name: Response Header
|
||||
description: Packet format for inbound data.
|
||||
type: struct
|
||||
struct_length: 4
|
||||
struct_members: [
|
||||
{
|
||||
type: token
|
||||
|
|
|
@ -83,6 +83,7 @@
|
|||
name: Broadcast Header
|
||||
description: Packet format for broadcast messages.
|
||||
type: struct
|
||||
struct_length: 4
|
||||
struct_members: [
|
||||
{
|
||||
type: token
|
||||
|
@ -240,6 +241,7 @@
|
|||
Retrieves the set of identifying information for the board.
|
||||
'''
|
||||
return_type: struct
|
||||
return_struct_length: 10
|
||||
return_struct_members: [
|
||||
{
|
||||
type: u16
|
||||
|
|
|
@ -38,6 +38,7 @@
|
|||
define: GET_KEYMAP_KEYCODE
|
||||
description: TODO
|
||||
request_type: struct
|
||||
request_struct_length: 3
|
||||
request_struct_members: [
|
||||
{
|
||||
type: u8
|
||||
|
@ -61,6 +62,7 @@
|
|||
define: SET_KEYMAP_KEYCODE
|
||||
description: TODO
|
||||
request_type: struct
|
||||
request_struct_length: 5
|
||||
request_struct_members: [
|
||||
{
|
||||
type: u8
|
||||
|
|
|
@ -133,6 +133,9 @@ def _append_route_types(lines, container, container_id=None, route_stack=None):
|
|||
lines.append(f' {member_type} {member_name};')
|
||||
lines.append(f'}} __attribute__((__packed__)) {route_name}_arg_t;')
|
||||
|
||||
req_len = container['request_struct_length']
|
||||
lines.append(f'_Static_assert(sizeof({route_name}_arg_t) == {req_len}, "{route_name}_arg_t needs to be {req_len} bytes in size");')
|
||||
|
||||
elif 'request_type' in container:
|
||||
request_type = container['request_type']
|
||||
found = re.search(r'(u\d+)\[(\d+)\]', request_type)
|
||||
|
@ -153,6 +156,9 @@ def _append_route_types(lines, container, container_id=None, route_stack=None):
|
|||
lines.append(f' {member_type} {member_name};')
|
||||
lines.append(f'}} __attribute__((__packed__)) {route_name}_t;')
|
||||
|
||||
req_len = container['return_struct_length']
|
||||
lines.append(f'_Static_assert(sizeof({route_name}_t) == {req_len}, "{route_name}_t needs to be {req_len} bytes in size");')
|
||||
|
||||
elif 'return_type' in container:
|
||||
return_type = container['return_type']
|
||||
found = re.search(r'(u\d+)\[(\d+)\]', return_type)
|
||||
|
@ -213,6 +219,9 @@ def _append_internal_types(lines, container):
|
|||
member_type = additional_types[member["type"]]
|
||||
lines.append(f' {member_type} {member_name};')
|
||||
lines.append(f'}} __attribute__((__packed__)) xap_{key}_t;')
|
||||
|
||||
req_len = value['struct_length']
|
||||
lines.append(f'_Static_assert(sizeof(xap_{key}_t) == {req_len}, "xap_{key}_t needs to be {req_len} bytes in size");')
|
||||
else:
|
||||
lines.append(f'typedef {data_type} xap_{key}_t;')
|
||||
|
||||
|
|
Loading…
Reference in a new issue