Skip to content

DeserializeWithLengthPrefix() returning a generic object with Type arg #1009

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

luca-domenichini
Copy link

This PR adds 2 DeserializeWithLengthPrefix method overloads to ProtoBuf.Serializer, with Type as first argument.

The new methods returns an object instead of <T>.

Sometimes developers do not have the generic T type argument, but instead they have a Type. Having this PR merged, will give developers the possibility to deserialize in those cases too.

@mgravell
Copy link
Member

The Serializer.NonGeneric API already exposes TryDeserializeWithLengthPrefix(...) which I think provides everything here - and there are multiple overloads under RuntimeTypeModel.Default.DeserializeWithLengthPrefix(...). If we do add anything extra: it should probably go on Serializer.NonGeneric, but honestly: I'm not sure we need an additional API here. Thoughts?

@luca-domenichini
Copy link
Author

luca-domenichini commented Jan 24, 2023

Hi Marc,
thanks for your quick reply.

I have been using RuntimeTypeModel.Default.DeserializeWithLengthPrefix(...) for some time infact.

I just figured it would be a slight improvement in the Serializer API to expose the non-generic method too, instead of relying on a criptic "RuntimeTypeModel".
It would probably be better to include the non-generic methods in the Serializer.NonGeneric prop as you mentioned. If you wish, I can refactor the PR to include them there.
The TryDeserializeWithLengthPrefix(...) is not a good solution having just the Type and a Stream.

I would say, that having these 5 methods in Serializer.NonGeneric, it would be good to have the "**WithLengthPrefix" overloads paired with them.
image

Thanks for your attention.

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.

2 participants