raft: use Equal in example

release-2.0
Blake Mizerany 2014-08-22 17:00:42 -07:00 committed by Yicheng Qin
parent 92bdb1390d
commit c312d6efad
3 changed files with 41 additions and 2 deletions

View File

@ -10,7 +10,6 @@ func applyToStore(ents []Entry) {}
func sendMessages(msgs []Message) {}
func saveStateToDisk(st State) {}
func saveToDisk(ents []Entry) {}
func stateChanged(prev, st State) bool { return false }
func Example_Node() {
n := Start(context.Background(), "", 0, 0)
@ -26,7 +25,7 @@ func Example_Node() {
log.Fatal(err)
}
if stateChanged(prev, st) {
if prev.Equal(st) {
saveStateToDisk(st)
prev = st
}

View File

@ -22,6 +22,8 @@ import math "math"
import io "io"
import code_google_com_p_gogoprotobuf_proto "code.google.com/p/gogoprotobuf/proto"
import bytes "bytes"
// Reference proto, json, and math imports to suppress error if they are not otherwise used.
var _ = proto.Marshal
var _ = &json.SyntaxError{}
@ -228,3 +230,40 @@ func encodeVarintState(data []byte, offset int, v uint64) int {
data[offset] = uint8(v)
return offset + 1
}
func (this *State) Equal(that interface{}) bool {
if that == nil {
if this == nil {
return true
}
return false
}
that1, ok := that.(*State)
if !ok {
return false
}
if that1 == nil {
if this == nil {
return true
}
return false
} else if this == nil {
return false
}
if this.Term != that1.Term {
return false
}
if this.Vote != that1.Vote {
return false
}
if this.Commit != that1.Commit {
return false
}
if this.LastIndex != that1.LastIndex {
return false
}
if !bytes.Equal(this.XXX_unrecognized, that1.XXX_unrecognized) {
return false
}
return true
}

View File

@ -6,6 +6,7 @@ option (gogoproto.marshaler_all) = true;
option (gogoproto.sizer_all) = true;
option (gogoproto.unmarshaler_all) = true;
option (gogoproto.goproto_getters_all) = false;
option (gogoproto.equal_all) = true;
message State {
required int64 term = 1 [(gogoproto.nullable) = false];