github.com/TrueCloudLab/frostfs-api-go/v2@v2.0.0-20230228134343-196241c4e79a/audit/marshal.go (about) 1 package audit 2 3 import ( 4 audit "github.com/TrueCloudLab/frostfs-api-go/v2/audit/grpc" 5 "github.com/TrueCloudLab/frostfs-api-go/v2/refs" 6 "github.com/TrueCloudLab/frostfs-api-go/v2/rpc/message" 7 "github.com/TrueCloudLab/frostfs-api-go/v2/util/proto" 8 ) 9 10 const ( 11 _ = iota 12 versionFNum 13 auditEpochFNum 14 cidFNum 15 pubKeyFNum 16 completeFNum 17 requestsFNum 18 retriesFNum 19 passSGFNum 20 failSGFNum 21 hitFNum 22 missFNum 23 failFNum 24 passNodesFNum 25 failNodesFNum 26 ) 27 28 // StableMarshal marshals unified DataAuditResult structure into a protobuf 29 // binary format without field order shuffle. 30 func (a *DataAuditResult) StableMarshal(buf []byte) []byte { 31 if a == nil { 32 return []byte{} 33 } 34 35 if buf == nil { 36 buf = make([]byte, a.StableSize()) 37 } 38 39 var offset int 40 41 offset += proto.NestedStructureMarshal(versionFNum, buf[offset:], a.version) 42 offset += proto.Fixed64Marshal(auditEpochFNum, buf[offset:], a.auditEpoch) 43 offset += proto.NestedStructureMarshal(cidFNum, buf[offset:], a.cid) 44 offset += proto.BytesMarshal(pubKeyFNum, buf[offset:], a.pubKey) 45 offset += proto.BoolMarshal(completeFNum, buf[offset:], a.complete) 46 offset += proto.UInt32Marshal(requestsFNum, buf[offset:], a.requests) 47 offset += proto.UInt32Marshal(retriesFNum, buf[offset:], a.retries) 48 offset += refs.ObjectIDNestedListMarshal(passSGFNum, buf[offset:], a.passSG) 49 offset += refs.ObjectIDNestedListMarshal(failSGFNum, buf[offset:], a.failSG) 50 offset += proto.UInt32Marshal(hitFNum, buf[offset:], a.hit) 51 offset += proto.UInt32Marshal(missFNum, buf[offset:], a.miss) 52 offset += proto.UInt32Marshal(failFNum, buf[offset:], a.fail) 53 offset += proto.RepeatedBytesMarshal(passNodesFNum, buf[offset:], a.passNodes) 54 proto.RepeatedBytesMarshal(failNodesFNum, buf[offset:], a.failNodes) 55 56 return buf 57 } 58 59 // StableSize returns byte length of DataAuditResult structure 60 // marshaled by StableMarshal function. 61 func (a *DataAuditResult) StableSize() (size int) { 62 if a == nil { 63 return 0 64 } 65 66 size += proto.NestedStructureSize(versionFNum, a.version) 67 size += proto.Fixed64Size(auditEpochFNum, a.auditEpoch) 68 size += proto.NestedStructureSize(cidFNum, a.cid) 69 size += proto.BytesSize(pubKeyFNum, a.pubKey) 70 size += proto.BoolSize(completeFNum, a.complete) 71 size += proto.UInt32Size(requestsFNum, a.requests) 72 size += proto.UInt32Size(retriesFNum, a.retries) 73 size += refs.ObjectIDNestedListSize(passSGFNum, a.passSG) 74 size += refs.ObjectIDNestedListSize(failSGFNum, a.failSG) 75 size += proto.UInt32Size(hitFNum, a.hit) 76 size += proto.UInt32Size(missFNum, a.miss) 77 size += proto.UInt32Size(failFNum, a.fail) 78 size += proto.RepeatedBytesSize(passNodesFNum, a.passNodes) 79 size += proto.RepeatedBytesSize(failNodesFNum, a.failNodes) 80 81 return size 82 } 83 84 // Unmarshal unmarshals DataAuditResult structure from its protobuf 85 // binary representation. 86 func (a *DataAuditResult) Unmarshal(data []byte) error { 87 return message.Unmarshal(a, data, new(audit.DataAuditResult)) 88 }