Reducer args encoding is hand-rolled #4

Closed
opened 2026-08-19 06:49:19 +00:00 by yuris · 1 comment
Owner

connection.call_reducer sends args as a raw Lua array — correct only for positional product args. Complex types (sum types, nested) need schema-driven encoding.

  • Decide: extend hand-rolled encoders per-shape vs schema-driven codegen
  • Cover: strings, numbers, bools, arrays, nested tables
  • Tests for each shape

ponytail: hand-rolled until a real module needs sum types.

`connection.call_reducer` sends `args` as a raw Lua array — correct only for positional product args. Complex types (sum types, nested) need schema-driven encoding. - [ ] Decide: extend hand-rolled encoders per-shape vs schema-driven codegen - [ ] Cover: strings, numbers, bools, arrays, nested tables - [ ] Tests for each shape ponytail: hand-rolled until a real module needs sum types.
Author
Owner

Resolved in ee90548 by observation rather than guesswork.

The wire format is JsonFormat::Single = ByteString — reducer args are a JSON string containing JSON:

{"CallReducer":{"reducer":"send_message","args":"[\"yuris\",\"hi\"]","request_id":2,"flags":0}}

protocol.encode_client now takes a Lua array for args and double-encodes it, passing a pre-encoded string through untouched. Verified end to end: the captured TransactionUpdate frames are responses to exactly these calls committing on a live 2.8.2 server.

Still open in principle: args whose types are sum types or nested products. Same rule applies (SATS-JSON inside the string), but the test module doesn't exercise them — revisit when a real module needs one.

Resolved in ee90548 by observation rather than guesswork. The wire format is `JsonFormat::Single = ByteString` — reducer args are a JSON **string containing JSON**: ``` {"CallReducer":{"reducer":"send_message","args":"[\"yuris\",\"hi\"]","request_id":2,"flags":0}} ``` `protocol.encode_client` now takes a Lua array for `args` and double-encodes it, passing a pre-encoded string through untouched. Verified end to end: the captured `TransactionUpdate` frames are responses to exactly these calls committing on a live 2.8.2 server. Still open in principle: args whose types are sum types or nested products. Same rule applies (SATS-JSON inside the string), but the test module doesn't exercise them — revisit when a real module needs one.
yuris closed this issue 2026-08-19 07:37:34 +00:00
Sign in to join this conversation.
No project
No assignees
1 participant
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
yuris/spacetimedb-defold#4
No description provided.