Giter Club home page Giter Club logo

Comments (8)

fvasco avatar fvasco commented on June 17, 2024 1

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.

altavir avatar altavir commented on June 17, 2024

@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.

fvasco avatar fvasco commented on June 17, 2024

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?

Is it better to use a variable size for `list.size`, to reduce the encoded size of frequently used small list?

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.

altavir avatar altavir commented on June 17, 2024

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.

fvasco avatar fvasco commented on June 17, 2024

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.

altavir avatar altavir commented on June 17, 2024

@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.

fvasco avatar fvasco commented on June 17, 2024

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.

fzhinkin avatar fzhinkin commented on June 17, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.