Skip to content

Support for encoding/decoding a sequence of values#20

Merged
brudaswen merged 11 commits intobrudaswen:mainfrom
UnknownJoe796:sequences
Dec 13, 2024
Merged

Support for encoding/decoding a sequence of values#20
brudaswen merged 11 commits intobrudaswen:mainfrom
UnknownJoe796:sequences

Conversation

@UnknownJoe796
Copy link
Copy Markdown
Contributor

This PR is intended to be for after #19 might be merged, as it is dependent.

Built explicitly to stream the processing of rows in a CSV effectively. Introduces the following functions to CSV:

// Encodes a sequence of values in a streaming fashion.
fun <T> encodeSequenceToAppendable(serializer: KSerializer<T>, values: Sequence<T>, appendable: Appendable) 

// Begin encoding, gives back a function to add an item.  Useful in conjuction with `suspend`.
@ExperimentalSerializationApi
fun <T> beginEncodingToAppendable(serializer: KSerializer<T>, appendable: Appendable): (T) -> Unit

// Decodes values as a sequence for doing streaming operations.
@ExperimentalSerializationApi
fun <T> decodeSequenceFromReader(deserializer: KSerializer<T>, reader: Reader): Sequence<T>

// A safer version of the above where the reader is closed by the function.
fun <T> decodeFromReaderUsingSequence(deserializer: KSerializer<T>, reader: Reader, handler: (Sequence<T>) -> Unit)

I acknowledge this API as needing additional review moreso than my other PR, which simply introduced using Reader and Appendable. We need to make sure the introduced API does not cause confusion or subtle issues.

This is the same as a previous PR but from a fork where I can allow editing from maintainers.

UnknownJoe796 and others added 7 commits February 23, 2023 16:14
# Conflicts:
#	library/src/test/kotlin/kotlinx/serialization/test/TestingFramework.kt
…equences

# Conflicts:
#	library/src/main/kotlin/kotlinx/serialization/csv/Csv.kt
# Conflicts:
#	library/src/main/kotlin/kotlinx/serialization/csv/Csv.kt
@brudaswen brudaswen merged commit bf89d3c into brudaswen:main Dec 13, 2024
@brudaswen
Copy link
Copy Markdown
Owner

brudaswen commented Dec 14, 2024

Thanks for the contribution. I changed the API a bit, but it should allow the same streaming support.

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.

2 participants