Skip to content

Add change_output_type to StreamDeserializer#25

Open
dr-bonez wants to merge 1 commit into
kanidm:mainfrom
dr-bonez:change-output-type
Open

Add change_output_type to StreamDeserializer#25
dr-bonez wants to merge 1 commit into
kanidm:mainfrom
dr-bonez:change-output-type

Conversation

@dr-bonez

Copy link
Copy Markdown

Summary

Adds a change_output_type method to StreamDeserializer that lets you switch the deserialization target type without rebuilding the deserializer or losing your position in the stream.

Motivation

When reading a CBOR stream that contains a mix of different types (e.g. a header followed by a sequence of records), you currently have to create a new StreamDeserializer for each type you want to read. Since the T parameter on StreamDeserializer is only used as a PhantomData marker, there's no reason you shouldn't be able to swap it out on the fly.

This comes up in practice when you have a framed protocol or file format where different sections of the stream have different schemas. Without this, you end up having to drop down to serde_cbor_2::Value and convert manually, or do awkward workarounds with the reader.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant