[#265] reputation: Implement converters and encoding methods on messages
Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
This commit is contained in:
parent
8ce1c5efcc
commit
ccae5a40ba
4 changed files with 517 additions and 4 deletions
|
@ -6,6 +6,38 @@ import (
|
|||
reputation "github.com/nspcc-dev/neofs-api-go/v2/reputation/grpc"
|
||||
)
|
||||
|
||||
const (
|
||||
_ = iota
|
||||
peerIDValFNum
|
||||
)
|
||||
|
||||
func (x *PeerID) StableMarshal(buf []byte) ([]byte, error) {
|
||||
if x == nil {
|
||||
return []byte{}, nil
|
||||
}
|
||||
|
||||
if buf == nil {
|
||||
buf = make([]byte, x.StableSize())
|
||||
}
|
||||
|
||||
_, err := protoutil.BytesMarshal(peerIDValFNum, buf, x.val)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return buf, nil
|
||||
}
|
||||
|
||||
func (x *PeerID) StableSize() (size int) {
|
||||
size += protoutil.BytesSize(peerIDValFNum, x.val)
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
func (x *PeerID) Unmarshal(data []byte) error {
|
||||
return message.Unmarshal(x, data, new(reputation.PeerID))
|
||||
}
|
||||
|
||||
const (
|
||||
_ = iota
|
||||
trustPeerFNum
|
||||
|
@ -26,7 +58,7 @@ func (x *Trust) StableMarshal(buf []byte) ([]byte, error) {
|
|||
err error
|
||||
)
|
||||
|
||||
n, err = protoutil.BytesMarshal(trustPeerFNum, buf[offset:], x.peer)
|
||||
n, err = protoutil.NestedStructureMarshal(trustPeerFNum, buf[offset:], x.peer)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -42,7 +74,7 @@ func (x *Trust) StableMarshal(buf []byte) ([]byte, error) {
|
|||
}
|
||||
|
||||
func (x *Trust) StableSize() (size int) {
|
||||
size += protoutil.BytesSize(trustPeerFNum, x.peer)
|
||||
size += protoutil.NestedStructureSize(trustPeerFNum, x.peer)
|
||||
size += protoutil.Float64Size(trustValueFNum, x.val)
|
||||
|
||||
return
|
||||
|
@ -52,6 +84,93 @@ func (x *Trust) Unmarshal(data []byte) error {
|
|||
return message.Unmarshal(x, data, new(reputation.Trust))
|
||||
}
|
||||
|
||||
const (
|
||||
_ = iota
|
||||
globalTrustBodyManagerFNum
|
||||
globalTrustBodyValueFNum
|
||||
)
|
||||
|
||||
func (x *GlobalTrustBody) StableMarshal(buf []byte) ([]byte, error) {
|
||||
if x == nil {
|
||||
return []byte{}, nil
|
||||
}
|
||||
|
||||
if buf == nil {
|
||||
buf = make([]byte, x.StableSize())
|
||||
}
|
||||
|
||||
offset, err := protoutil.NestedStructureMarshal(globalTrustBodyManagerFNum, buf, x.manager)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
_, err = protoutil.NestedStructureMarshal(globalTrustBodyValueFNum, buf[offset:], x.trust)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return buf, nil
|
||||
}
|
||||
|
||||
func (x *GlobalTrustBody) StableSize() (size int) {
|
||||
size += protoutil.NestedStructureSize(globalTrustBodyManagerFNum, x.manager)
|
||||
size += protoutil.NestedStructureSize(globalTrustBodyValueFNum, x.trust)
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
func (x *GlobalTrustBody) Unmarshal(data []byte) error {
|
||||
return message.Unmarshal(x, data, new(reputation.GlobalTrust_Body))
|
||||
}
|
||||
|
||||
const (
|
||||
_ = iota
|
||||
globalTrustVersionFNum
|
||||
globalTrustBodyFNum
|
||||
globalTrustSigFNum
|
||||
)
|
||||
|
||||
func (x *GlobalTrust) StableMarshal(buf []byte) ([]byte, error) {
|
||||
if x == nil {
|
||||
return []byte{}, nil
|
||||
}
|
||||
|
||||
if buf == nil {
|
||||
buf = make([]byte, x.StableSize())
|
||||
}
|
||||
|
||||
offset, err := protoutil.NestedStructureMarshal(globalTrustVersionFNum, buf, x.version)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
n, err := protoutil.NestedStructureMarshal(globalTrustBodyFNum, buf[offset:], x.body)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
offset += n
|
||||
|
||||
_, err = protoutil.NestedStructureMarshal(globalTrustSigFNum, buf[offset:], x.sig)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return buf, nil
|
||||
}
|
||||
|
||||
func (x *GlobalTrust) StableSize() (size int) {
|
||||
size += protoutil.NestedStructureSize(globalTrustVersionFNum, x.version)
|
||||
size += protoutil.NestedStructureSize(globalTrustBodyFNum, x.body)
|
||||
size += protoutil.NestedStructureSize(globalTrustSigFNum, x.sig)
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
func (x *GlobalTrust) Unmarshal(data []byte) error {
|
||||
return message.Unmarshal(x, data, new(reputation.GlobalTrust))
|
||||
}
|
||||
|
||||
const (
|
||||
_ = iota
|
||||
sendLocalTrustBodyEpochFNum
|
||||
|
@ -116,3 +235,54 @@ func (x *SendLocalTrustResponseBody) StableSize() int {
|
|||
func (x *SendLocalTrustResponseBody) Unmarshal(data []byte) error {
|
||||
return message.Unmarshal(x, data, new(reputation.SendLocalTrustResponse_Body))
|
||||
}
|
||||
|
||||
const (
|
||||
_ = iota
|
||||
sendInterResBodyIterFNum
|
||||
sendInterResBodyTrustFNum
|
||||
)
|
||||
|
||||
func (x *SendIntermediateResultRequestBody) StableMarshal(buf []byte) ([]byte, error) {
|
||||
if x == nil {
|
||||
return []byte{}, nil
|
||||
}
|
||||
|
||||
if buf == nil {
|
||||
buf = make([]byte, x.StableSize())
|
||||
}
|
||||
|
||||
offset, err := protoutil.UInt32Marshal(sendInterResBodyIterFNum, buf, x.iter)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
_, err = protoutil.NestedStructureMarshal(sendInterResBodyTrustFNum, buf[offset:], x.trust)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return buf, nil
|
||||
}
|
||||
|
||||
func (x *SendIntermediateResultRequestBody) StableSize() (size int) {
|
||||
size += protoutil.UInt32Size(sendInterResBodyIterFNum, x.iter)
|
||||
size += protoutil.NestedStructureSize(sendInterResBodyTrustFNum, x.trust)
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
func (x *SendIntermediateResultRequestBody) Unmarshal(data []byte) error {
|
||||
return message.Unmarshal(x, data, new(reputation.SendIntermediateResultRequest_Body))
|
||||
}
|
||||
|
||||
func (x *SendIntermediateResultResponseBody) StableMarshal(buf []byte) ([]byte, error) {
|
||||
return buf, nil
|
||||
}
|
||||
|
||||
func (x *SendIntermediateResultResponseBody) StableSize() int {
|
||||
return 0
|
||||
}
|
||||
|
||||
func (x *SendIntermediateResultResponseBody) Unmarshal(data []byte) error {
|
||||
return message.Unmarshal(x, data, new(reputation.SendIntermediateResultResponse_Body))
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue