odnoklassniki/one-nio

Little get started for serializer

QIvan opened this issue · 4 comments

QIvan commented

Is there any tutorial 'hot to use serializer'?

I have serveral questions:

  1. Did I right understand that a work do through
  • one.nio.serial.Serializer#serialize
  • one.nio.serial.Serializer#deserialize
    Is it the best (for perfomance) way?
  1. What is the difference between persist and serialize?
  2. You told that there is a feature to request a schema. I didn't find it =(
  3. Can I add a custom Serializer for my type?

Thanks!

There is no tutorial, sorry. I'll be glad with any help on writing this.

  1. Right, this is a basic part of serialization API, and it is supposed to be fast.

  2. persist embeds serialization schema into the output array, so that result byte[] is self-sufficient for deserialization, even in a different JVM on a different machine. serialize produces smaller output as it does not store full schema, only the schema fingerprint. It also works faster. In order to decode data produced by serialize, all custom (non-bootstrap) serializers must be present in Repository. deserialize can decode both kinds of data.

  3. Automatic schema management is built into one-nio RPC mechanism, see RpcClient.invoke(). When making a remote call, a client may request an unknown schema from a server, or it may provide its own schema to a server if the other side responds with SerializerNotFoundException. Schema exchange is implemented using the same RPC request-response mechanism.

Out of RPC scope an application may implement its own schema management, e.g. a central database for schemas. The simplest way to store schemas is to call saveSnapshot which will make the complete persistable representation of current Repository state.

  1. Yes. Extend Serializer class, and register it using Repository.provideSerializer.
QIvan commented

many thanks for answers!
I hope I will be able to help you with tutorial.

QIvan commented

@apangin didn't you think about to extract serial package to self project?

I did. However, I don't think it's worth doing, because one-nio is a rather small library, and serialization is tightly coupled with other parts of it: util, RPC, bytecode generation etc. There was a similar question #6.