2020-08-18 06:49:55 +00:00
|
|
|
package accounting
|
|
|
|
|
|
|
|
import (
|
2022-12-09 11:16:24 +00:00
|
|
|
accounting "github.com/TrueCloudLab/frostfs-api-go/v2/accounting/grpc"
|
|
|
|
"github.com/TrueCloudLab/frostfs-api-go/v2/rpc/message"
|
|
|
|
protoutil "github.com/TrueCloudLab/frostfs-api-go/v2/util/proto"
|
2020-08-18 06:49:55 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
|
|
|
decimalValueField = 1
|
|
|
|
decimalPrecisionField = 2
|
|
|
|
|
|
|
|
balanceReqBodyOwnerField = 1
|
|
|
|
|
|
|
|
balanceRespBodyDecimalField = 1
|
|
|
|
)
|
|
|
|
|
2022-04-05 08:24:34 +00:00
|
|
|
func (d *Decimal) StableMarshal(buf []byte) []byte {
|
2020-08-18 06:49:55 +00:00
|
|
|
if d == nil {
|
2022-04-05 08:24:34 +00:00
|
|
|
return []byte{}
|
2020-08-18 06:49:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if buf == nil {
|
|
|
|
buf = make([]byte, d.StableSize())
|
|
|
|
}
|
|
|
|
|
2022-03-12 12:20:19 +00:00
|
|
|
var offset int
|
2020-08-18 06:49:55 +00:00
|
|
|
|
2022-03-12 12:20:19 +00:00
|
|
|
offset += protoutil.Int64Marshal(decimalValueField, buf[offset:], d.val)
|
|
|
|
protoutil.UInt32Marshal(decimalPrecisionField, buf[offset:], d.prec)
|
2020-08-18 06:49:55 +00:00
|
|
|
|
2022-04-05 08:24:34 +00:00
|
|
|
return buf
|
2020-08-18 06:49:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (d *Decimal) StableSize() (size int) {
|
|
|
|
if d == nil {
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
2020-11-13 10:38:49 +00:00
|
|
|
size += protoutil.Int64Size(decimalValueField, d.val)
|
|
|
|
size += protoutil.UInt32Size(decimalPrecisionField, d.prec)
|
2020-08-18 06:49:55 +00:00
|
|
|
|
|
|
|
return size
|
|
|
|
}
|
|
|
|
|
2020-11-13 10:38:49 +00:00
|
|
|
func (d *Decimal) Unmarshal(data []byte) error {
|
2021-03-12 12:57:23 +00:00
|
|
|
return message.Unmarshal(d, data, new(accounting.Decimal))
|
2020-11-13 10:38:49 +00:00
|
|
|
}
|
|
|
|
|
2022-04-05 08:24:34 +00:00
|
|
|
func (b *BalanceRequestBody) StableMarshal(buf []byte) []byte {
|
2020-08-18 06:49:55 +00:00
|
|
|
if b == nil {
|
2022-04-05 08:24:34 +00:00
|
|
|
return []byte{}
|
2020-08-18 06:49:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if buf == nil {
|
|
|
|
buf = make([]byte, b.StableSize())
|
|
|
|
}
|
|
|
|
|
2022-04-05 08:24:34 +00:00
|
|
|
protoutil.NestedStructureMarshal(balanceReqBodyOwnerField, buf, b.ownerID)
|
2020-08-18 06:49:55 +00:00
|
|
|
|
2022-04-05 08:24:34 +00:00
|
|
|
return buf
|
2020-08-18 06:49:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (b *BalanceRequestBody) StableSize() (size int) {
|
|
|
|
if b == nil {
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
2020-11-13 10:38:49 +00:00
|
|
|
size = protoutil.NestedStructureSize(balanceReqBodyOwnerField, b.ownerID)
|
2020-08-18 06:49:55 +00:00
|
|
|
|
|
|
|
return size
|
|
|
|
}
|
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
func (b *BalanceRequestBody) Unmarshal(data []byte) error {
|
|
|
|
return message.Unmarshal(b, data, new(accounting.BalanceRequest_Body))
|
|
|
|
}
|
|
|
|
|
2022-04-05 08:24:34 +00:00
|
|
|
func (br *BalanceResponseBody) StableMarshal(buf []byte) []byte {
|
2020-08-18 06:49:55 +00:00
|
|
|
if br == nil {
|
2022-04-05 08:24:34 +00:00
|
|
|
return []byte{}
|
2020-08-18 06:49:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if buf == nil {
|
|
|
|
buf = make([]byte, br.StableSize())
|
|
|
|
}
|
|
|
|
|
2022-04-05 08:24:34 +00:00
|
|
|
protoutil.NestedStructureMarshal(balanceRespBodyDecimalField, buf, br.bal)
|
2020-08-18 06:49:55 +00:00
|
|
|
|
2022-04-05 08:24:34 +00:00
|
|
|
return buf
|
2020-08-18 06:49:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (br *BalanceResponseBody) StableSize() (size int) {
|
|
|
|
if br == nil {
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
2020-11-13 10:38:49 +00:00
|
|
|
size = protoutil.NestedStructureSize(balanceRespBodyDecimalField, br.bal)
|
2020-08-18 06:49:55 +00:00
|
|
|
|
|
|
|
return size
|
|
|
|
}
|
2021-03-12 12:57:23 +00:00
|
|
|
|
|
|
|
func (br *BalanceResponseBody) Unmarshal(data []byte) error {
|
|
|
|
return message.Unmarshal(br, data, new(accounting.BalanceResponse_Body))
|
|
|
|
}
|