2021-10-26 10:31:31 +00:00
|
|
|
package accounting
|
|
|
|
|
2024-10-07 14:20:25 +00:00
|
|
|
import "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/api/accounting"
|
2021-10-26 10:31:31 +00:00
|
|
|
|
|
|
|
// Decimal represents decimal number for accounting operations.
|
|
|
|
//
|
2024-10-07 14:20:25 +00:00
|
|
|
// Decimal is mutually compatible with git.frostfs.info/TrueCloudLab/frostfs-sdk-go/api/accounting.Decimal
|
2022-03-17 13:45:26 +00:00
|
|
|
// message. See ReadFromV2 / WriteToV2 methods.
|
2022-03-12 16:15:26 +00:00
|
|
|
//
|
|
|
|
// Instances can be created using built-in var declaration.
|
|
|
|
//
|
|
|
|
// Note that direct typecast is not safe and may result in loss of compatibility:
|
2022-08-24 14:17:40 +00:00
|
|
|
//
|
|
|
|
// _ = Decimal(accounting.Decimal{}) // not recommended
|
2022-03-12 16:15:26 +00:00
|
|
|
type Decimal accounting.Decimal
|
2021-10-26 10:31:31 +00:00
|
|
|
|
2022-07-07 10:51:05 +00:00
|
|
|
// ReadFromV2 reads Decimal from the accounting.Decimal message. Checks if the
|
2022-12-29 10:46:18 +00:00
|
|
|
// message conforms to FrostFS API V2 protocol.
|
2021-10-26 10:31:31 +00:00
|
|
|
//
|
2022-03-17 13:45:26 +00:00
|
|
|
// See also WriteToV2.
|
2022-07-07 10:51:05 +00:00
|
|
|
func (d *Decimal) ReadFromV2(m accounting.Decimal) error {
|
2022-03-12 16:15:26 +00:00
|
|
|
*d = Decimal(m)
|
2022-07-07 10:51:05 +00:00
|
|
|
return nil
|
2021-10-26 10:31:31 +00:00
|
|
|
}
|
|
|
|
|
2022-03-17 13:45:26 +00:00
|
|
|
// WriteToV2 writes Decimal to the accounting.Decimal message.
|
2022-03-12 16:15:26 +00:00
|
|
|
// The message must not be nil.
|
2021-10-26 10:31:31 +00:00
|
|
|
//
|
2022-03-17 13:45:26 +00:00
|
|
|
// See also ReadFromV2.
|
|
|
|
func (d Decimal) WriteToV2(m *accounting.Decimal) {
|
2022-03-12 16:15:26 +00:00
|
|
|
*m = (accounting.Decimal)(d)
|
2021-10-26 10:31:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Value returns value of the decimal number.
|
2022-03-12 16:15:26 +00:00
|
|
|
//
|
|
|
|
// Zero Decimal has zero value.
|
|
|
|
//
|
|
|
|
// See also SetValue.
|
|
|
|
func (d Decimal) Value() int64 {
|
|
|
|
return (*accounting.Decimal)(&d).GetValue()
|
2021-10-26 10:31:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// SetValue sets value of the decimal number.
|
2022-03-12 16:15:26 +00:00
|
|
|
//
|
|
|
|
// See also Value.
|
2021-10-26 10:31:31 +00:00
|
|
|
func (d *Decimal) SetValue(v int64) {
|
|
|
|
(*accounting.Decimal)(d).SetValue(v)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Precision returns precision of the decimal number.
|
2022-03-12 16:15:26 +00:00
|
|
|
//
|
|
|
|
// Zero Decimal has zero precision.
|
|
|
|
//
|
|
|
|
// See also SetPrecision.
|
|
|
|
func (d Decimal) Precision() uint32 {
|
|
|
|
return (*accounting.Decimal)(&d).GetPrecision()
|
2021-10-26 10:31:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// SetPrecision sets precision of the decimal number.
|
2022-03-12 16:15:26 +00:00
|
|
|
//
|
|
|
|
// See also Precision.
|
2021-10-26 10:31:31 +00:00
|
|
|
func (d *Decimal) SetPrecision(p uint32) {
|
|
|
|
(*accounting.Decimal)(d).SetPrecision(p)
|
|
|
|
}
|