scala / pickling

Fast, customizable, boilerplate-free pickling support for Scala
lampwww.epfl.ch/~hmiller/pickling
BSD 3-Clause "New" or "Revised" License
831 stars 79 forks source link

Design of PickleFormat trait #61

Open maqdev opened 10 years ago

maqdev commented 10 years ago

Hi!

I've created a library using the power off scala.pickling.

While I was working on that library I was struggling with PickleFormat.

The problem is that this is solid type for both pickle/unpickle operations. If you're serializing into database there is different types of objects for reading/writing like Statement class (write parameters) and ResultSet/Row classes for reading. For example in PickleFormat you have to define method createBuilder without parameters which should create instance of empty output type. This is problematic with the database where you have a session/connection object and the output (Statement) is always bound to connection. My proposal is to define separate traits for input/output types:

trait PickleInputFormat {
  def createReader(pickle: PickleType, mirror: Mirror): PReader
}

trait PickleOutputFormat {
  type OutputType
  def createBuilder(): PBuilder
  def createBuilder(out: OutputType): PBuilder
}

This allows you to create pickle method with implicit parameters that accepts Statement/Session of database where it's available. The same applies to PickleOutputFormat.

If you're interested in the library please see it here: https://github.com/InnovaCo/capickling The library is for the Cassandra and allows binding (which is actualy serialization) to database statement and mapping (deserialization) from database results.

jsuereth commented 9 years ago

@maqdev I really like your proposal. Would you be interested in trying to put more effort behind it for a 0.11.x release? I'm curious what else would have to be done to make this a reality.