Comments (8)
Hi @altavir,
the readThis()
and writeThis(obj)
functions look confusing to me, I propose something like readObject
and writeObject
, similar to readInt
and writeInt
.
Moreover I don't understand why IOFormat
interface contains only extension methods, do you wish to use it as an implicit parameter?
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).
from kotlinx-io.
@fvasco readObject
and writeObject
names are possible, I used it at some moment, but then changed (don't remember, why). Yes, I want to use the feature in context-oriented way, so it is possible to add additional serialization possibilities with additional nested contexts (or with KEEP-176). Also in this way it is easier to implement those methods. readDouble
looks better than input.reaadDouble
and one can use nested formats. But I am not sure that it is the best solution.
Serialization sadly does not have something similar at the moment. It has KSerializaer
which works in a similar way, but with Encoder
and Decoder
, not with raw byte IO. Also serialization uses very limited old version of IO internally. I think that the idea is to make this library a base for serialization runtime, ktor and other things in the future and remove code duplication.
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 IOFormats
instead of some kind of implicit inner implementations.
from kotlinx-io.
I am sorry, @altavir,
but I not agree with the above reply.
I want to use the feature in context-oriented way, so it is possible to add additional serialization possibilities with additional nested contexts (or with KEEP-176)
It looks like the poor-man KEEP-87 implementation.
But I am not sure that it is the best solution.
Me too
I think that the idea is to make this library a base for serialization runtime, ktor and other things in the future and remove code duplication.
I don't understand.
Is serlializing arbitrary object and deprecating kotlinx.serialization
a hidden goal of this library?
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.
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.
You are assuming that every list MUST be encoded using your format, do you really think that this implementation will cover all use cases?
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.
from kotlinx-io.
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.
from kotlinx-io.
Hi @altavir,
so, recap:
You are proposing to add only the IOFormat
interface?
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.
I am sorry for misunderstanding.
from kotlinx-io.
@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 writeThis
by writeObject
. It looks more concise.
from kotlinx-io.
I've replaced writeThis by writeObject. It looks more concise.
Please think twice about motivation.
this
has a special meaning in Kotlin.
maybe two small extensions for lists and maps
So my disapproval is still valid.
from kotlinx-io.
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.
from kotlinx-io.
Related Issues (20)
- Path.parent doesn't work with default Windows path separator
- Support listing files in a directory Path HOT 4
- Support getting a canonical file Path HOT 2
- Evaluate and tune Segment::compact behaviour
- Support read-only views with random-access capability
- Support encodings other than UTF-8 and support BOM handling HOT 2
- Update Kotlin to 1.9.20
- Random access to files HOT 2
- Add permissions to FileMetadata HOT 2
- Add SystemFileSystem.copy() HOT 4
- Support Wasm Wasi target
- Problems when creating own implementation of RawSink/RawSource HOT 2
- Support ByteBuffer as a backing storage on JVM HOT 8
- Files and FileSystems support HOT 3
- Add benchmarks targeting kotlinx.io.Source methods and extensions
- `Path.parent` for Native returns null for space-only parent directory HOT 1
- `SystemPathSeparator` defined as `/` for Window HOT 3
- Reuse allcocated arrays HOT 2
- SystemFileSystem.sink does not create empty file on NodeJs target HOT 1
- Cannot get position from Source HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from kotlinx-io.