Skip to content

Deserialize empty protobuf list on iOS #355

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

Closed
webfrea-k opened this issue Feb 1, 2019 · 5 comments
Closed

Deserialize empty protobuf list on iOS #355

webfrea-k opened this issue Feb 1, 2019 · 5 comments

Comments

@webfrea-k
Copy link

webfrea-k commented Feb 1, 2019

I have the following data class:

@Serializable
data class Test (
        @Optional @SerialId(1) var events: List<Event> = emptyList(),
        @Optional @SerialId(2) var games: List<Game> = emptyList()
)

Protobuf deserialization (proto3) works correctly on Android and iOS if both values are not empty. If at least one list property is empty (empty list), the deserialization fails on iOS with error: Unexpected EOF.

If empty property is commented out of data class, deserialization works on iOS as well.

@sandwwraith
Copy link
Member

Hi, could you please give a sample of protobuf bytes so I could debug this? And definitions of Event and Game classes, too

@webfrea-k
Copy link
Author

Unfortunately the only example producing this error has 28k+ bytes in the response (and the entire Test class is way bigger than just events and games too). But maybe my observations can help:

I've implemented custom deserializer for this class and debug the following while loop:

loop@ while (true) {
        when (val i = inp.decodeElementIndex(descriptor)) { ... }
}
inp.endStructure(descriptor)

Is it possible, that decodeElementIndex is somehow not incremented if the repeated field is empty and while loop eventually runs until EOF is thrown?

@sandwwraith
Copy link
Member

Hm, do you use ktor client on ios? It could be possibly related to #360 , since errors occur only on big data

@webfrea-k
Copy link
Author

You are correct! I managed to make the response shorter and data is indeed handled correctly on iOS as well.

  • Max length working on both platforms (that I can re-produce): 96735 bytes
  • Length working on android and not on iOS: 128153 bytes

@sandwwraith
Copy link
Member

Kotlin/kotlinx-io#36 will fix this

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

No branches or pull requests

2 participants