type Quantity … type CanonicalValue … type Format … const DecimalExponent … const BinarySI … const DecimalSI … // MustParse turns the given string into a quantity or panics; for tests // or other cases where you know the string is valid. func MustParse(str string) Quantity { … } const splitREString … var ErrFormatWrong … var ErrNumeric … var ErrSuffix … // parseQuantityString is a fast scanner for quantity values. func parseQuantityString(str string) (positive bool, value, num, denom, suffix string, err error) { … } // ParseQuantity turns str into a Quantity, or returns an error. func ParseQuantity(str string) (Quantity, error) { … } // DeepCopy returns a deep-copy of the Quantity value. Note that the method // receiver is a value, so we can mutate it in-place and return it. func (q Quantity) DeepCopy() Quantity { … } // OpenAPISchemaType is used by the kube-openapi generator when constructing // the OpenAPI spec of this type. // // See: https://github.com/kubernetes/kube-openapi/tree/master/pkg/generators func (_ Quantity) OpenAPISchemaType() []string { … } // OpenAPISchemaFormat is used by the kube-openapi generator when constructing // the OpenAPI spec of this type. func (_ Quantity) OpenAPISchemaFormat() string { … } // OpenAPIV3OneOfTypes is used by the kube-openapi generator when constructing // the OpenAPI v3 spec of this type. func (Quantity) OpenAPIV3OneOfTypes() []string { … } // CanonicalizeBytes returns the canonical form of q and its suffix (see comment on Quantity). // // Note about BinarySI: // - If q.Format is set to BinarySI and q.Amount represents a non-zero value between // -1 and +1, it will be emitted as if q.Format were DecimalSI. // - Otherwise, if q.Format is set to BinarySI, fractional parts of q.Amount will be // rounded up. (1.1i becomes 2i.) func (q *Quantity) CanonicalizeBytes(out []byte) (result, suffix []byte) { … } // AsApproximateFloat64 returns a float64 representation of the quantity which // may lose precision. If precision matter more than performance, see // AsFloat64Slow. If the value of the quantity is outside the range of a // float64 +Inf/-Inf will be returned. func (q *Quantity) AsApproximateFloat64() float64 { … } // AsFloat64Slow returns a float64 representation of the quantity. This is // more precise than AsApproximateFloat64 but significantly slower. If the // value of the quantity is outside the range of a float64 +Inf/-Inf will be // returned. func (q *Quantity) AsFloat64Slow() float64 { … } // AsInt64 returns a representation of the current value as an int64 if a fast conversion // is possible. If false is returned, callers must use the inf.Dec form of this quantity. func (q *Quantity) AsInt64() (int64, bool) { … } // ToDec promotes the quantity in place to use an inf.Dec representation and returns itself. func (q *Quantity) ToDec() *Quantity { … } // AsDec returns the quantity as represented by a scaled inf.Dec. func (q *Quantity) AsDec() *inf.Dec { … } // AsCanonicalBytes returns the canonical byte representation of this quantity as a mantissa // and base 10 exponent. The out byte slice may be passed to the method to avoid an extra // allocation. func (q *Quantity) AsCanonicalBytes(out []byte) (result []byte, exponent int32) { … } // IsZero returns true if the quantity is equal to zero. func (q *Quantity) IsZero() bool { … } // Sign returns 0 if the quantity is zero, -1 if the quantity is less than zero, or 1 if the // quantity is greater than zero. func (q *Quantity) Sign() int { … } // AsScale returns the current value, rounded up to the provided scale, and returns // false if the scale resulted in a loss of precision. func (q *Quantity) AsScale(scale Scale) (CanonicalValue, bool) { … } // RoundUp updates the quantity to the provided scale, ensuring that the value is at // least 1. False is returned if the rounding operation resulted in a loss of precision. // Negative numbers are rounded away from zero (-9 scale 1 rounds to -10). func (q *Quantity) RoundUp(scale Scale) bool { … } // Add adds the provide y quantity to the current value. If the current value is zero, // the format of the quantity will be updated to the format of y. func (q *Quantity) Add(y Quantity) { … } // Sub subtracts the provided quantity from the current value in place. If the current // value is zero, the format of the quantity will be updated to the format of y. func (q *Quantity) Sub(y Quantity) { … } // Mul multiplies the provided y to the current value. // It will return false if the result is inexact. Otherwise, it will return true. func (q *Quantity) Mul(y int64) bool { … } // Cmp returns 0 if the quantity is equal to y, -1 if the quantity is less than y, or 1 if the // quantity is greater than y. func (q *Quantity) Cmp(y Quantity) int { … } // CmpInt64 returns 0 if the quantity is equal to y, -1 if the quantity is less than y, or 1 if the // quantity is greater than y. func (q *Quantity) CmpInt64(y int64) int { … } // Neg sets quantity to be the negative value of itself. func (q *Quantity) Neg() { … } // Equal checks equality of two Quantities. This is useful for testing with // cmp.Equal. func (q Quantity) Equal(v Quantity) bool { … } const int64QuantityExpectedBytes … // String formats the Quantity as a string, caching the result if not calculated. // String is an expensive operation and caching this result significantly reduces the cost of // normal parse / marshal operations on Quantity. func (q *Quantity) String() string { … } // MarshalJSON implements the json.Marshaller interface. func (q Quantity) MarshalJSON() ([]byte, error) { … } func (q Quantity) MarshalCBOR() ([]byte, error) { … } // ToUnstructured implements the value.UnstructuredConverter interface. func (q Quantity) ToUnstructured() interface{ … } // UnmarshalJSON implements the json.Unmarshaller interface. // TODO: Remove support for leading/trailing whitespace func (q *Quantity) UnmarshalJSON(value []byte) error { … } func (q *Quantity) UnmarshalCBOR(value []byte) error { … } // NewDecimalQuantity returns a new Quantity representing the given // value in the given format. func NewDecimalQuantity(b inf.Dec, format Format) *Quantity { … } // NewQuantity returns a new Quantity representing the given // value in the given format. func NewQuantity(value int64, format Format) *Quantity { … } // NewMilliQuantity returns a new Quantity representing the given // value * 1/1000 in the given format. Note that BinarySI formatting // will round fractional values, and will be changed to DecimalSI for // values x where (-1 < x < 1) && (x != 0). func NewMilliQuantity(value int64, format Format) *Quantity { … } // NewScaledQuantity returns a new Quantity representing the given // value * 10^scale in DecimalSI format. func NewScaledQuantity(value int64, scale Scale) *Quantity { … } // Value returns the unscaled value of q rounded up to the nearest integer away from 0. func (q *Quantity) Value() int64 { … } // MilliValue returns the value of ceil(q * 1000); this could overflow an int64; // if that's a concern, call Value() first to verify the number is small enough. func (q *Quantity) MilliValue() int64 { … } // ScaledValue returns the value of ceil(q / 10^scale). // For example, NewQuantity(1, DecimalSI).ScaledValue(Milli) returns 1000. // This could overflow an int64. // To detect overflow, call Value() first and verify the expected magnitude. func (q *Quantity) ScaledValue(scale Scale) int64 { … } // Set sets q's value to be value. func (q *Quantity) Set(value int64) { … } // SetMilli sets q's value to be value * 1/1000. func (q *Quantity) SetMilli(value int64) { … } // SetScaled sets q's value to be value * 10^scale func (q *Quantity) SetScaled(value int64, scale Scale) { … } type QuantityValue … // Set implements pflag.Value.Set and Go flag.Value.Set. func (q *QuantityValue) Set(s string) error { … } // Type implements pflag.Value.Type. func (q QuantityValue) Type() string { … }