fling_pickle library

Lightweight object Serialization and Deserialization (SerDes).

In short, a "pickle" represents a Memento (design pattern). Pickles can be passed around, persisted on disk or in the cloud, and used to reproduce the original object.

This library aims to be lightweight and shies away from reflection magic or intrusive changes to your classes. In fact, you can probably use the system without making any changes to your serializable classes, though you will need to map the attributes that define your class to the Pickle attributes.

Pickle picklePerson(final Person person) {
  return Pickle()
    .withString('name', Person.name),
    .withDouble('age', Person.age);
}

Person depicklePerson(final Pickle pickle) {
  return Person(
    name: pickle.readString('name'),
    age: pickle.readDouble('age'),
  );
}

For full integration, have your serializable class implement Pickleable. This will mean the serializable class gets a "depickle" method and gives you access to some handy SerDes methods on the Pickle class itself.

class Person implements Pickleable {...}

final pickle = Pickle()
  .withPickleable('mom', Person('Nancy', 34.6))
  .withPickleable('dad', Person('Bob', 32.3))
  .withPickleables('children', [
      Person('harry', 4.5),
      Person('margaret', 3.2),
    ]);

Classes

BinaryPickler
Converts Pickles to and from a binary representation.
JsonPickler
Reads and writes Pickles to and from Dart's JSON representation.
Pickle
A Memento-like abstraction of an object's state.
Pickleable
A class that can be turned into a Pickle.
PickleBuilder
PickleReader<T>
Can read Pickles from data sources.
PickleSyncReader<T>
Can read Pickles from data sources.
PickleSyncWriter<T>
Can write a Pickle to persistence.
PickleWriter<T>
Can write a Pickle to persistence.

Exceptions / Errors

PickleTypeError
Error thrown when attempting to read a value from a Pickle that is of a different type than expected.