Last active
February 23, 2018 20:28
-
-
Save joshgarnett/454b34da33738d06ceddeedb84398308 to your computer and use it in GitHub Desktop.
protoc-gen-zsharp example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
syntax = "proto3"; | |
import "event_plugin.proto"; | |
package example; | |
message Foo { | |
option (com.zynga.runtime.protobuf.event_sourced) = true; | |
int32 foo_id = 1; | |
Bar bar = 2; | |
} | |
message Bar { | |
option (com.zynga.runtime.protobuf.event_sourced) = true; | |
int32 bar_id = 1; | |
repeated Baz baz = 2; | |
} | |
message Baz { | |
option (com.zynga.runtime.protobuf.event_sourced) = true; | |
int32 baz_id = 1; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var foo = new Foo(); | |
foo.Bar = new Bar(); // creates set delta event | |
foo.Bar.Baz.Add(new Baz()); // creates add list delta event | |
foo.Bar.Baz[0].baz_id = 10; // creates update list delta event | |
// generate the events for the changes | |
// This is what you would persist as a journal entry | |
var events = foo.GenerateEvents(); | |
// apply the events | |
var fooB = new Foo(); | |
fooB.ApplyEvents(root); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Rough example of what the events look like | |
// foo.Bar = new Bar(); | |
var setEvent = new EventData { | |
Path = [2], | |
Set = new EventContent { | |
ByteData = bar.ToByteString() | |
} | |
} | |
// foo.Bar.Baz.Add(new Baz()); | |
var listEvent = new EventData { | |
Path = [2, 2], | |
ListEvent = new ListEvent { | |
ListAction = AddList, | |
Content = new EventContent { | |
ByteData = baz.ToByteString() | |
} | |
} | |
} | |
// foo.Bar.Baz[0].baz_id = 10; | |
var listEvent = new EventData { | |
Path = [2, 2], | |
ListEvent = new ListEvent { | |
ListAction = UpdateList, | |
Index = 0, | |
EventData = new EventData { | |
Path = [1], | |
Set = new EventContent { | |
I32 = 10 | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment