github.com/TrueCloudLab/frostfs-api-go/v2@v2.0.0-20230228134343-196241c4e79a/accounting/marshal.go (about) 1 package accounting 2 3 import ( 4 accounting "github.com/TrueCloudLab/frostfs-api-go/v2/accounting/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 decimalValueField = 1 11 decimalPrecisionField = 2 12 13 balanceReqBodyOwnerField = 1 14 15 balanceRespBodyDecimalField = 1 16 ) 17 18 func (d *Decimal) StableMarshal(buf []byte) []byte { 19 if d == nil { 20 return []byte{} 21 } 22 23 if buf == nil { 24 buf = make([]byte, d.StableSize()) 25 } 26 27 var offset int 28 29 offset += protoutil.Int64Marshal(decimalValueField, buf[offset:], d.val) 30 protoutil.UInt32Marshal(decimalPrecisionField, buf[offset:], d.prec) 31 32 return buf 33 } 34 35 func (d *Decimal) StableSize() (size int) { 36 if d == nil { 37 return 0 38 } 39 40 size += protoutil.Int64Size(decimalValueField, d.val) 41 size += protoutil.UInt32Size(decimalPrecisionField, d.prec) 42 43 return size 44 } 45 46 func (d *Decimal) Unmarshal(data []byte) error { 47 return message.Unmarshal(d, data, new(accounting.Decimal)) 48 } 49 50 func (b *BalanceRequestBody) StableMarshal(buf []byte) []byte { 51 if b == nil { 52 return []byte{} 53 } 54 55 if buf == nil { 56 buf = make([]byte, b.StableSize()) 57 } 58 59 protoutil.NestedStructureMarshal(balanceReqBodyOwnerField, buf, b.ownerID) 60 61 return buf 62 } 63 64 func (b *BalanceRequestBody) StableSize() (size int) { 65 if b == nil { 66 return 0 67 } 68 69 size = protoutil.NestedStructureSize(balanceReqBodyOwnerField, b.ownerID) 70 71 return size 72 } 73 74 func (b *BalanceRequestBody) Unmarshal(data []byte) error { 75 return message.Unmarshal(b, data, new(accounting.BalanceRequest_Body)) 76 } 77 78 func (br *BalanceResponseBody) StableMarshal(buf []byte) []byte { 79 if br == nil { 80 return []byte{} 81 } 82 83 if buf == nil { 84 buf = make([]byte, br.StableSize()) 85 } 86 87 protoutil.NestedStructureMarshal(balanceRespBodyDecimalField, buf, br.bal) 88 89 return buf 90 } 91 92 func (br *BalanceResponseBody) StableSize() (size int) { 93 if br == nil { 94 return 0 95 } 96 97 size = protoutil.NestedStructureSize(balanceRespBodyDecimalField, br.bal) 98 99 return size 100 } 101 102 func (br *BalanceResponseBody) Unmarshal(data []byte) error { 103 return message.Unmarshal(br, data, new(accounting.BalanceResponse_Body)) 104 }