func (req *AppendEntriesRequest) Encode(w io.Writer) (int, error) {
pb := &protobuf.AppendEntriesRequest{
Term: proto.Uint64(req.Term),
PrevLogIndex: proto.Uint64(req.PrevLogIndex),
PrevLogTerm: proto.Uint64(req.PrevLogTerm),
CommitIndex: proto.Uint64(req.CommitIndex),
LeaderName: proto.String(req.LeaderName),
Entries: req.Entries,
}
p, err := proto.Marshal(pb)
if err != nil {
return -1, err
}
return w.Write(p)
}
For this function, is "w" input? what about req? Kinda confused here. Thanks
that is a Go Method
AppendEntriesRequest
is a type and req *AppendEntriesRequest
is a pointer to that type. You can compare req
in other languages as this
or self
w io.Writer
is the input of the function.
(int, error)
are the return values.
You can invoke this method by instantiating a AppendEntriesRequest
structure:
r := &AppendEntriesRequest{}
n, err := r.Encode(...)