Structured API
Define a bare structured API, useful for interfaces that don't need to be portable across multiple platforms. E.G. embedded applications targeting a single architecture.
Usage
Basic Usage
Define the API in TOML or another markup language.
[file]
brief = 'Command set for a thermostat'
description = 'Provides basic debug commands for a thermostat. Allows for both imperial and metric units.'
[commands]
description = "Debug commands for thermostat"
display_name = "Thermostat command"
type = "group"
[cmd_reset]
description = "Request a software reset"
display_name = "reset request"
size = 0
type = "structure"
groups.commands = { value = 1, name = "reset" }
[cmd_temperature_set]
description = "Request a change in temperature"
display_name = "Request temperature change"
members = [
{ name = "temperature", size = 2, type = 'int', description = 'Desired temperature' },
{ name = "units", size = 1, type = 'temperature_units', description = 'Selected temperature unit' },
]
size = 3
type = "structure"
groups.commands = { value = 2, name = "temperature_set" }
This will generate code that looks like this for c by default
/**
* @file
* @brief Command set for a thermostat
*
* Provides basic debug commands for a thermostat. Allows for both imperial and
* metric units.
*
* @note This file is autogenerated using structured_api
*/
#ifndef STRUCTURES_H_
#define STRUCTURES_H_
#ifdef __cplusplus
extern "C" {
#endif
#include <static_assert.h>
#include <stdint.h>
/// commands tag
/// Enumeration for commands tag
typedef enum commands_tag_e {
/// @see cmd_reset_t
commands_tag_reset = 0x1,
/// @see cmd_temperature_set_t
commands_tag_temperature_set = 0x2,
} commands_tag_t;
STATIC_ASSERT_TYPE_SIZE(commands_tag_t, 1);
/// reset request
/// Request a software reset
typedef struct cmd_reset_s {
/// Structure is intentionally empty (zero sized)
uint8_t empty[0];
} cmd_reset_t;
STATIC_ASSERT_TYPE_SIZE(cmd_reset_t, 0);
/// Request temperature change
/// Request a change in temperature
typedef struct cmd_temperature_set_s {
/// Desired temperature
int16_t temperature;
/// Selected temperature unit
temperature_units_t units;
} cmd_temperature_set_t;
STATIC_ASSERT_TYPE_SIZE(cmd_temperature_set_t, 3);
/// Thermostat command
/// Debug commands for thermostat
typedef struct commands_u_s {
/// commands tag
commands_tag_t tag;
union {
/// Request a software reset
cmd_reset_t reset;
/// Request a change in temperature
cmd_temperature_set_t temperature_set;
} value;
} commands_u_t;
STATIC_ASSERT_TYPE_SIZE(commands_u_t, 4);
#ifdef __cplusplus
}
#endif
#endif // STRUCTURES_H_
An example is given in the examples folder:
struct-writer --input-definition examples/structures.toml --output-file examples/output/structures.h
Customizable templates
Code generation is customizable using templates. If no templates are provided, we use the default C template.
The default template is shown in the examples folder.
struct-writer --input-definition examples/structures.toml --output-file examples/output/structures.h --template-file examples/template_c.toml
Multiple templates
Chain templates together to more tightly specify certain files in a project. For example if a certain file needs specific includes.
struct-writer --input-definition examples/structures.toml --output-file examples/output/structures.h --template-file examples/template_c.toml --template-file examples/packed_templates.toml
development
watchexec.exe --clear --restart --debounce 500 --exts py,toml "isort . && black . && pytest && struct-writer --input-definition examples/structures.toml --template-files examples/template.toml --output-file examples/output/structures.h && pylint ."
Metadata
Release files for struct_writer 0.5.6
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| struct_writer-0.5.6.tar.gz | 45.4 kB | Without provenance | Details for struct_writer-0.5.6.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| struct_writer-0.5.6-py3-none-any.whl | Python 3 | none | any | Details for struct_writer-0.5.6-py3-none-any.whl |
Total release size: 61.9 kB
Release files / struct_writer-0.5.6.tar.gz
| Download URL | struct_writer-0.5.6.tar.gz |
|---|---|
| Size | 45.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
c0005fc77eaac04388e745f91ea5843919406b091d20a615588fe6c2e60a5bd2
|
|
BLAKE2b-256 checksum How to use checksums |
452de24a6cdf53e0d0c91cf3fa886bec43251394802419df00f8c0da8d9825a2
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.7.9
|
Release files / struct_writer-0.5.6-py3-none-any.whl
| Download URL | struct_writer-0.5.6-py3-none-any.whl |
|---|---|
| Size | 16.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
da3aef834c0aec68e3b6243b586514dee6f554409c2ccec4ba9c1e16c480609b
|
|
BLAKE2b-256 checksum How to use checksums |
78cb51e3a27d2eee1bf7270070d83c4fb81a5b2a8a9da7406a014ef81e14ca0c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.7.9
|
Security for struct_writer 0.5.6
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.