[#274] reputation: Adapt converters and encoding methods on messages

Signed-off-by: Pavel Karpy <carpawell@nspcc.ru>
This commit is contained in:
Pavel Karpy 2021-04-22 10:40:12 +03:00 committed by Alex Vanin
parent 1076478b29
commit 541a56aae1
4 changed files with 38 additions and 1 deletions

View file

@ -458,6 +458,7 @@ func (x *SendIntermediateResultRequestBody) ToGRPCMessage() grpc.Message {
if x != nil {
m = new(reputation.SendIntermediateResultRequest_Body)
m.SetEpoch(x.epoch)
m.SetIteration(x.iter)
m.SetTrust(x.trust.ToGRPCMessage().(*reputation.PeerToPeerTrust))
}
@ -480,6 +481,7 @@ func (x *SendIntermediateResultRequestBody) FromGRPCMessage(m grpc.Message) erro
return err
}
x.epoch = v.GetEpoch()
x.iter = v.GetIteration()
return nil

View file

@ -277,6 +277,7 @@ func (x *SendLocalTrustResponseBody) Unmarshal(data []byte) error {
const (
_ = iota
sendInterResBodyEpochFNum
sendInterResBodyIterFNum
sendInterResBodyTrustFNum
)
@ -290,11 +291,25 @@ func (x *SendIntermediateResultRequestBody) StableMarshal(buf []byte) ([]byte, e
buf = make([]byte, x.StableSize())
}
offset, err := protoutil.UInt32Marshal(sendInterResBodyIterFNum, buf, x.iter)
var (
offset, n int
err error
)
n, err = protoutil.UInt64Marshal(sendInterResBodyEpochFNum, buf, x.epoch)
if err != nil {
return nil, err
}
offset += n
n, err = protoutil.UInt32Marshal(sendInterResBodyIterFNum, buf[offset:], x.iter)
if err != nil {
return nil, err
}
offset += n
_, err = protoutil.NestedStructureMarshal(sendInterResBodyTrustFNum, buf[offset:], x.trust)
if err != nil {
return nil, err
@ -304,6 +319,7 @@ func (x *SendIntermediateResultRequestBody) StableMarshal(buf []byte) ([]byte, e
}
func (x *SendIntermediateResultRequestBody) StableSize() (size int) {
size += protoutil.UInt64Size(sendInterResBodyEpochFNum, x.epoch)
size += protoutil.UInt32Size(sendInterResBodyIterFNum, x.iter)
size += protoutil.NestedStructureSize(sendInterResBodyTrustFNum, x.trust)

View file

@ -109,6 +109,7 @@ func GenerateSendIntermediateResultRequestBody(empty bool) *reputation.SendInter
m := new(reputation.SendIntermediateResultRequestBody)
if !empty {
m.SetEpoch(123)
m.SetIteration(564)
}

View file

@ -297,11 +297,29 @@ func (x *SendLocalTrustResponse) SetBody(v *SendLocalTrustResponseBody) {
// SendIntermediateResultRequestBody is a structure of SendIntermediateResult request body.
type SendIntermediateResultRequestBody struct {
epoch uint64
iter uint32
trust *PeerToPeerTrust
}
// GetEpoch returns epoch number in which the intermediate trust was assessed.
func (x *SendIntermediateResultRequestBody) GetEpoch() uint64 {
if x != nil {
return x.epoch
}
return 0
}
// SetEpoch sets epoch number in which the intermediate trust was assessed.
func (x *SendIntermediateResultRequestBody) SetEpoch(v uint64) {
if x != nil {
x.epoch = v
}
}
// GetIteration returns sequence number of the iteration.
func (x *SendIntermediateResultRequestBody) GetIteration() uint32 {
if x != nil {