-
Notifications
You must be signed in to change notification settings - Fork 63
[io-2] Conceptual design for IO format #62
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
Comments
Hi @altavir, Moreover I don't understand why with (output) {
with (UserFormat) {
with (BookFormat) {
write (user)
write (book)
}
}
} In closing, I wish understand why should this feature be included in this library, serialization libraries already perform this task (see kotlinx.serialization as example). |
@fvasco Serialization sadly does not have something similar at the moment. It has As for why do I think it is needed here. As you said, several libraries do use similar features already, but we have a problem of interface compatibility and moving functionality from one library to another one, one need to re-implement everything according to new interface. Declaring a single interface and a few very basic implementations (like list I've mentioned) would not increase the size of the library, but will significantly increase plug-ability. After I wrote the post, I've also thought that what I am trying to do is similar to python pickle, meaning fast way to serialize-deserialize everything. The difference is that I propose to use explicit |
I am sorry, @altavir,
It looks like the poor-man KEEP-87 implementation.
Me too
I don't understand.
This is the seed of the the holy war between big-endian and little-endian, each one assumes that there is only one, right, method to serialize a word. I'm not interested to the answer (if it exists), I thinks that this is not the right place to debate about the data carried by the byte buffers. |
Serialization library works in two stages: first stage transforms kotlin objects into intermediate representation (Encoder/Decoder). Then this representation is transformed or streamed into actual byte IO. While the front part is being covered by compiler magic and serialization-runtime library, the back part is actually a quite limited version of this library. I think it was planned to bring everything into a single ecosystem one day. For example, we want streaming engine for serialization, which is possible only kotlinx.io. As for one size fits all. This is not the thing I am proposing. You can have any number of different formats for the same object. You can have a parameter in the format which switches little/big endian. Or you can have and use different objects for that. The proposal includes only common interface. |
Hi @altavir, You are proposing to add only the interface IOFormat<T : Any> {
fun Output.writeThis(obj: T)
fun Input.readThis(): T
}
fun <T : Any> Input.readWith(format: IOFormat<T>): T = format.run { readThis() }
fun <T : Any> Output.readWith(format: IOFormat<T>, obj: T) = format.run { writeThis(obj) } If so, apart from the actual API design already commented, it looks good. |
@fvasco Yes, the idea is to introduce only interface and maybe two small extensions for lists and maps. The rest should be done in the external plugins. I've replaced |
Please think twice about motivation.
So my disapproval is still valid. |
We're rebooting the kotlinx-io development (see #131), all issues related to the previous versions will be closed. Consider reopening it if the issue remains (or the feature is still missing) in a new version. |
Here are some thoughts about IO format functionality I would like to add as soon as IO-2 is out. The idea is that we can add an easy way to write objects to streams and read them from streams. The resulting API could then simplify the work with serialization and file IO.
The idea is shown in the following example (using io-1 API):
IOFormat
represents a way to read and write data with Input and Output. One can construct a format for complex objects from the formats of individual parts. It could be probably used as a way to customize serialization backends. The similar idea is currently used in kmath in-memory operations on data: https://github.com/mipt-npm/kmath/blob/dev/kmath-memory/src/commonMain/kotlin/scientifik/memory/MemorySpec.kt.The text was updated successfully, but these errors were encountered: