github.com/TrueCloudLab/frostfs-api-go/v2@v2.0.0-20230228134343-196241c4e79a/reputation/marshal.go (about) 1 package reputation 2 3 import ( 4 reputation "github.com/TrueCloudLab/frostfs-api-go/v2/reputation/grpc" 5 "github.com/TrueCloudLab/frostfs-api-go/v2/rpc/message" 6 protoutil "github.com/TrueCloudLab/frostfs-api-go/v2/util/proto" 7 ) 8 9 const ( 10 _ = iota 11 peerIDPubKeyFNum 12 ) 13 14 func (x *PeerID) StableMarshal(buf []byte) []byte { 15 if x == nil { 16 return []byte{} 17 } 18 19 if buf == nil { 20 buf = make([]byte, x.StableSize()) 21 } 22 23 protoutil.BytesMarshal(peerIDPubKeyFNum, buf, x.publicKey) 24 25 return buf 26 } 27 28 func (x *PeerID) StableSize() (size int) { 29 size += protoutil.BytesSize(peerIDPubKeyFNum, x.publicKey) 30 31 return 32 } 33 34 func (x *PeerID) Unmarshal(data []byte) error { 35 return message.Unmarshal(x, data, new(reputation.PeerID)) 36 } 37 38 const ( 39 _ = iota 40 trustPeerFNum 41 trustValueFNum 42 ) 43 44 func (x *Trust) StableMarshal(buf []byte) []byte { 45 if x == nil { 46 return []byte{} 47 } 48 49 if buf == nil { 50 buf = make([]byte, x.StableSize()) 51 } 52 53 var offset int 54 55 offset += protoutil.NestedStructureMarshal(trustPeerFNum, buf[offset:], x.peer) 56 protoutil.Float64Marshal(trustValueFNum, buf[offset:], x.val) 57 58 return buf 59 } 60 61 func (x *Trust) StableSize() (size int) { 62 size += protoutil.NestedStructureSize(trustPeerFNum, x.peer) 63 size += protoutil.Float64Size(trustValueFNum, x.val) 64 65 return 66 } 67 68 func (x *Trust) Unmarshal(data []byte) error { 69 return message.Unmarshal(x, data, new(reputation.Trust)) 70 } 71 72 const ( 73 _ = iota 74 p2pTrustTrustingFNum 75 p2pTrustValueFNum 76 ) 77 78 func (x *PeerToPeerTrust) StableMarshal(buf []byte) []byte { 79 if x == nil { 80 return []byte{} 81 } 82 83 if buf == nil { 84 buf = make([]byte, x.StableSize()) 85 } 86 87 var offset int 88 89 offset += protoutil.NestedStructureMarshal(p2pTrustTrustingFNum, buf, x.trusting) 90 protoutil.NestedStructureMarshal(p2pTrustValueFNum, buf[offset:], x.trust) 91 92 return buf 93 } 94 95 func (x *PeerToPeerTrust) StableSize() (size int) { 96 size += protoutil.NestedStructureSize(p2pTrustTrustingFNum, x.trusting) 97 size += protoutil.NestedStructureSize(p2pTrustValueFNum, x.trust) 98 99 return 100 } 101 102 func (x *PeerToPeerTrust) Unmarshal(data []byte) error { 103 return message.Unmarshal(x, data, new(reputation.PeerToPeerTrust)) 104 } 105 106 const ( 107 _ = iota 108 globalTrustBodyManagerFNum 109 globalTrustBodyValueFNum 110 ) 111 112 func (x *GlobalTrustBody) StableMarshal(buf []byte) []byte { 113 if x == nil { 114 return []byte{} 115 } 116 117 if buf == nil { 118 buf = make([]byte, x.StableSize()) 119 } 120 121 var offset int 122 123 offset += protoutil.NestedStructureMarshal(globalTrustBodyManagerFNum, buf, x.manager) 124 protoutil.NestedStructureMarshal(globalTrustBodyValueFNum, buf[offset:], x.trust) 125 126 return buf 127 } 128 129 func (x *GlobalTrustBody) StableSize() (size int) { 130 size += protoutil.NestedStructureSize(globalTrustBodyManagerFNum, x.manager) 131 size += protoutil.NestedStructureSize(globalTrustBodyValueFNum, x.trust) 132 133 return 134 } 135 136 func (x *GlobalTrustBody) Unmarshal(data []byte) error { 137 return message.Unmarshal(x, data, new(reputation.GlobalTrust_Body)) 138 } 139 140 const ( 141 _ = iota 142 globalTrustVersionFNum 143 globalTrustBodyFNum 144 globalTrustSigFNum 145 ) 146 147 func (x *GlobalTrust) StableMarshal(buf []byte) []byte { 148 if x == nil { 149 return []byte{} 150 } 151 152 if buf == nil { 153 buf = make([]byte, x.StableSize()) 154 } 155 156 var offset int 157 158 offset += protoutil.NestedStructureMarshal(globalTrustVersionFNum, buf, x.version) 159 offset += protoutil.NestedStructureMarshal(globalTrustBodyFNum, buf[offset:], x.body) 160 protoutil.NestedStructureMarshal(globalTrustSigFNum, buf[offset:], x.sig) 161 162 return buf 163 } 164 165 func (x *GlobalTrust) StableSize() (size int) { 166 size += protoutil.NestedStructureSize(globalTrustVersionFNum, x.version) 167 size += protoutil.NestedStructureSize(globalTrustBodyFNum, x.body) 168 size += protoutil.NestedStructureSize(globalTrustSigFNum, x.sig) 169 170 return 171 } 172 173 func (x *GlobalTrust) Unmarshal(data []byte) error { 174 return message.Unmarshal(x, data, new(reputation.GlobalTrust)) 175 } 176 177 const ( 178 _ = iota 179 announceLocalTrustBodyEpochFNum 180 announceLocalTrustBodyTrustsFNum 181 ) 182 183 func (x *AnnounceLocalTrustRequestBody) StableMarshal(buf []byte) []byte { 184 if x == nil { 185 return []byte{} 186 } 187 188 if buf == nil { 189 buf = make([]byte, x.StableSize()) 190 } 191 192 var offset int 193 194 offset += protoutil.UInt64Marshal(announceLocalTrustBodyEpochFNum, buf[offset:], x.epoch) 195 196 for i := range x.trusts { 197 offset += protoutil.NestedStructureMarshal(announceLocalTrustBodyTrustsFNum, buf[offset:], &x.trusts[i]) 198 } 199 200 return buf 201 } 202 203 func (x *AnnounceLocalTrustRequestBody) StableSize() (size int) { 204 size += protoutil.UInt64Size(announceLocalTrustBodyEpochFNum, x.epoch) 205 206 for i := range x.trusts { 207 size += protoutil.NestedStructureSize(announceLocalTrustBodyTrustsFNum, &x.trusts[i]) 208 } 209 210 return 211 } 212 213 func (x *AnnounceLocalTrustRequestBody) Unmarshal(data []byte) error { 214 return message.Unmarshal(x, data, new(reputation.AnnounceLocalTrustRequest_Body)) 215 } 216 217 func (x *AnnounceLocalTrustResponseBody) StableMarshal(buf []byte) []byte { 218 return buf 219 } 220 221 func (x *AnnounceLocalTrustResponseBody) StableSize() int { 222 return 0 223 } 224 225 func (x *AnnounceLocalTrustResponseBody) Unmarshal(data []byte) error { 226 return message.Unmarshal(x, data, new(reputation.AnnounceLocalTrustResponse_Body)) 227 } 228 229 const ( 230 _ = iota 231 announceInterResBodyEpochFNum 232 announceInterResBodyIterFNum 233 announceInterResBodyTrustFNum 234 ) 235 236 func (x *AnnounceIntermediateResultRequestBody) StableMarshal(buf []byte) []byte { 237 if x == nil { 238 return []byte{} 239 } 240 241 if buf == nil { 242 buf = make([]byte, x.StableSize()) 243 } 244 245 var offset int 246 247 offset += protoutil.UInt64Marshal(announceInterResBodyEpochFNum, buf, x.epoch) 248 offset += protoutil.UInt32Marshal(announceInterResBodyIterFNum, buf[offset:], x.iter) 249 protoutil.NestedStructureMarshal(announceInterResBodyTrustFNum, buf[offset:], x.trust) 250 251 return buf 252 } 253 254 func (x *AnnounceIntermediateResultRequestBody) StableSize() (size int) { 255 size += protoutil.UInt64Size(announceInterResBodyEpochFNum, x.epoch) 256 size += protoutil.UInt32Size(announceInterResBodyIterFNum, x.iter) 257 size += protoutil.NestedStructureSize(announceInterResBodyTrustFNum, x.trust) 258 259 return 260 } 261 262 func (x *AnnounceIntermediateResultRequestBody) Unmarshal(data []byte) error { 263 return message.Unmarshal(x, data, new(reputation.AnnounceIntermediateResultRequest_Body)) 264 } 265 266 func (x *AnnounceIntermediateResultResponseBody) StableMarshal(buf []byte) []byte { 267 return buf 268 } 269 270 func (x *AnnounceIntermediateResultResponseBody) StableSize() int { 271 return 0 272 } 273 274 func (x *AnnounceIntermediateResultResponseBody) Unmarshal(data []byte) error { 275 return message.Unmarshal(x, data, new(reputation.AnnounceIntermediateResultResponse_Body)) 276 }