You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
- Functions taking `key: [u8; KeyBytes]` expect a fixed-length key known at compile time.
98
98
- Functions with `_var` take `key: BoundedVec<u8, KeyBytes>` for variable-length keys up to `KeyBytes`.
99
99
100
-
### Object getters API
101
-
102
-
-**`get_object<let KeyBytes>(key: [u8; KeyBytes])` → `Option<JSON>`**: From an object root, returns `Some(JSON)` if `key` exists and is an object, `None` if `key` is missing; errors if `key` exists but is not an object, or if called when the current root is an array.
103
-
104
-
-**`get_object_unchecked<let KeyBytes>(key: [u8; KeyBytes])` → `JSON`**: From an object root, returns the object at `key`; errors otherwise.
105
-
106
-
-**`get_object_var<let KeyBytes>(key: BoundedVec<u8, KeyBytes>)` → `Option<JSON>`**: Same as `get_object`, but the key can be variable-length up to `KeyBytes`.
107
-
108
-
-**`get_object_unchecked_var<let KeyBytes>(key: BoundedVec<u8, KeyBytes>)` → `JSON`**: Same as `get_object_unchecked`, but with a variable-length key.
109
-
110
-
-**`get_object_from_array(index: Field)` → `Option<JSON>`**: When the current root is an array, returns the object at `index` wrapped in `Option`. Returns `None` if `index` is out of bounds; errors if in-bounds but the element is not an object.
111
-
112
-
-**`get_object_from_array_unchecked(index: Field)` → `JSON`**: When the current root is an array, returns the object at `index`. Errors if `index` is out of bounds or the element is not an object.
113
-
114
-
### Array getters API
115
-
116
-
-**`get_length()` → `u32`**: Returns its length when the current root is an array; errors otherwise.
117
-
118
-
-**`get_array<let KeyBytes>(key: [u8; KeyBytes])` → `Option<JSON>`**: From an object root, returns Some(JSON) if key exists and is an array, None if key is missing; errors if key exists but is not an array, or if called when the current root is an array.
119
-
120
-
-**`get_array_unchecked<let KeyBytes>(key: [u8; KeyBytes])` → `JSON`**: From an object root, returns the array at key; errors otherwise.
121
-
122
-
-**`get_array_var<let KeyBytes>(key: BoundedVec<u8, KeyBytes>)` → `Option<JSON>`**: Same as `get_array`, but the key can be variable-length up to `KeyBytes`.
123
-
124
-
-**`get_array_unchecked_var<let KeyBytes>(key: BoundedVec<u8, KeyBytes>)` → `JSON`**: Same as `get_array_unchecked`, but with a variable-length key.
125
-
126
-
-**`get_array_from_array(index: Field)` → `Option<JSON>`**: When the current root is an array, returns the nested array at `index` wrapped in `Option`. Returns `None` if `index` is out of bounds; errors if in-bounds but the element is not an array.
127
-
128
-
-**`get_array_from_array_unchecked(index: Field)` → `JSON`**: When the current root is an array, returns the nested array at `index`. Errors if `index` is out of bounds or the element is not an array.
129
-
130
-
### Literal getters API
131
-
132
-
Literals are the JSON keywords `true`, `false`, and `null`. They are represented by `JSONLiteral`, which supports:
-**`get_literal<let KeyBytes>(key: [u8; KeyBytes])` → `Option<JSONLiteral>`**: From an object root, returns `Some(JSONLiteral)` if `key` exists and is a literal; `None` if `key` is missing; errors if `key` exists but is not a literal, or if called when the current root is an array.
137
-
138
-
-**`get_literal_unchecked<let KeyBytes>(key: [u8; KeyBytes])` → `JSONLiteral`**: From an object root, returns the literal at `key`; errors if the key is missing, not a literal, or if called when the current root is an array.
139
-
140
-
-**`get_literal_var<let KeyBytes>(key: BoundedVec<u8, KeyBytes>)` → `Option<JSONLiteral>`**: Same as `get_literal`, but accepts a variable-length key up to `KeyBytes`.
141
-
142
-
-**`get_literal_unchecked_var<let KeyBytes>(key: BoundedVec<u8, KeyBytes>)` → `JSONLiteral`**: Same as `get_literal_unchecked`, with a variable-length key.
143
-
144
-
-**`get_literal_from_array(index: Field)` → `Option<JSONLiteral>`**: When the current root is an array, returns the literal at `index` wrapped in `Option`. Returns `None` if `index` is out of bounds; errors if in-bounds but the element at `index` is not a literal.
145
-
146
-
-**`get_literal_from_array_unchecked(index: Field)` → `JSONLiteral`**: When the current root is an array, returns the literal at `index`; errors if `index` is out of bounds or the element is not a literal.
147
-
148
-
### Number getters API
149
-
150
-
Numbers are parsed as unsigned integers and must fit into `u64` (no decimals).
151
-
152
-
-**`get_number<let KeyBytes>(key: [u8; KeyBytes])` → `Option<u64>`**: From an object root, returns `Some(u64)` if `key` exists and is a number; `None` if `key` is missing; errors if `key` exists but is not a number, or if called when the current root is an array.
153
-
154
-
-**`get_number_unchecked<let KeyBytes>(key: [u8; KeyBytes])` → `u64`**: From an object root, returns the number at `key`; errors if the key is missing, not a number, or if called when the current root is an array.
155
-
156
-
-**`get_number_var<let KeyBytes>(key: BoundedVec<u8, KeyBytes>)` → `Option<u64>`**: Same as `get_number`, but accepts a variable-length key up to `KeyBytes`.
157
-
158
-
-**`get_number_unchecked_var<let KeyBytes>(key: BoundedVec<u8, KeyBytes>)` → `u64`**: Same as `get_number_unchecked`, with a variable-length key.
159
-
160
-
-**`get_number_from_array(index: Field)` → `Option<u64>`**: When the current root is an array, returns the number at `index` wrapped in `Option`. Returns `None` if `index` is out of bounds; errors if in-bounds but the element at `index` is not a number.
161
-
162
-
-**`get_number_from_array_unchecked(index: Field)` → `u64`**: When the current root is an array, returns the number at `index`; errors if `index` is out of bounds or the element is not a number.
163
-
164
-
### String getters API
165
-
166
-
Strings are returned as `BoundedVec<u8, StringBytes>` where `StringBytes` is the maximum allowed length of the returned string.
167
-
168
-
-**`get_string<let KeyBytes, let StringBytes>(key: [u8; KeyBytes])` → `Option<BoundedVec<u8, StringBytes>>`**: From an object root, returns `Some(string)` if `key` exists and is a string; `None` if `key` is missing; errors if `key` exists but is not a string, or if called when the current root is an array.
169
-
170
-
-**`get_string_unchecked<let KeyBytes, let StringBytes>(key: [u8; KeyBytes])` → `BoundedVec<u8, StringBytes>`**: From an object root, returns the string at `key`; errors otherwise.
171
-
172
-
-**`get_string_var<let KeyBytes, let StringBytes>(key: BoundedVec<u8, KeyBytes>)` → `Option<BoundedVec<u8, StringBytes>>`**: Same as `get_string`, but accepts a variable-length key up to `KeyBytes`.
173
-
174
-
-**`get_string_unchecked_var<let KeyBytes, let StringBytes>(key: BoundedVec<u8, KeyBytes>)` → `BoundedVec<u8, StringBytes>`**: Same as `get_string_unchecked`, with a variable-length key.
175
-
176
-
-**`get_string_from_array<let StringBytes>(index: Field)` → `Option<BoundedVec<u8, StringBytes>>`**: When the current root is an array, returns the string at `index` wrapped in `Option`. Returns `None` if `index` is out of bounds; errors if in-bounds but the element at `index` is not a string.
177
-
178
-
-**`get_string_from_array_unchecked<let StringBytes>(index: Field)` → `BoundedVec<u8, StringBytes>`**: When the current root is an array, returns the string at `index`; errors if `index` is out of bounds or the element is not a string.
179
-
180
-
-**`get_string_from_path<let KeyBytes, let StringBytes, let PathDepth>(keys: [BoundedVec<u8, KeyBytes>; PathDepth])` → `Option<BoundedVec<u8, StringBytes>>`**: Traverses nested objects by the given keys; returns Some(string) if the final value exists and is a string, otherwise None.
Copy file name to clipboardExpand all lines: src/get_array.nr
+1-1Lines changed: 1 addition & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -152,7 +152,7 @@ impl<let NumBytes: u32, let NumPackedFields: u32, let MaxNumTokens: u32, let Max
152
152
153
153
/**
154
154
* @brief if the root JSON is an array, extract an array given by the position of the target in the source array
155
-
* @description will revert if the array does not exist
155
+
* @description When the current root is an array, returns the nested array at `index`. Errors if `index` is out of bounds or the element is not an array.
* @brief getter methods for extracting literal values out of a JSON struct
69
+
* @description iterals are the JSON keywords `true`, `false`, and `null`. They are represented by `JSONLiteral`, which supports: `is_true()`, `is_false()`, `is_null()`, `to_bool()` (maps `true` to `true`, `false`/`null` to `false`)
* @brief if the root JSON is an object, extract a literal value given by `key`
74
-
* @description returns an Option<JSONLiteral> which will be null if the literal does not exist
75
+
* @description From an object root, returns `Some(JSONLiteral)` if `key` exists and is a literal; `None` if `key` is missing; errors if `key` exists but is not a literal, or if called when the current root is an array.
assert(self.layer_type_of_root != ARRAY_LAYER, "cannot extract array elements via a key");
@@ -93,7 +94,7 @@ impl<let NumBytes: u32, let NumPackedFields: u32, let MaxNumTokens: u32, let Max
93
94
94
95
/**
95
96
* @brief if the root JSON is an object, extract a literal value given by `key`
96
-
* @description will revert if the literal does not exist
97
+
* @description From an object root, returns the literal at `key`; errors if the key is missing, not a literal, or if called when the current root is an array.
assert(self.layer_type_of_root != ARRAY_LAYER, "cannot extract array elements via a key");
@@ -110,7 +111,7 @@ impl<let NumBytes: u32, let NumPackedFields: u32, let MaxNumTokens: u32, let Max
110
111
}
111
112
112
113
/**
113
-
* @brief same as `get_literal` for where the key length may be less than KeyBytes
114
+
* @brief Same as `get_literal`, but accepts a variable-length key up to `KeyBytes`.
114
115
**/
115
116
pubfnget_literal_var<letKeyBytes: u32>(
116
117
self,
@@ -134,7 +135,7 @@ impl<let NumBytes: u32, let NumPackedFields: u32, let MaxNumTokens: u32, let Max
134
135
}
135
136
136
137
/**
137
-
* @brief same as `get_literal_unchecked` for where the key length may be less than KeyBytes
138
+
* @brief Same as `get_literal_unchecked`, with a variable-length key.
138
139
**/
139
140
pubfnget_literal_unchecked_var<letKeyBytes: u32>(
140
141
self,
@@ -155,7 +156,7 @@ impl<let NumBytes: u32, let NumPackedFields: u32, let MaxNumTokens: u32, let Max
155
156
156
157
/**
157
158
* @brief if the root JSON is an array, extract a literal given by the position of the target in the source array
158
-
* @description returns an Option<JSONLiteral> which will be null if the literal does not exist
159
+
* @description When the current root is an array, returns the literal at `index` wrapped in `Option`. Returns `None` if `index` is out of bounds; errors if in-bounds but the element at `index` is not a literal.
Copy file name to clipboardExpand all lines: src/get_number.nr
+8-14Lines changed: 8 additions & 14 deletions
Original file line number
Diff line number
Diff line change
@@ -52,7 +52,7 @@ impl<let NumBytes: u32, let NumPackedFields: u32, let MaxNumTokens: u32, let Max
52
52
53
53
/**
54
54
* @brief if the root JSON is an object, extract a numeric value given by `key`
55
-
* @description returns an Option<u64> which will be null if the key does not exist
55
+
* @description From an object root, returns `Some(u64)` if `key` exists and is a number; `None` if `key` is missing; errors if `key` exists but is not a number, or if called when the current root is an array.
@@ -71,7 +71,7 @@ impl<let NumBytes: u32, let NumPackedFields: u32, let MaxNumTokens: u32, let Max
71
71
72
72
/**
73
73
* @brief if the root JSON is an object, extract a u64 value given by `key`
74
-
* @description will revert if the number does not exist
74
+
* @description From an object root, returns the number at `key`; errors if the key is missing, not a number, or if called when the current root is an array.
@@ -118,13 +118,10 @@ impl<let NumBytes: u32, let NumPackedFields: u32, let MaxNumTokens: u32, let Max
118
118
119
119
/**
120
120
* @brief if the root JSON is an array, extract a numeric value given by the position of the target in the source array
121
-
* @description returns an Option<u64> which will be null if the number does not exist
121
+
* @description When the current root is an array, returns the number at `index` wrapped in `Option`. Returns `None` if `index` is out of bounds; errors if in-bounds but the element at `index` is not a number.
Copy file name to clipboardExpand all lines: src/get_string.nr
+7-7Lines changed: 7 additions & 7 deletions
Original file line number
Diff line number
Diff line change
@@ -98,7 +98,7 @@ impl<let NumBytes: u32, let NumPackedFields: u32, let MaxNumTokens: u32, let Max
98
98
99
99
/**
100
100
* @brief if the root JSON is an object, extract a string given by `key`
101
-
* @description returns an Option<BoundedVec> which will be null if the key does not exist
101
+
* @description From an object root, returns `Some(string)` if `key` exists and is a string; `None` if `key` is missing; errors if `key` exists but is not a string, or if called when the current root is an array.
102
102
* @note the `StringBytes` parameter defines the maximum allowable length of the returned string
@@ -189,7 +189,7 @@ impl<let NumBytes: u32, let NumPackedFields: u32, let MaxNumTokens: u32, let Max
189
189
190
190
/**
191
191
* @brief if the root JSON is an array, extract a string given by the position of the target in the source array
192
-
* @description returns an Option<BoundedVec> which will be null if the string does not exist
192
+
* @description When the current root is an array, returns the string at `index` wrapped in `Option`. Returns `None` if `index` is out of bounds; errors if in-bounds but the element at `index` is not a string.
193
193
**/
194
194
pubfnget_string_from_array<letStringBytes: u32>(
195
195
self,
@@ -229,7 +229,7 @@ impl<let NumBytes: u32, let NumPackedFields: u32, let MaxNumTokens: u32, let Max
229
229
230
230
/**
231
231
* @brief if the root JSON is an array, extract a string given by the position of the target in the source array
232
-
* @description will revert if the string does not exist
232
+
* @description When the current root is an array, returns the string at `index`; errors if `index` is out of bounds or the element is not a string.
0 commit comments