Login
You're viewing the functional.cafe public feed.
  • Nov 7, 2026, 8:10 AM

    This is in the context of doing something like stacking protocol decoders, where the output of the decoder is a well formed static type, but we can't really expose that in a dynamic way to the host or any of the decoders that use it as input, but we need to let them know how it's shaped.

    And it needs to be *fast* to encode/decode, So querying for each field is out of the question.

    💬 1🔄 0⭐ 0

Replies

  • Nov 7, 2026, 8:13 AM

    One thought I had was to use proc-macro magic and a special decoder endpoint.

    So the idea is you would have a macro that takes a decoder name, and then inside the proc-macro it loads it to query how the output formats should be layed out.

    Then it will generate a strongly type structure that matches that.

    💬 0🔄 0⭐ 0
  • Nov 7, 2026, 8:16 AM

    @lethalbit
    structs are just a compile time tool to avoid calculating offsets

    you could just have the struct layout queried for each type once at the start, and then just use the offsets

    struct Real { int a; char *b; };
    struct Offsets { uintptr_t a; uintptr_t b; };

    // startup
    offsets.a = &(((Real*)0)->a);

    // processing
    a = *(int*)(real + offsets.a);

    💬 1🔄 0⭐ 0
  • 💬 0🔄 0⭐ 0