Zack Williams | e940c7a | 2019-08-21 14:25:39 -0700 | [diff] [blame] | 1 | /* |
| 2 | Copyright The Kubernetes Authors. |
| 3 | |
| 4 | Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | you may not use this file except in compliance with the License. |
| 6 | You may obtain a copy of the License at |
| 7 | |
| 8 | http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | |
| 10 | Unless required by applicable law or agreed to in writing, software |
| 11 | distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | See the License for the specific language governing permissions and |
| 14 | limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | |
| 18 | // This file was autogenerated by go-to-protobuf. Do not edit it manually! |
| 19 | |
| 20 | syntax = 'proto2'; |
| 21 | |
| 22 | package k8s.io.apimachinery.pkg.api.resource; |
| 23 | |
| 24 | // Package-wide variables from generator "generated". |
| 25 | option go_package = "resource"; |
| 26 | |
| 27 | // Quantity is a fixed-point representation of a number. |
| 28 | // It provides convenient marshaling/unmarshaling in JSON and YAML, |
| 29 | // in addition to String() and Int64() accessors. |
David Bainbridge | 8697152 | 2019-09-26 22:09:39 +0000 | [diff] [blame] | 30 | // |
Zack Williams | e940c7a | 2019-08-21 14:25:39 -0700 | [diff] [blame] | 31 | // The serialization format is: |
David Bainbridge | 8697152 | 2019-09-26 22:09:39 +0000 | [diff] [blame] | 32 | // |
Zack Williams | e940c7a | 2019-08-21 14:25:39 -0700 | [diff] [blame] | 33 | // <quantity> ::= <signedNumber><suffix> |
| 34 | // (Note that <suffix> may be empty, from the "" case in <decimalSI>.) |
| 35 | // <digit> ::= 0 | 1 | ... | 9 |
| 36 | // <digits> ::= <digit> | <digit><digits> |
| 37 | // <number> ::= <digits> | <digits>.<digits> | <digits>. | .<digits> |
| 38 | // <sign> ::= "+" | "-" |
| 39 | // <signedNumber> ::= <number> | <sign><number> |
| 40 | // <suffix> ::= <binarySI> | <decimalExponent> | <decimalSI> |
| 41 | // <binarySI> ::= Ki | Mi | Gi | Ti | Pi | Ei |
| 42 | // (International System of units; See: http://physics.nist.gov/cuu/Units/binary.html) |
| 43 | // <decimalSI> ::= m | "" | k | M | G | T | P | E |
| 44 | // (Note that 1024 = 1Ki but 1000 = 1k; I didn't choose the capitalization.) |
| 45 | // <decimalExponent> ::= "e" <signedNumber> | "E" <signedNumber> |
David Bainbridge | 8697152 | 2019-09-26 22:09:39 +0000 | [diff] [blame] | 46 | // |
Zack Williams | e940c7a | 2019-08-21 14:25:39 -0700 | [diff] [blame] | 47 | // No matter which of the three exponent forms is used, no quantity may represent |
| 48 | // a number greater than 2^63-1 in magnitude, nor may it have more than 3 decimal |
| 49 | // places. Numbers larger or more precise will be capped or rounded up. |
| 50 | // (E.g.: 0.1m will rounded up to 1m.) |
| 51 | // This may be extended in the future if we require larger or smaller quantities. |
David Bainbridge | 8697152 | 2019-09-26 22:09:39 +0000 | [diff] [blame] | 52 | // |
Zack Williams | e940c7a | 2019-08-21 14:25:39 -0700 | [diff] [blame] | 53 | // When a Quantity is parsed from a string, it will remember the type of suffix |
| 54 | // it had, and will use the same type again when it is serialized. |
David Bainbridge | 8697152 | 2019-09-26 22:09:39 +0000 | [diff] [blame] | 55 | // |
Zack Williams | e940c7a | 2019-08-21 14:25:39 -0700 | [diff] [blame] | 56 | // Before serializing, Quantity will be put in "canonical form". |
| 57 | // This means that Exponent/suffix will be adjusted up or down (with a |
| 58 | // corresponding increase or decrease in Mantissa) such that: |
| 59 | // a. No precision is lost |
| 60 | // b. No fractional digits will be emitted |
| 61 | // c. The exponent (or suffix) is as large as possible. |
| 62 | // The sign will be omitted unless the number is negative. |
David Bainbridge | 8697152 | 2019-09-26 22:09:39 +0000 | [diff] [blame] | 63 | // |
Zack Williams | e940c7a | 2019-08-21 14:25:39 -0700 | [diff] [blame] | 64 | // Examples: |
| 65 | // 1.5 will be serialized as "1500m" |
| 66 | // 1.5Gi will be serialized as "1536Mi" |
David Bainbridge | 8697152 | 2019-09-26 22:09:39 +0000 | [diff] [blame] | 67 | // |
Zack Williams | e940c7a | 2019-08-21 14:25:39 -0700 | [diff] [blame] | 68 | // Note that the quantity will NEVER be internally represented by a |
| 69 | // floating point number. That is the whole point of this exercise. |
David Bainbridge | 8697152 | 2019-09-26 22:09:39 +0000 | [diff] [blame] | 70 | // |
Zack Williams | e940c7a | 2019-08-21 14:25:39 -0700 | [diff] [blame] | 71 | // Non-canonical values will still parse as long as they are well formed, |
| 72 | // but will be re-emitted in their canonical form. (So always use canonical |
| 73 | // form, or don't diff.) |
David Bainbridge | 8697152 | 2019-09-26 22:09:39 +0000 | [diff] [blame] | 74 | // |
Zack Williams | e940c7a | 2019-08-21 14:25:39 -0700 | [diff] [blame] | 75 | // This format is intended to make it difficult to use these numbers without |
| 76 | // writing some sort of special handling code in the hopes that that will |
| 77 | // cause implementors to also use a fixed point implementation. |
David Bainbridge | 8697152 | 2019-09-26 22:09:39 +0000 | [diff] [blame] | 78 | // |
Zack Williams | e940c7a | 2019-08-21 14:25:39 -0700 | [diff] [blame] | 79 | // +protobuf=true |
| 80 | // +protobuf.embed=string |
| 81 | // +protobuf.options.marshal=false |
| 82 | // +protobuf.options.(gogoproto.goproto_stringer)=false |
| 83 | // +k8s:deepcopy-gen=true |
| 84 | // +k8s:openapi-gen=true |
| 85 | message Quantity { |
| 86 | optional string string = 1; |
| 87 | } |
| 88 | |