tafia / quick-protobuf

A rust implementation of protobuf parser
MIT License
452 stars 87 forks source link

Serialize/Deserialize slices without length prefix #208

Open AlaaZorkane opened 2 years ago

AlaaZorkane commented 2 years ago

Following: https://github.com/tafia/quick-protobuf/issues/202

This PR adds the following:

snproj commented 1 year ago

Hi! The PR looks good; I was actually considering a few options, since this seems to be a common stumbling block for new users:

What do you think? Something to consider is the fact that we might have breaking changes already anyway from other PRs #235 and #240.

ScarboroughCoral commented 1 year ago

Is there any progress on this pr :-)

snproj commented 1 year ago

In my opinion, since we already have breaking changes from other PRs that look like they're going to be merged, let's go with option 1 above. That is, just change the functions to no longer include the prefix, and don't include any backwards-compatibility functions that do, because that seems a bit messy to me. Counterarguments are welcome though!

I don't know of any particular use for the functions that have length prefixes, so my instinct is to remove them for the sake of keeping the API intuitive and small. Are you okay with this @AlaaZorkane?

I understand of course that this PR was awhile ago haha 😅 so I will likely make the change myself in a bit if there's no response. Do let me know if you want to do it yourself though!

ScarboroughCoral commented 1 year ago

I think can add two methods this pr or next pr

  1. serialize_into_slice_with_variant(variant: Option<T>, msg: M)
  2. deserialize_from_slice with_variant() -> Result<variant:Option<T>> because I don't know what kind of a binary message is, I can serialize the message with a variant at head, and deserialize the message getting the variant and check my variant table get the type of the binary message and deserialize it.