-
Notifications
You must be signed in to change notification settings - Fork 613
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
Conversation
e6f2692
to
72dedf3
Compare
fdcd95a
to
a0b9502
Compare
formats/protobuf/commonMain/src/kotlinx/serialization/protobuf/ProtoTypes.kt
Outdated
Show resolved
Hide resolved
formats/protobuf/commonMain/src/kotlinx/serialization/protobuf/internal/Helpers.kt
Outdated
Show resolved
Hide resolved
formats/protobuf/commonMain/src/kotlinx/serialization/protobuf/internal/PackedArrayDecoder.kt
Outdated
Show resolved
Hide resolved
formats/protobuf/commonMain/src/kotlinx/serialization/protobuf/internal/PackedArrayDecoder.kt
Outdated
Show resolved
Hide resolved
formats/protobuf/commonMain/src/kotlinx/serialization/protobuf/internal/ProtobufDecoding.kt
Outdated
Show resolved
Hide resolved
formats/protobuf/commonMain/src/kotlinx/serialization/protobuf/internal/ProtobufDecoding.kt
Show resolved
Hide resolved
formats/protobuf/commonTest/src/kotlinx/serialization/protobuf/PackedArraySerializerTest.kt
Show resolved
Hide resolved
formats/protobuf/commonTest/src/kotlinx/serialization/protobuf/PackedArraySerializerTest.kt
Outdated
Show resolved
Hide resolved
… 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).
…ted structures - invalid in packing).
…/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.
f2950fd
to
e3a5107
Compare
There was a problem hiding this 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 is this going to be included in the next release? |
@achojoao Yes, it is merged to dev already. |
* 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.
@sandwwraith Any news on when the new version of the library with this included is going to be released? |
I think we need a fresh release, so I'd try to publish it in the following days |
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.