@@ -9,26 +9,12 @@ import (
99)
1010
1111// Kind represents the basic type of a field in an object.
12- // Each kind defines the following encodings :
12+ // Each kind defines the following encoding :
1313//
1414// - Go Encoding: the golang type which should be accepted by listeners and
1515// generated by decoders when providing entity updates.
16- // - JSON Encoding: the JSON encoding which should be used when encoding the field to JSON.
17- // - Key Binary Encoding: the encoding which should be used when encoding the field
18- // as a key in binary messages. Some encodings specify a terminal and non-terminal form
19- // depending on whether or not the field is the last field in the key.
20- // - Value Binary Encoding: the encoding which should be used when encoding the field
21- // as a value in binary messages.
2216//
23- // When there is some non-determinism in an encoding, kinds should specify what
24- // values they accept and also what is the canonical, deterministic encoding which
25- // should be preferably emitted by serializers.
26- //
27- // Binary encodings were chosen based on what is likely to be the most convenient default binary encoding
28- // for state management implementations. This encoding allows for sorted keys whenever it is possible for a kind
29- // and is deterministic.
30- // Modules that use the specified encoding natively will have a trivial decoder implementation because the
31- // encoding is already in the correct format after any initial prefix bytes are stripped.
17+ // More encodings such as JSON or binary may be specified in the future.
3218type Kind int
3319
3420const (
@@ -37,110 +23,56 @@ const (
3723
3824 // StringKind is a string type.
3925 // Go Encoding: UTF-8 string with no null characters.
40- // JSON Encoding: string
41- // Key Binary Encoding:
42- // non-terminal: UTF-8 string with no null characters suffixed with a null character
43- // terminal: UTF-8 string with no null characters
44- // Value Binary Encoding: the same value binary encoding as BytesKind.
4526 StringKind
4627
4728 // BytesKind represents a byte array.
4829 // Go Encoding: []byte
49- // JSON Encoding: base64 encoded string, canonical values should be encoded with standard encoding and padding.
50- // Either standard or URL encoding with or without padding should be accepted.
51- // Key Binary Encoding:
52- // non-terminal: length prefixed bytes where the width of the length prefix is 1, 2, 3 or 4 bytes depending on
53- // the field's MaxLength (defaulting to 4 bytes).
54- // Length prefixes should be big-endian encoded.
55- // Values larger than 2^32 bytes are not supported (likely key-value stores impose a lower limit).
56- // terminal: raw bytes with no length prefix
57- // Value Binary Encoding: two 32-bit unsigned little-endian integers, the first one representing the offset of the
58- // value in the buffer and the second one representing the length of the value.
5930 BytesKind
6031
6132 // Int8Kind represents an 8-bit signed integer.
6233 // Go Encoding: int8
63- // JSON Encoding: number
64- // Key Binary Encoding: 1-byte two's complement encoding, with the first bit inverted for sorting.
65- // Value Binary Encoding: 1-byte two's complement encoding.
6634 Int8Kind
6735
6836 // Uint8Kind represents an 8-bit unsigned integer.
6937 // Go Encoding: uint8
70- // JSON Encoding: number
71- // Key Binary Encoding: 1-byte unsigned encoding.
72- // Value Binary Encoding: 1-byte unsigned encoding.
7338 Uint8Kind
7439
7540 // Int16Kind represents a 16-bit signed integer.
7641 // Go Encoding: int16
77- // JSON Encoding: number
78- // Key Binary Encoding: 2-byte two's complement big-endian encoding, with the first bit inverted for sorting.
79- // Value Binary Encoding: 2 byte two's complement little-endian encoding.
8042 Int16Kind
8143
8244 // Uint16Kind represents a 16-bit unsigned integer.
8345 // Go Encoding: uint16
84- // JSON Encoding: number
85- // Key Binary Encoding: 2-byte unsigned big-endian encoding.
86- // Value Binary Encoding: 2-byte unsigned little-endian encoding.
8746 Uint16Kind
8847
8948 // Int32Kind represents a 32-bit signed integer.
9049 // Go Encoding: int32
91- // JSON Encoding: number
92- // Key Binary Encoding: 4-byte two's complement big-endian encoding, with the first bit inverted for sorting.
93- // Value Binary Encoding: 4-byte two's complement little-endian encoding.
9450 Int32Kind
9551
9652 // Uint32Kind represents a 32-bit unsigned integer.
9753 // Go Encoding: uint32
98- // JSON Encoding: number
99- // Key Binary Encoding: 4-byte unsigned big-endian encoding.
100- // Value Binary Encoding: 4-byte unsigned little-endian encoding.
10154 Uint32Kind
10255
10356 // Int64Kind represents a 64-bit signed integer.
10457 // Go Encoding: int64
105- // JSON Encoding: base10 integer string which matches the IntegerFormat regex
106- // The canonical encoding should include no leading zeros.
107- // Key Binary Encoding: 8-byte two's complement big-endian encoding, with the first bit inverted for sorting.
108- // Value Binary Encoding: 8-byte two's complement little-endian encoding.
10958 Int64Kind
11059
11160 // Uint64Kind represents a 64-bit unsigned integer.
11261 // Go Encoding: uint64
113- // JSON Encoding: base10 integer string which matches the IntegerFormat regex
114- // Canonically encoded values should include no leading zeros.
115- // Key Binary Encoding: 8-byte unsigned big-endian encoding.
116- // Value Binary Encoding: 8-byte unsigned little-endian encoding.
11762 Uint64Kind
11863
11964 // IntegerKind represents an arbitrary precision integer number.
12065 // Support for expressing the maximum bit precision of values will be added in the future.
12166 // Go Encoding: string which matches the IntegerFormat regex (unstable, subject to change).
122- // JSON Encoding: base10 integer string
123- // Canonically encoded values should include no leading zeros.
124- // Equality comparison with integers should be done using numerical equality rather
125- // than string equality.
12667 IntegerKind
12768
12869 // DecimalKind represents an arbitrary precision decimal or integer number.
12970 // Support for optionally limiting the precision may be added in the future.
13071 // Go Encoding: string which matches the DecimalFormat regex
131- // JSON Encoding: base10 decimal string
132- // Canonically encoded values should include no leading zeros or trailing zeros,
133- // and exponential notation with a lowercase 'e' should be used for any numbers
134- // with an absolute value less than or equal to 1e-6 or greater than or equal to 1e6.
135- // Equality comparison with decimals should be done using numerical equality rather
136- // than string equality.
13772 DecimalKind
13873
13974 // BoolKind represents a boolean true or false value.
14075 // Go Encoding: bool
141- // JSON Encoding: boolean
142- // Key Binary Encoding: 1-byte encoding where 0 is false and 1 is true.
143- // Value Binary Encoding: 1-byte encoding where 0 is false and 1 is true.
14476 BoolKind
14577
14678 // TimeKind represents a nanosecond precision UNIX time value (with zero representing January 1, 1970 UTC).
@@ -157,106 +89,32 @@ const (
15789 // DurationKind represents the elapsed time between two nanosecond precision time values.
15890 // Its valid range is +/- 2^63 (the range of a 64-bit signed integer).
15991 // Go Encoding: time.Duration
160- // JSON Encoding: the number of seconds as a decimal string with no trailing zeros followed by
161- // a lowercase 's' character to represent seconds.
162- // Key Binary Encoding: 8-byte two's complement big-endian encoding, with the first bit inverted for sorting.
163- // Value Binary Encoding: 8-byte two's complement little-endian encoding.
16492 DurationKind
16593
16694 // Float32Kind represents an IEEE-754 32-bit floating point number.
16795 // Go Encoding: float32
168- // JSON Encoding: number
169- // Key Binary Encoding: 4-byte IEEE-754 encoding.
170- // Value Binary Encoding: 4-byte IEEE-754 encoding.
17196 Float32Kind
17297
17398 // Float64Kind represents an IEEE-754 64-bit floating point number.
17499 // Go Encoding: float64
175- // JSON Encoding: number
176- // Key Binary Encoding: 8-byte IEEE-754 encoding.
177- // Value Binary Encoding: 8-byte IEEE-754 encoding.
178100 Float64Kind
179101
180102 // AddressKind represents an account address which is represented by a variable length array of bytes.
181103 // Addresses usually have a human-readable rendering, such as bech32, and tooling should provide
182104 // a way for apps to define a string encoder for friendly user-facing display. Addresses have a maximum
183105 // supported length of 63 bytes.
184106 // Go Encoding: []byte
185- // JSON Encoding: addresses should be encoded as strings using the human-readable address renderer
186- // provided to the JSON encoder.
187- // Key Binary Encoding:
188- // non-terminal: bytes prefixed with 1-byte length prefix
189- // terminal: raw bytes with no length prefix
190- // Value Binary Encoding: bytes prefixed with 1-byte length prefix.
191107 AddressKind
192108
193109 // EnumKind represents a value of an enum type.
194110 // Fields of this type are expected to set the EnumType field in the field definition to the enum
195111 // definition.
196112 // Go Encoding: string
197- // JSON Encoding: string
198- // Key Binary Encoding: the same binary encoding as the EnumType's numeric kind.
199- // Value Binary Encoding: the same binary encoding as the EnumType's numeric kind.
200113 EnumKind
201114
202115 // JSONKind represents arbitrary JSON data.
203116 // Go Encoding: json.RawMessage
204- // JSON Encoding: any valid JSON value
205- // Key Binary Encoding: string encoding
206- // Value Binary Encoding: string encoding
207117 JSONKind
208-
209- // UIntNKind represents a signed integer type with a width in bits specified by the Size field in the
210- // field definition.
211- // Support for this is currently UNIMPLEMENTED, this notice will be removed when it is added.
212- // N must be a multiple of 8, and it is invalid for N to equal 8, 16, 32, 64 as there are more specific
213- // types for these widths.
214- // Go Encoding: []byte where len([]byte) == Size / 8, little-endian encoded.
215- // JSON Encoding: base10 integer string matching the IntegerFormat regex, canonically with no leading zeros.
216- // Key Binary Encoding: N / 8 bytes big-endian encoded
217- // Value Binary Encoding: N / 8 bytes little-endian encoded
218- UIntNKind
219-
220- // IntNKind represents an unsigned integer type with a width in bits specified by the Size field in the
221- // field definition. N must be a multiple of 8.
222- // Support for this is currently UNIMPLEMENTED, this notice will be removed when it is added.
223- // N must be a multiple of 8, and it is invalid for N to equal 8, 16, 32, 64 as there are more specific
224- // types for these widths.
225- // Go Encoding: []byte where len([]byte) == Size / 8, two's complement little-endian encoded.
226- // JSON Encoding: base10 integer string matching the IntegerFormat regex, canonically with no leading zeros.
227- // Key Binary Encoding: N / 8 bytes big-endian two's complement encoded with the first bit inverted for sorting.
228- // Value Binary Encoding: N / 8 bytes little-endian two's complement encoded.
229- IntNKind
230-
231- // StructKind represents a struct object.
232- // Support for this is currently UNIMPLEMENTED, this notice will be removed when it is added.
233- // Go Encoding: an array of type []interface{} where each element is of the respective field's kind type.
234- // JSON Encoding: an object where each key is the field name and the value is the field value.
235- // Canonically, keys are in alphabetical order with no extra whitespace.
236- // Key Binary Encoding: not valid as a key field.
237- // Value Binary Encoding: 32-bit unsigned little-endian length prefix,
238- // followed by the value binary encoding of each field in order.
239- StructKind
240-
241- // OneOfKind represents a field that can be one of a set of types.
242- // Support for this is currently UNIMPLEMENTED, this notice will be removed when it is added.
243- // Go Encoding: the anonymous struct { Case string; Value interface{} }, aliased as OneOfValue.
244- // JSON Encoding: same as the case's struct encoding with "@type" set to the case name.
245- // Key Binary Encoding: not valid as a key field.
246- // Value Binary Encoding: the oneof's discriminant numeric value encoded as its discriminant kind
247- // followed by the encoded value.
248- OneOfKind
249-
250- // ListKind represents a list of elements.
251- // Support for this is currently UNIMPLEMENTED, this notice will be removed when it is added.
252- // Go Encoding: an array of type []interface{} where each element is of the respective field's kind type.
253- // JSON Encoding: an array of values where each element is the field value.
254- // Canonically, there is no extra whitespace.
255- // Key Binary Encoding: not valid as a key field.
256- // Value Binary Encoding: 32-bit unsigned little-endian size prefix indicating the size of the encoded data in bytes,
257- // followed by a 32-bit unsigned little-endian count of the number of elements in the list,
258- // followed by each element encoded with value binary encoding.
259- ListKind
260118)
261119
262120// MAX_VALID_KIND is the maximum valid kind value.
0 commit comments