Skip to content

Instantly share code, notes, and snippets.

@joshgarnett
Last active February 23, 2018 20:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joshgarnett/454b34da33738d06ceddeedb84398308 to your computer and use it in GitHub Desktop.
Save joshgarnett/454b34da33738d06ceddeedb84398308 to your computer and use it in GitHub Desktop.
protoc-gen-zsharp example
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;
}
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);
// 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