Stream: API design

Topic: Decode record


view this post on Zulip Brendan Hansknecht (Jul 08 2024 at 01:32):

I am a bit confused by how we decode records.

    record :
        state,
        (state, Str -> [Keep (Decoder state state err), Skip]),
        (state -> Result val err)
        -> Decoder state val err where state implements DecoderFormatting

Specifically I am confused by Skip. If we are decoding a record and find an unknown field, do we really want to skip it in decoding? I would assume that we would want to return an error on extraneous fields existing? Maybe with a way to explicitly skip some fields? Just a bit confused by this design.

view this post on Zulip Ayaz Hafiz (Jul 08 2024 at 01:37):

i believe it is for unknown fields yes

view this post on Zulip Ayaz Hafiz (Jul 08 2024 at 01:38):

it feels like deciding whether that should error or not should be a decision of the concrete decoder

view this post on Zulip Brendan Hansknecht (Jul 08 2024 at 01:39):

Ah yeah, I guess that could be a config stored in the decoder state. Was thinking it might be nice to be a per record decision instead of a whole decoder decision. But I'm sure with opaque types and custom implementations, the state could be temporarily modified to enable/disable this feature.

view this post on Zulip Luke Boswell (Jul 08 2024 at 01:46):

It's configurable in Json implementation, to either skipp or fail I think.

view this post on Zulip Brendan Hansknecht (Jul 08 2024 at 01:47):

Cool, so definitely a solved problem. Though only configurable at the whole decoder level. Cause to set it for a specific sub decoder would take adding the configuration to skip/fail to EncoderFormatting.

view this post on Zulip Brendan Hansknecht (Jul 08 2024 at 01:48):

If that ends up being needed, it can be added later.

view this post on Zulip Brendan Hansknecht (Jul 08 2024 at 01:49):

Related question to this api: (state, Str -> [Keep (Decoder state state err), Skip]),

Record decoding requires a string field name. I guess for binary formats that don't include field names, this means we have to decode records as tuples and then map them to a record? Cause the decoder can never know field names?


Last updated: Jul 06 2025 at 12:14 UTC