github.com/TrueCloudLab/frostfs-api-go/v2@v2.0.0-20230228134343-196241c4e79a/netmap/marshal.go (about) 1 package netmap 2 3 import ( 4 netmap "github.com/TrueCloudLab/frostfs-api-go/v2/netmap/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 nameFilterField = 1 11 keyFilterField = 2 12 opFilterField = 3 13 valueFilterField = 4 14 filtersFilterField = 5 15 16 nameSelectorField = 1 17 countSelectorField = 2 18 clauseSelectorField = 3 19 attributeSelectorField = 4 20 filterSelectorField = 5 21 22 countReplicaField = 1 23 selectorReplicaField = 2 24 25 replicasPolicyField = 1 26 backupPolicyField = 2 27 selectorsPolicyField = 3 28 filtersPolicyField = 4 29 subnetIDPolicyField = 5 30 31 keyAttributeField = 1 32 valueAttributeField = 2 33 parentsAttributeField = 3 34 35 keyNodeInfoField = 1 36 addressNodeInfoField = 2 37 attributesNodeInfoField = 3 38 stateNodeInfoField = 4 39 40 versionInfoResponseBodyField = 1 41 nodeInfoResponseBodyField = 2 42 ) 43 44 func (f *Filter) StableMarshal(buf []byte) []byte { 45 if f == nil { 46 return []byte{} 47 } 48 49 if buf == nil { 50 buf = make([]byte, f.StableSize()) 51 } 52 53 var offset int 54 55 offset += protoutil.StringMarshal(nameFilterField, buf[offset:], f.name) 56 offset += protoutil.StringMarshal(keyFilterField, buf[offset:], f.key) 57 offset += protoutil.EnumMarshal(opFilterField, buf[offset:], int32(f.op)) 58 offset += protoutil.StringMarshal(valueFilterField, buf[offset:], f.value) 59 60 for i := range f.filters { 61 offset += protoutil.NestedStructureMarshal(filtersFilterField, buf[offset:], &f.filters[i]) 62 } 63 64 return buf 65 } 66 67 func (f *Filter) StableSize() (size int) { 68 size += protoutil.StringSize(nameFilterField, f.name) 69 size += protoutil.StringSize(keyFilterField, f.key) 70 size += protoutil.EnumSize(opFilterField, int32(f.op)) 71 size += protoutil.StringSize(valueFilterField, f.value) 72 for i := range f.filters { 73 size += protoutil.NestedStructureSize(filtersFilterField, &f.filters[i]) 74 } 75 76 return size 77 } 78 79 func (f *Filter) Unmarshal(data []byte) error { 80 return message.Unmarshal(f, data, new(netmap.Filter)) 81 } 82 83 func (s *Selector) StableMarshal(buf []byte) []byte { 84 if s == nil { 85 return []byte{} 86 } 87 88 if buf == nil { 89 buf = make([]byte, s.StableSize()) 90 } 91 92 var offset int 93 94 offset += protoutil.StringMarshal(nameSelectorField, buf[offset:], s.name) 95 offset += protoutil.UInt32Marshal(countSelectorField, buf[offset:], s.count) 96 offset += protoutil.EnumMarshal(clauseSelectorField, buf[offset:], int32(s.clause)) 97 offset += protoutil.StringMarshal(attributeSelectorField, buf[offset:], s.attribute) 98 protoutil.StringMarshal(filterSelectorField, buf[offset:], s.filter) 99 100 return buf 101 } 102 103 func (s *Selector) StableSize() (size int) { 104 size += protoutil.StringSize(nameSelectorField, s.name) 105 size += protoutil.UInt32Size(countSelectorField, s.count) 106 size += protoutil.EnumSize(countSelectorField, int32(s.clause)) 107 size += protoutil.StringSize(attributeSelectorField, s.attribute) 108 size += protoutil.StringSize(filterSelectorField, s.filter) 109 110 return size 111 } 112 113 func (s *Selector) Unmarshal(data []byte) error { 114 return message.Unmarshal(s, data, new(netmap.Selector)) 115 } 116 117 func (r *Replica) StableMarshal(buf []byte) []byte { 118 if r == nil { 119 return []byte{} 120 } 121 122 if buf == nil { 123 buf = make([]byte, r.StableSize()) 124 } 125 126 var offset int 127 128 offset += protoutil.UInt32Marshal(countReplicaField, buf[offset:], r.count) 129 protoutil.StringMarshal(selectorReplicaField, buf[offset:], r.selector) 130 131 return buf 132 } 133 134 func (r *Replica) StableSize() (size int) { 135 size += protoutil.UInt32Size(countReplicaField, r.count) 136 size += protoutil.StringSize(selectorReplicaField, r.selector) 137 138 return size 139 } 140 141 func (r *Replica) Unmarshal(data []byte) error { 142 return message.Unmarshal(r, data, new(netmap.Replica)) 143 } 144 145 func (p *PlacementPolicy) StableMarshal(buf []byte) []byte { 146 if p == nil { 147 return []byte{} 148 } 149 150 if buf == nil { 151 buf = make([]byte, p.StableSize()) 152 } 153 154 var offset int 155 156 for i := range p.replicas { 157 offset += protoutil.NestedStructureMarshal(replicasPolicyField, buf[offset:], &p.replicas[i]) 158 } 159 160 offset += protoutil.UInt32Marshal(backupPolicyField, buf[offset:], p.backupFactor) 161 162 for i := range p.selectors { 163 offset += protoutil.NestedStructureMarshal(selectorsPolicyField, buf[offset:], &p.selectors[i]) 164 } 165 166 for i := range p.filters { 167 offset += protoutil.NestedStructureMarshal(filtersPolicyField, buf[offset:], &p.filters[i]) 168 } 169 170 protoutil.NestedStructureMarshal(subnetIDPolicyField, buf[offset:], p.subnetID) 171 172 return buf 173 } 174 175 func (p *PlacementPolicy) StableSize() (size int) { 176 for i := range p.replicas { 177 size += protoutil.NestedStructureSize(replicasPolicyField, &p.replicas[i]) 178 } 179 180 size += protoutil.UInt32Size(backupPolicyField, p.backupFactor) 181 182 for i := range p.selectors { 183 size += protoutil.NestedStructureSize(selectorsPolicyField, &p.selectors[i]) 184 } 185 186 for i := range p.filters { 187 size += protoutil.NestedStructureSize(filtersPolicyField, &p.filters[i]) 188 } 189 190 size += protoutil.NestedStructureSize(subnetIDPolicyField, p.subnetID) 191 192 return size 193 } 194 195 func (p *PlacementPolicy) Unmarshal(data []byte) error { 196 return message.Unmarshal(p, data, new(netmap.PlacementPolicy)) 197 } 198 199 func (a *Attribute) StableMarshal(buf []byte) []byte { 200 if a == nil { 201 return []byte{} 202 } 203 204 if buf == nil { 205 buf = make([]byte, a.StableSize()) 206 } 207 208 var offset int 209 210 offset += protoutil.StringMarshal(keyAttributeField, buf[offset:], a.key) 211 offset += protoutil.StringMarshal(valueAttributeField, buf[offset:], a.value) 212 213 for i := range a.parents { 214 offset += protoutil.StringMarshal(parentsAttributeField, buf[offset:], a.parents[i]) 215 } 216 217 return buf 218 } 219 220 func (a *Attribute) StableSize() (size int) { 221 if a == nil { 222 return 0 223 } 224 225 size += protoutil.StringSize(keyAttributeField, a.key) 226 size += protoutil.StringSize(valueAttributeField, a.value) 227 228 for i := range a.parents { 229 size += protoutil.StringSize(parentsAttributeField, a.parents[i]) 230 } 231 232 return size 233 } 234 235 func (a *Attribute) Unmarshal(data []byte) error { 236 return message.Unmarshal(a, data, new(netmap.NodeInfo_Attribute)) 237 } 238 239 func (ni *NodeInfo) StableMarshal(buf []byte) []byte { 240 if ni == nil { 241 return []byte{} 242 } 243 244 if buf == nil { 245 buf = make([]byte, ni.StableSize()) 246 } 247 248 var offset int 249 250 offset += protoutil.BytesMarshal(keyNodeInfoField, buf[offset:], ni.publicKey) 251 offset += protoutil.RepeatedStringMarshal(addressNodeInfoField, buf[offset:], ni.addresses) 252 253 for i := range ni.attributes { 254 offset += protoutil.NestedStructureMarshal(attributesNodeInfoField, buf[offset:], &ni.attributes[i]) 255 } 256 257 protoutil.EnumMarshal(stateNodeInfoField, buf[offset:], int32(ni.state)) 258 259 return buf 260 } 261 262 func (ni *NodeInfo) StableSize() (size int) { 263 if ni == nil { 264 return 0 265 } 266 267 size += protoutil.BytesSize(keyNodeInfoField, ni.publicKey) 268 size += protoutil.RepeatedStringSize(addressNodeInfoField, ni.addresses) 269 270 for i := range ni.attributes { 271 size += protoutil.NestedStructureSize(attributesNodeInfoField, &ni.attributes[i]) 272 } 273 274 size += protoutil.EnumSize(stateNodeInfoField, int32(ni.state)) 275 276 return size 277 } 278 279 func (ni *NodeInfo) Unmarshal(data []byte) error { 280 return message.Unmarshal(ni, data, new(netmap.NodeInfo)) 281 } 282 283 func (l *LocalNodeInfoRequestBody) StableMarshal(buf []byte) []byte { 284 return nil 285 } 286 287 func (l *LocalNodeInfoRequestBody) StableSize() (size int) { 288 return 0 289 } 290 291 func (l *LocalNodeInfoRequestBody) Unmarshal([]byte) error { 292 return nil 293 } 294 295 func (l *LocalNodeInfoResponseBody) StableMarshal(buf []byte) []byte { 296 if l == nil { 297 return []byte{} 298 } 299 300 if buf == nil { 301 buf = make([]byte, l.StableSize()) 302 } 303 304 var offset int 305 306 offset += protoutil.NestedStructureMarshal(versionInfoResponseBodyField, buf[offset:], l.version) 307 protoutil.NestedStructureMarshal(nodeInfoResponseBodyField, buf[offset:], l.nodeInfo) 308 309 return buf 310 } 311 312 func (l *LocalNodeInfoResponseBody) StableSize() (size int) { 313 if l == nil { 314 return 0 315 } 316 317 size += protoutil.NestedStructureSize(versionInfoResponseBodyField, l.version) 318 size += protoutil.NestedStructureSize(nodeInfoResponseBodyField, l.nodeInfo) 319 320 return size 321 } 322 323 func (l *LocalNodeInfoResponseBody) Unmarshal(data []byte) error { 324 return message.Unmarshal(l, data, new(netmap.LocalNodeInfoResponse_Body)) 325 } 326 327 const ( 328 _ = iota 329 netPrmKeyFNum 330 netPrmValFNum 331 ) 332 333 func (x *NetworkParameter) StableMarshal(buf []byte) []byte { 334 if x == nil { 335 return []byte{} 336 } 337 338 if buf == nil { 339 buf = make([]byte, x.StableSize()) 340 } 341 342 var offset int 343 344 offset += protoutil.BytesMarshal(netPrmKeyFNum, buf[offset:], x.k) 345 protoutil.BytesMarshal(netPrmValFNum, buf[offset:], x.v) 346 347 return buf 348 } 349 350 func (x *NetworkParameter) StableSize() (size int) { 351 if x == nil { 352 return 0 353 } 354 355 size += protoutil.BytesSize(netPrmKeyFNum, x.k) 356 size += protoutil.BytesSize(netPrmValFNum, x.v) 357 358 return size 359 } 360 361 const ( 362 _ = iota 363 netCfgPrmsFNum 364 ) 365 366 func (x *NetworkConfig) StableMarshal(buf []byte) []byte { 367 if x == nil { 368 return []byte{} 369 } 370 371 if buf == nil { 372 buf = make([]byte, x.StableSize()) 373 } 374 375 var offset int 376 377 for i := range x.ps { 378 offset += protoutil.NestedStructureMarshal(netCfgPrmsFNum, buf[offset:], &x.ps[i]) 379 } 380 381 return buf 382 } 383 384 func (x *NetworkConfig) StableSize() (size int) { 385 if x == nil { 386 return 0 387 } 388 389 for i := range x.ps { 390 size += protoutil.NestedStructureSize(netCfgPrmsFNum, &x.ps[i]) 391 } 392 393 return size 394 } 395 396 const ( 397 _ = iota 398 netInfoCurEpochFNum 399 netInfoMagicNumFNum 400 netInfoMSPerBlockFNum 401 netInfoCfgFNum 402 ) 403 404 func (i *NetworkInfo) StableMarshal(buf []byte) []byte { 405 if i == nil { 406 return []byte{} 407 } 408 409 if buf == nil { 410 buf = make([]byte, i.StableSize()) 411 } 412 413 var offset int 414 415 offset += protoutil.UInt64Marshal(netInfoCurEpochFNum, buf[offset:], i.curEpoch) 416 offset += protoutil.UInt64Marshal(netInfoMagicNumFNum, buf[offset:], i.magicNum) 417 offset += protoutil.Int64Marshal(netInfoMSPerBlockFNum, buf[offset:], i.msPerBlock) 418 protoutil.NestedStructureMarshal(netInfoCfgFNum, buf[offset:], i.netCfg) 419 420 return buf 421 } 422 423 func (i *NetworkInfo) StableSize() (size int) { 424 if i == nil { 425 return 0 426 } 427 428 size += protoutil.UInt64Size(netInfoCurEpochFNum, i.curEpoch) 429 size += protoutil.UInt64Size(netInfoMagicNumFNum, i.magicNum) 430 size += protoutil.Int64Size(netInfoMSPerBlockFNum, i.msPerBlock) 431 size += protoutil.NestedStructureSize(netInfoCfgFNum, i.netCfg) 432 433 return size 434 } 435 436 func (i *NetworkInfo) Unmarshal(data []byte) error { 437 return message.Unmarshal(i, data, new(netmap.NetworkInfo)) 438 } 439 440 func (l *NetworkInfoRequestBody) StableMarshal(buf []byte) []byte { 441 return nil 442 } 443 444 func (l *NetworkInfoRequestBody) StableSize() (size int) { 445 return 0 446 } 447 448 func (l *NetworkInfoRequestBody) Unmarshal(data []byte) error { 449 return message.Unmarshal(l, data, new(netmap.NetworkInfoRequest_Body)) 450 } 451 452 const ( 453 _ = iota 454 netInfoRespBodyNetInfoFNum 455 ) 456 457 func (i *NetworkInfoResponseBody) StableMarshal(buf []byte) []byte { 458 if i == nil { 459 return []byte{} 460 } 461 462 if buf == nil { 463 buf = make([]byte, i.StableSize()) 464 } 465 466 protoutil.NestedStructureMarshal(netInfoRespBodyNetInfoFNum, buf, i.netInfo) 467 468 return buf 469 } 470 471 func (i *NetworkInfoResponseBody) StableSize() (size int) { 472 if i == nil { 473 return 0 474 } 475 476 size += protoutil.NestedStructureSize(netInfoRespBodyNetInfoFNum, i.netInfo) 477 478 return size 479 } 480 481 func (i *NetworkInfoResponseBody) Unmarshal(data []byte) error { 482 return message.Unmarshal(i, data, new(netmap.NetworkInfoResponse_Body)) 483 } 484 485 const ( 486 _ = iota 487 fNumNetMapEpoch 488 fNumNetMapNodes 489 ) 490 491 func (x *NetMap) StableMarshal(buf []byte) []byte { 492 if x == nil { 493 return []byte{} 494 } 495 496 if buf == nil { 497 buf = make([]byte, x.StableSize()) 498 } 499 500 offset := protoutil.UInt64Marshal(fNumNetMapEpoch, buf, x.epoch) 501 502 for i := range x.nodes { 503 offset += protoutil.NestedStructureMarshal(fNumNetMapNodes, buf[offset:], &x.nodes[i]) 504 } 505 506 return buf 507 } 508 509 func (x *NetMap) StableSize() (size int) { 510 if x != nil { 511 size = protoutil.UInt64Size(fNumNetMapEpoch, x.epoch) 512 513 for i := range x.nodes { 514 size += protoutil.NestedStructureSize(fNumNetMapNodes, &x.nodes[i]) 515 } 516 } 517 518 return 519 } 520 521 func (x *SnapshotRequestBody) StableMarshal([]byte) []byte { 522 return nil 523 } 524 525 func (x *SnapshotRequestBody) StableSize() int { 526 return 0 527 } 528 529 const ( 530 _ = iota 531 fNumSnapshotResponseBodyNetMap 532 ) 533 534 func (x *SnapshotResponseBody) StableMarshal(buf []byte) []byte { 535 if x == nil { 536 return []byte{} 537 } 538 539 if buf == nil { 540 buf = make([]byte, x.StableSize()) 541 } 542 543 protoutil.NestedStructureMarshal(fNumSnapshotResponseBodyNetMap, buf, x.netMap) 544 545 return buf 546 } 547 548 func (x *SnapshotResponseBody) StableSize() (size int) { 549 if x != nil { 550 size = protoutil.NestedStructureSize(fNumSnapshotResponseBodyNetMap, x.netMap) 551 } 552 553 return 554 }