Add key->[known structure] schemas to j2s #50

Merged
jordan merged 3 commits from lda/Cytoplasm:master into master 2024-08-27 16:34:50 +00:00
Contributor

Fixes #49.

Fixes #49.
lda added 1 commit 2024-08-26 13:41:51 +00:00
lda added 1 commit 2024-08-27 09:24:40 +00:00
jordan reviewed 2024-08-27 13:43:45 +00:00
@ -38,6 +38,7 @@
#define MAX_DEPENDENCIES 32
#define IsDelimited(field, c1, c2) (*field == c1 && field[strlen(field) - 1] == c2)
Owner

Very clever. I don't know if IsDelimited is a great name though. But I also can't think of a better one so maybe it is fine.

Very clever. I don't know if `IsDelimited` is a great name though. But I also can't think of a better one so maybe it is fine.
Owner

I like this. Can you show a quick example of how it is used? Or can you point to a specific place in the code where this is used? I just want to see it in use, but I think the idea is good.

I like this. Can you show a quick example of how it is used? Or can you point to a specific place in the code where this is used? I just want to see it in use, but I think the idea is good.
Author
Contributor

I like this. Can you show a quick example of how it is used? Or can you point to a specific place in the code where this is used? I just want to see it in use, but I think the idea is good.

It generally behaves just like the [type] syntax, except that operations(getting, listing, ...) now use HashMaps instead of Arrays.
So, for example with a schema(note that some types aren't declared), where:

{
  "types": {
    "SharedData": {
      "type": "struct",
      "fields": {
         "signatures": { "type": "{SignatureInfo}" },
         "serverDepth": { "type": "{integer}" }
    }
  }
}

I can now, from C, do things like this:

/* SharedData data = ...; */
const char *server = "blow.hole";
SignatureInfo *sign = HashMapGet(data.signatures, server);
int64_t *depth = HashMapGet(data.signatures, server);
/* ... */

Matrix also sometimes lean into this pattern (see https://spec.matrix.org/v1.7/client-server-api/#get_matrixclientv3sync, especially the rooms fields)

> I like this. Can you show a quick example of how it is used? Or can you point to a specific place in the code where this is used? I just want to see it in use, but I think the idea is good. It generally behaves just like the `[type]` syntax, except that operations(getting, listing, ...) now use `HashMap`s instead of `Array`s. So, for example with a schema(note that some types aren't declared), where: ```json { "types": { "SharedData": { "type": "struct", "fields": { "signatures": { "type": "{SignatureInfo}" }, "serverDepth": { "type": "{integer}" } } } } ``` I can now, from C, do things like this: ```c /* SharedData data = ...; */ const char *server = "blow.hole"; SignatureInfo *sign = HashMapGet(data.signatures, server); int64_t *depth = HashMapGet(data.signatures, server); /* ... */ ``` Matrix also sometimes lean into this pattern (see https://spec.matrix.org/v1.7/client-server-api/#get_matrixclientv3sync, especially the `rooms` fields)
lda added 1 commit 2024-08-27 16:25:31 +00:00
Owner

Okay yeah that's pretty nice. Good work.

Okay yeah that's pretty nice. Good work.
jordan merged commit 4831f2e03d into master 2024-08-27 16:34:50 +00:00
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: Telodendria/Cytoplasm#50
No description provided.