Skip to content
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

Protobuf packed encoding/decoding #1830

Merged
merged 15 commits into from
Feb 2, 2022
Merged

Conversation

pdvrieze
Copy link
Contributor

@pdvrieze pdvrieze commented Jan 14, 2022

To address issue #1829 I've implemented support for protobuf packed fields. This is enabled using a new annotation.
Per the protocol it only supports primitive integers.

While there are some small updates in the libraries I've not attempted to move existing code paths over (the RepeatedDecoder
and NestedRepeatedEncoder classes etc. come to mind.

pdvrieze and others added 15 commits February 1, 2022 22:03
… 1, 2 or 5) to allow

decoders decode either format independently of the proto specification. Make sure to test
this flexibility in the parser.
…t to be used to effectively

peek the type without assumptions on state.
…ruct methods to be in

line with other list handling. It also ensures consistent reading of run lengths and means
that the encoders/decoders don't need to handle the initial structure start (and writing
can handle the writing of the subBuffer automatically at the end of the structure when the
run length is known).
…/ProtoTypes.kt


Add link to packed

Co-authored-by: Leonid Startsev <sandwwraith@users.noreply.github.com>
…that outputs of the serializer should never hit this exception.
…ports inputs in either format,

independent of the annotation. The annotation only affects writing.
… of strings

and "packed" toplevel arrays. The checking for eof works as bytesize is always >= array length.
Copy link
Member

@sandwwraith sandwwraith left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you, this feature would be really helpful!

@sandwwraith sandwwraith merged commit c78e950 into Kotlin:dev Feb 2, 2022
@pdvrieze pdvrieze deleted the packedProtobuf branch February 2, 2022 20:18
@achojoao
Copy link

@sandwwraith is this going to be included in the next release?

@sandwwraith
Copy link
Member

@achojoao Yes, it is merged to dev already.

pdvrieze added a commit to pdvrieze/kotlinx.serialization that referenced this pull request Apr 29, 2022
* Create an annotation to request packing of collections.

* The specification only allows packing for primitive types (wire types 1, 2 or 5) to allow
decoders decode either format independently of the proto specification.

* Make pushback work in respect to currentType/currentId. This allows it to be used to effectively
peek the type without assumptions on state.

* Clarify in the documentation that reading will (per the standard) supports inputs in either format,
independent of the annotation. The annotation only affects writing.

* Support decoding "packed" arrays as toplevels. Add tests for handling of strings
and "packed" toplevel arrays. The checking for eof works as bytesize is always >= array length.
@achojoao
Copy link

achojoao commented May 3, 2022

@sandwwraith Any news on when the new version of the library with this included is going to be released?

@sandwwraith
Copy link
Member

I think we need a fresh release, so I'd try to publish it in the following days

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.

None yet

3 participants