Skip to content

Instantly share code, notes, and snippets.

@joshgarnett
Last active February 5, 2018 22:41
Show Gist options
  • Save joshgarnett/a69bf60757f7b627f1e75d29246e3a0d to your computer and use it in GitHub Desktop.
Save joshgarnett/a69bf60757f7b627f1e75d29246e3a0d to your computer and use it in GitHub Desktop.
Proposal for deltas of messages within a RepeatedField
var foo = new SimpleNestedMessage();
list.Add(foo);
// Generates: new EventData { Action = AddList, EventContent = foo.toByteString() , Path = [1, 0]} // 0 is the index of foo object
// Sets _root and _path in the foo instance
// if _root already exists throw exception, can't add message to two parents at once
foo.a = 10;
// Generates: new EventData { Action = Set, EventContent = 10 , Path = [1, 0, 1]}
foo.b = "hello";
// Generates: new EventData { Action = Set, EventContent = "hello" , Path = [1, 0, 2]}
var bar = new SimpleNestedMessage();
list.Insert(bar);
// Generates: new EventData { Action = InsertList, Field = 0, EventContent = bar.toByteString() , Path = [1, 0]} // 0 is the index of bar object
// Updates path on any objects that appear after bar, in this case foo, becomes index 1
// Sets _root and _path in the bar instance
// if _root already exists throw exception, can't add message to two parents at once
foo.a = 11;
// Generates: new EventData { Action = Set, EventContent = 11 , Path = [1, 1, 1]} // 1 is the index of foo object now
list.RemoveAt(0);
// Generates: new EventData { Action = RemoveAtList, Path = [1, 0]}
// Updates path on any objects that appear after bar, in this case foo, becomes index 1
// clears _root & _path on the bar object
var baz = new SimpleNestedMessage();
list[0] = baz;
// Generates: new EventData { Action = ReplaceList, EventContent = baz.toByteString() , Path = [1, 0]}
// clears _root & _path on the foo object
// Sets _root and _path in the baz instance
// if _root already exists throw exception, can't add message to two parents at once
message SimpleNestedMessage {
int64 a = 1;
string b = 2;
}
message SimpleList {
repeated SimpleNestedMessage = 1;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment