|
1 | | - |
2 | 1 | This is a custom IFormatter implementation based on the |
3 | 2 | protobuf-net library by Marc Gravell, available at http://code.google.com/p/protobuf-net/ |
4 | 3 |
|
5 | | -By default, the formatter writes type information to the stream which is needed during deserialization. |
6 | 4 |
|
7 | | -Usage: |
8 | | -var formatter = new ProtoBufFormatter(); |
9 | | -formatter.Serialize(stream, graph); |
10 | | -object cloned = formatter.Deserialize(); |
| 5 | +To serialize using protobuf you need to annotate your types with ProtoContract and ProtoMember or |
| 6 | +configure a RunTimeTypeModel object and pass it to the ProtoBufFormatter constructor. |
| 7 | + |
| 8 | +To learn read, the protobuf-net docs, see examples in the protobuf-net source and the source |
| 9 | +of this repository. |
| 10 | + |
| 11 | + |
| 12 | +Once you have configured your types, there are a couple of static methods to help |
| 13 | +you get the OrigoDB configuration right: |
| 14 | + |
| 15 | +```csharp |
| 16 | + |
| 17 | + //Annotate your model and entities with ProtoContract and ProtoMember |
| 18 | + // or create a type model from code: |
| 19 | + var typeModel = TypeModel.Create(); |
| 20 | + //todo: add types, fields and subtypes to the typeModel |
| 21 | + |
| 22 | + |
| 23 | + var config = new EngineConfiguration(); |
| 24 | + |
| 25 | + //use helper methods |
| 26 | + ProtoBufFormatter.ConfigureSnapshots<MyModel>(config, typeModel); |
| 27 | + ProtoBufFormatter.Configure(config, FormatterUsage.Results, typeModel); |
| 28 | + |
| 29 | + //or do it yourself |
| 30 | + config.SetFormatterFactory((cfg,fu) => new ProtoBufFormatter<MyModel>(), FormatterUsage.Snapshot); |
| 31 | + |
| 32 | + //use the config when creating an engine |
| 33 | + var db = Db.For<MyModel>(config); |
| 34 | + db.WriteSnapshot(); |
| 35 | +``` |
| 36 | + |
| 37 | + |
0 commit comments