tafia / quick-protobuf

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

Add possibility to read message with speciefied length #109

Closed foesi closed 6 years ago

foesi commented 6 years ago

As you can read in https://developers.google.com/protocol-buffers/docs/techniques the protobuf protocol does not specify the format how the length of a message is stated. If you communicate with an entity which does not encode it's message length in varints you are not able to read them. Therfore this fix should enable you to read your own format of message size and read the message of specified length.

This should fix #108

If you merge this it would be nice if you can publish it soon because I am relying on this fix and currently depending on a local Version of quick-protobuf. Thank you.

foesi commented 6 years ago

Thank you for the fast response.

I renamed the private fucnctions read_len_size to read_len because it is now the more general function and "just" reads bytes by a specified length and the read_len function to read_len_varint (maybe read_len_by_varint is better). I kept the name read_message to stay consistent in the public api. (I was the first one complaining about it so I assume normally the length prefix is a varint and therfore the normal behaviour gets the shorter name). The function read_message_size became read_message_by_len that is two character less.

What do you think?

tafia commented 6 years ago

I like it thanks! I'll fix the rustfmt error (I think the api got updated).

tafia commented 6 years ago

Published v0.6.2