Skip to content

Commit 0bebf18

Browse files
committed
2 parents 766dc06 + caf5f6e commit 0bebf18

File tree

1 file changed

+33
-6
lines changed

1 file changed

+33
-6
lines changed

README.md

Lines changed: 33 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,37 @@
1-
21
This is a custom IFormatter implementation based on the
32
protobuf-net library by Marc Gravell, available at http://code.google.com/p/protobuf-net/
43

5-
By default, the formatter writes type information to the stream which is needed during deserialization.
64

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

Comments
 (0)