From 541a56aae1f8245d8b64512e58d3360df155dddc Mon Sep 17 00:00:00 2001 From: Pavel Karpy Date: Thu, 22 Apr 2021 10:40:12 +0300 Subject: [PATCH] [#274] reputation: Adapt converters and encoding methods on messages Signed-off-by: Pavel Karpy --- v2/reputation/convert.go | 2 ++ v2/reputation/marshal.go | 18 +++++++++++++++++- v2/reputation/test/generate.go | 1 + v2/reputation/types.go | 18 ++++++++++++++++++ 4 files changed, 38 insertions(+), 1 deletion(-) diff --git a/v2/reputation/convert.go b/v2/reputation/convert.go index 52df2fa..8aa9aa0 100644 --- a/v2/reputation/convert.go +++ b/v2/reputation/convert.go @@ -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 diff --git a/v2/reputation/marshal.go b/v2/reputation/marshal.go index 20fa677..2f08408 100644 --- a/v2/reputation/marshal.go +++ b/v2/reputation/marshal.go @@ -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) diff --git a/v2/reputation/test/generate.go b/v2/reputation/test/generate.go index 65e50e8..fbd4bd1 100644 --- a/v2/reputation/test/generate.go +++ b/v2/reputation/test/generate.go @@ -109,6 +109,7 @@ func GenerateSendIntermediateResultRequestBody(empty bool) *reputation.SendInter m := new(reputation.SendIntermediateResultRequestBody) if !empty { + m.SetEpoch(123) m.SetIteration(564) } diff --git a/v2/reputation/types.go b/v2/reputation/types.go index b7ef545..b1bd707 100644 --- a/v2/reputation/types.go +++ b/v2/reputation/types.go @@ -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 {