diff options
| author | eunhhu <[email protected]> | 2026-09-29 07:11:32 +0100 |
|---|---|---|
| committer | eunhhu <[email protected]> | 2026-09-29 07:11:32 +0100 |
| commit | fcf7cdbe0a971825da0bb087383c60e714ab2be0 (patch) | |
| tree | d805332bdd68171349892b950de02cf317988de7 /core/module.c | |
| parent | a052b95c8135cdc5f9b91f8efc991cac80fbbe8b (diff) | |
| download | pure-fcf7cdbe0a971825da0bb087383c60e714ab2be0.tar.gz pure-fcf7cdbe0a971825da0bb087383c60e714ab2be0.zip | |
Let links know nothing of the core: the host names inputs and shapes
A sender takes its messages' shape, and a listener asks its host which
input a stream goes to. The core gives the shape (pure_module_shape);
link/ now builds without the core's headers.
Diffstat (limited to 'core/module.c')
| -rw-r--r-- | core/module.c | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/core/module.c b/core/module.c index cb4fe1a..8ac3b48 100644 --- a/core/module.c +++ b/core/module.c @@ -1094,6 +1094,25 @@ static int find(const char (*names)[PURE_MODULE_NAME], unsigned count, const cha int pure_module_state(const PureModule *m, const char *name) { return find(m->state_names, m->states, name); } int pure_module_input(const PureModule *m, const char *name) { return find(m->input_names, m->inputs, name); } +static uint32_t fnv(uint32_t h, const void *bytes, size_t size) { + const unsigned char *p = bytes; + for (size_t i = 0; i < size; ++i) h = (h ^ p[i]) * 16777619u; + return h; +} + +uint32_t pure_module_shape(const PureModule *m, uint32_t input) { + const PureInputShape *s = &m->input[input]; + uint32_t h = fnv(2166136261u, &s->prefix, sizeof(s->prefix)); + for (uint32_t f = 0; f < s->field_count; ++f) { + const PureField *field = &m->field[s->field_start + f]; + unsigned char fixed[7] = {field->type, (unsigned char)field->rows, (unsigned char)(field->rows >> 8), + (unsigned char)field->offset, (unsigned char)(field->offset >> 8), + (unsigned char)(field->offset >> 16), (unsigned char)(field->offset >> 24)}; + h = fnv(fnv(h, field->name, strlen(field->name) + 1), fixed, sizeof(fixed)); + } + return h; +} + int pure_module_view(const PureModule *m, const char *name) { for (uint32_t i = 0; i < m->views; ++i) if (!m->view_table[i] && !strcmp(m->view_names[i], name)) return (int)i; |
