diff --git a/src/lib.nr b/src/lib.nr index 41c629a..43fd1ab 100644 --- a/src/lib.nr +++ b/src/lib.nr @@ -16,14 +16,12 @@ mod get_literal; mod get_object; mod get_array; -use crate::_string_tools::slice_packed_field::slice_fields; -use crate::get_literal::JSONLiteral; -use crate::json::JSON; -use crate::json::JSONValue; -use crate::json_entry::JSONEntry; -use crate::json_entry::JSONEntryPacked; +use _string_tools::slice_packed_field::slice_fields; +use get_literal::JSONLiteral; +use json::{JSON, JSONValue}; +use json_entry::{JSONEntry, JSONEntryPacked}; -trait JSONParserTrait { +pub trait JSONParserTrait { fn parse_json_from_string(s: str) -> Self; fn parse_json(s: [u8; StringBytes]) -> Self; fn get_length(self) -> u32; @@ -125,1289 +123,9 @@ trait JSONParserTrait { ) -> BoundedVec, MaxNumKeys>; } -mod JSON512b { - struct JSON { - inner: crate::json::JSON<512, 20, 64, 33, 2>, - } - - impl JSON { - fn convert(inner: Option>) -> Option { - Option { _is_some: inner._is_some, _value: JSON { inner: inner._value } } - } - } - impl crate::JSONParserTrait for JSON { - fn parse_json_from_string(s: str) -> Self { - JSON { inner: crate::json::JSON::parse_json_from_string(s) } - } - - fn parse_json(s: [u8; StringBytes]) -> Self { - JSON { inner: crate::json::JSON::parse_json(s) } - } - fn get_length(self) -> u32 { - self.inner.get_length() - } - fn get_array(self, key: [u8; KeyBytes]) -> Option { - JSON::convert(self.inner.get_array(key)) - } - fn get_array_unchecked(self, key: [u8; KeyBytes]) -> Self { - JSON { inner: self.inner.get_array_unchecked(key) } - } - fn get_array_var(self, key: BoundedVec) -> Option { - { - JSON::convert(self.inner.get_array_var(key)) - } - } - fn get_array_unchecked_var(self, key: BoundedVec) -> Self { - JSON { inner: self.inner.get_array_unchecked_var(key) } - } - fn get_array_from_array(self, array_index: Field) -> Option { - JSON::convert(self.inner.get_array_from_array(array_index)) - } - fn get_array_from_array_unchecked(self, array_index: Field) -> Self { - JSON { inner: self.inner.get_array_from_array_unchecked(array_index) } - } - fn map( - self, - f: fn(crate::JSONValue) -> U, - ) -> [U; MaxElements] - where - U: std::default::Default, - { - self.inner.map(f) - } - fn get_object(self, key: [u8; KeyBytes]) -> Option { - { - JSON::convert(self.inner.get_object(key)) - } - } - fn get_object_unchecked(self, key: [u8; KeyBytes]) -> Self { - JSON { inner: self.inner.get_object_unchecked(key) } - } - fn get_object_var(self, key: BoundedVec) -> Option { - { - JSON::convert(self.inner.get_object_var(key)) - } - } - fn get_object_unchecked_var( - self, - key: BoundedVec, - ) -> Self { - JSON { inner: self.inner.get_object_unchecked_var(key) } - } - fn get_object_from_array(self, array_index: Field) -> Option { - JSON::convert(self.inner.get_object_from_array(array_index)) - } - fn get_object_from_array_unchecked(self, array_index: Field) -> Self { - JSON { inner: self.inner.get_object_from_array_unchecked(array_index) } - } - fn get_literal(self, key: [u8; KeyBytes]) -> Option { - self.inner.get_literal(key) - } - fn get_literal_unchecked( - self, - key: [u8; KeyBytes], - ) -> crate::JSONLiteral { - self.inner.get_literal_unchecked(key) - } - fn get_literal_var( - self, - key: BoundedVec, - ) -> Option { - self.inner.get_literal_var(key) - } - fn get_literal_unchecked_var( - self, - key: BoundedVec, - ) -> crate::JSONLiteral { - self.inner.get_literal_unchecked_var(key) - } - fn get_literal_from_array(self, array_index: Field) -> Option { - self.inner.get_literal_from_array(array_index) - } - fn get_literal_from_array_unchecked(self, array_index: Field) -> crate::JSONLiteral { - self.inner.get_literal_from_array_unchecked(array_index) - } - fn get_number(self, key: [u8; KeyBytes]) -> Option { - self.inner.get_number(key) - } - fn get_number_unchecked(self, key: [u8; KeyBytes]) -> u64 { - self.inner.get_number_unchecked(key) - } - fn get_number_var(self, key: BoundedVec) -> Option { - self.inner.get_number_var(key) - } - fn get_number_unchecked_var(self, key: BoundedVec) -> u64 { - self.inner.get_number_unchecked_var(key) - } - fn get_number_from_array(self, array_index: Field) -> Option { - self.inner.get_number_from_array(array_index) - } - fn get_number_from_array_unchecked(self, array_index: Field) -> u64 { - self.inner.get_number_from_array_unchecked(array_index) - } - - fn get_string( - self, - key: [u8; KeyBytes], - ) -> Option> { - self.inner.get_string(key) - } - fn get_string_unchecked( - self, - key: [u8; KeyBytes], - ) -> BoundedVec { - self.inner.get_string_unchecked(key) - } - fn get_string_var( - self, - key: BoundedVec, - ) -> Option> { - self.inner.get_string_var(key) - } - fn get_string_unchecked_var( - self, - key: BoundedVec, - ) -> BoundedVec { - self.inner.get_string_unchecked_var(key) - } - fn get_string_from_array( - self, - array_index: Field, - ) -> Option> { - self.inner.get_string_from_array(array_index) - } - fn get_string_from_array_unchecked( - self, - array_index: Field, - ) -> BoundedVec { - self.inner.get_string_from_array_unchecked(array_index) - } - fn get_string_from_path( - self, - keys: [BoundedVec; PathDepth], - ) -> Option> { - self.inner.get_string_from_path(keys) - } - fn get_value( - self, - key: [u8; KeyBytes], - ) -> Option> { - self.inner.get_value(key) - } - fn get_value_unchecked( - self, - key: [u8; KeyBytes], - ) -> crate::JSONValue { - self.inner.get_value_unchecked(key) - } - fn get_value_var( - self, - key: BoundedVec, - ) -> Option> { - self.inner.get_value_var(key) - } - fn get_value_unchecked_var( - self, - key: BoundedVec, - ) -> crate::JSONValue { - self.inner.get_value_unchecked_var(key) - } - fn get_value_from_array( - self, - array_index: Field, - ) -> Option> { - self.inner.get_value_from_array(array_index) - } - fn get_value_from_array_unchecked( - self, - array_index: Field, - ) -> crate::JSONValue { - self.inner.get_value_from_array_unchecked(array_index) - } - fn get_value_from_path( - self, - keys: [BoundedVec; PathDepth], - ) -> Option> { - self.inner.get_value_from_path(keys) - } - - fn key_exists(self, key: BoundedVec) -> bool { - self.inner.key_exists(key) - } - fn get_keys_at_root( - self, - ) -> BoundedVec, MaxNumKeys> { - self.inner.get_keys_at_root() - } - } -} - -mod JSON1kb { - struct JSON { - inner: crate::json::JSON<1024, 37, 128, 65, 2>, - } - impl JSON { - fn convert(inner: Option>) -> Option { - Option { _is_some: inner._is_some, _value: JSON { inner: inner._value } } - } - } - impl crate::JSONParserTrait for JSON { - fn parse_json_from_string(s: str) -> Self { - JSON { inner: crate::json::JSON::parse_json_from_string(s) } - } - - fn parse_json(s: [u8; StringBytes]) -> Self { - JSON { inner: crate::json::JSON::parse_json(s) } - } - fn get_length(self) -> u32 { - self.inner.get_length() - } - fn get_array(self, key: [u8; KeyBytes]) -> Option { - JSON::convert(self.inner.get_array(key)) - } - fn get_array_unchecked(self, key: [u8; KeyBytes]) -> Self { - JSON { inner: self.inner.get_array_unchecked(key) } - } - fn get_array_var(self, key: BoundedVec) -> Option { - { - JSON::convert(self.inner.get_array_var(key)) - } - } - fn get_array_unchecked_var(self, key: BoundedVec) -> Self { - JSON { inner: self.inner.get_array_unchecked_var(key) } - } - fn get_array_from_array(self, array_index: Field) -> Option { - JSON::convert(self.inner.get_array_from_array(array_index)) - } - fn get_array_from_array_unchecked(self, array_index: Field) -> Self { - JSON { inner: self.inner.get_array_from_array_unchecked(array_index) } - } - fn map( - self, - f: fn(crate::JSONValue) -> U, - ) -> [U; MaxElements] - where - U: std::default::Default, - { - self.inner.map(f) - } - fn get_object(self, key: [u8; KeyBytes]) -> Option { - { - JSON::convert(self.inner.get_object(key)) - } - } - fn get_object_unchecked(self, key: [u8; KeyBytes]) -> Self { - JSON { inner: self.inner.get_object_unchecked(key) } - } - fn get_object_var(self, key: BoundedVec) -> Option { - { - JSON::convert(self.inner.get_object_var(key)) - } - } - fn get_object_unchecked_var( - self, - key: BoundedVec, - ) -> Self { - JSON { inner: self.inner.get_object_unchecked_var(key) } - } - fn get_object_from_array(self, array_index: Field) -> Option { - JSON::convert(self.inner.get_object_from_array(array_index)) - } - fn get_object_from_array_unchecked(self, array_index: Field) -> Self { - JSON { inner: self.inner.get_object_from_array_unchecked(array_index) } - } - fn get_literal(self, key: [u8; KeyBytes]) -> Option { - self.inner.get_literal(key) - } - fn get_literal_unchecked( - self, - key: [u8; KeyBytes], - ) -> crate::JSONLiteral { - self.inner.get_literal_unchecked(key) - } - fn get_literal_var( - self, - key: BoundedVec, - ) -> Option { - self.inner.get_literal_var(key) - } - fn get_literal_unchecked_var( - self, - key: BoundedVec, - ) -> crate::JSONLiteral { - self.inner.get_literal_unchecked_var(key) - } - fn get_literal_from_array(self, array_index: Field) -> Option { - self.inner.get_literal_from_array(array_index) - } - fn get_literal_from_array_unchecked(self, array_index: Field) -> crate::JSONLiteral { - self.inner.get_literal_from_array_unchecked(array_index) - } - fn get_number(self, key: [u8; KeyBytes]) -> Option { - self.inner.get_number(key) - } - fn get_number_unchecked(self, key: [u8; KeyBytes]) -> u64 { - self.inner.get_number_unchecked(key) - } - fn get_number_var(self, key: BoundedVec) -> Option { - self.inner.get_number_var(key) - } - fn get_number_unchecked_var(self, key: BoundedVec) -> u64 { - self.inner.get_number_unchecked_var(key) - } - fn get_number_from_array(self, array_index: Field) -> Option { - self.inner.get_number_from_array(array_index) - } - fn get_number_from_array_unchecked(self, array_index: Field) -> u64 { - self.inner.get_number_from_array_unchecked(array_index) - } - fn get_string( - self, - key: [u8; KeyBytes], - ) -> Option> { - self.inner.get_string(key) - } - fn get_string_unchecked( - self, - key: [u8; KeyBytes], - ) -> BoundedVec { - self.inner.get_string_unchecked(key) - } - fn get_string_var( - self, - key: BoundedVec, - ) -> Option> { - self.inner.get_string_var(key) - } - fn get_string_unchecked_var( - self, - key: BoundedVec, - ) -> BoundedVec { - self.inner.get_string_unchecked_var(key) - } - fn get_string_from_array( - self, - array_index: Field, - ) -> Option> { - self.inner.get_string_from_array(array_index) - } - fn get_string_from_array_unchecked( - self, - array_index: Field, - ) -> BoundedVec { - self.inner.get_string_from_array_unchecked(array_index) - } - fn get_string_from_path( - self, - keys: [BoundedVec; PathDepth], - ) -> Option> { - self.inner.get_string_from_path(keys) - } - fn get_value( - self, - key: [u8; KeyBytes], - ) -> Option> { - self.inner.get_value(key) - } - fn get_value_unchecked( - self, - key: [u8; KeyBytes], - ) -> crate::JSONValue { - self.inner.get_value_unchecked(key) - } - fn get_value_var( - self, - key: BoundedVec, - ) -> Option> { - self.inner.get_value_var(key) - } - fn get_value_unchecked_var( - self, - key: BoundedVec, - ) -> crate::JSONValue { - self.inner.get_value_unchecked_var(key) - } - fn get_value_from_array( - self, - array_index: Field, - ) -> Option> { - self.inner.get_value_from_array(array_index) - } - fn get_value_from_array_unchecked( - self, - array_index: Field, - ) -> crate::JSONValue { - self.inner.get_value_from_array_unchecked(array_index) - } - fn get_value_from_path( - self, - keys: [BoundedVec; PathDepth], - ) -> Option> { - self.inner.get_value_from_path(keys) - } - fn key_exists(self, key: BoundedVec) -> bool { - self.inner.key_exists(key) - } - fn get_keys_at_root( - self, - ) -> BoundedVec, MaxNumKeys> { - self.inner.get_keys_at_root() - } - } -} - -mod JSON2kb { - struct JSON { - inner: crate::json::JSON<2048, 70, 256, 129, 2>, - } - impl JSON { - fn convert(inner: Option>) -> Option { - Option { _is_some: inner._is_some, _value: JSON { inner: inner._value } } - } - } - impl crate::JSONParserTrait for JSON { - fn parse_json_from_string(s: str) -> Self { - JSON { inner: crate::json::JSON::parse_json_from_string(s) } - } - - fn parse_json(s: [u8; StringBytes]) -> Self { - JSON { inner: crate::json::JSON::parse_json(s) } - } - fn get_length(self) -> u32 { - self.inner.get_length() - } - fn get_array(self, key: [u8; KeyBytes]) -> Option { - JSON::convert(self.inner.get_array(key)) - } - fn get_array_unchecked(self, key: [u8; KeyBytes]) -> Self { - JSON { inner: self.inner.get_array_unchecked(key) } - } - fn get_array_var(self, key: BoundedVec) -> Option { - { - JSON::convert(self.inner.get_array_var(key)) - } - } - fn get_array_unchecked_var(self, key: BoundedVec) -> Self { - JSON { inner: self.inner.get_array_unchecked_var(key) } - } - fn get_array_from_array(self, array_index: Field) -> Option { - JSON::convert(self.inner.get_array_from_array(array_index)) - } - fn get_array_from_array_unchecked(self, array_index: Field) -> Self { - JSON { inner: self.inner.get_array_from_array_unchecked(array_index) } - } - fn map( - self, - f: fn(crate::JSONValue) -> U, - ) -> [U; MaxElements] - where - U: std::default::Default, - { - self.inner.map(f) - } - fn get_object(self, key: [u8; KeyBytes]) -> Option { - { - JSON::convert(self.inner.get_object(key)) - } - } - fn get_object_unchecked(self, key: [u8; KeyBytes]) -> Self { - JSON { inner: self.inner.get_object_unchecked(key) } - } - fn get_object_var(self, key: BoundedVec) -> Option { - { - JSON::convert(self.inner.get_object_var(key)) - } - } - fn get_object_unchecked_var( - self, - key: BoundedVec, - ) -> Self { - JSON { inner: self.inner.get_object_unchecked_var(key) } - } - fn get_object_from_array(self, array_index: Field) -> Option { - JSON::convert(self.inner.get_object_from_array(array_index)) - } - fn get_object_from_array_unchecked(self, array_index: Field) -> Self { - JSON { inner: self.inner.get_object_from_array_unchecked(array_index) } - } - fn get_literal(self, key: [u8; KeyBytes]) -> Option { - self.inner.get_literal(key) - } - fn get_literal_unchecked( - self, - key: [u8; KeyBytes], - ) -> crate::JSONLiteral { - self.inner.get_literal_unchecked(key) - } - fn get_literal_var( - self, - key: BoundedVec, - ) -> Option { - self.inner.get_literal_var(key) - } - fn get_literal_unchecked_var( - self, - key: BoundedVec, - ) -> crate::JSONLiteral { - self.inner.get_literal_unchecked_var(key) - } - fn get_literal_from_array(self, array_index: Field) -> Option { - self.inner.get_literal_from_array(array_index) - } - fn get_literal_from_array_unchecked(self, array_index: Field) -> crate::JSONLiteral { - self.inner.get_literal_from_array_unchecked(array_index) - } - fn get_number(self, key: [u8; KeyBytes]) -> Option { - self.inner.get_number(key) - } - fn get_number_unchecked(self, key: [u8; KeyBytes]) -> u64 { - self.inner.get_number_unchecked(key) - } - fn get_number_var(self, key: BoundedVec) -> Option { - self.inner.get_number_var(key) - } - fn get_number_unchecked_var(self, key: BoundedVec) -> u64 { - self.inner.get_number_unchecked_var(key) - } - fn get_number_from_array(self, array_index: Field) -> Option { - self.inner.get_number_from_array(array_index) - } - fn get_number_from_array_unchecked(self, array_index: Field) -> u64 { - self.inner.get_number_from_array_unchecked(array_index) - } - fn get_string( - self, - key: [u8; KeyBytes], - ) -> Option> { - self.inner.get_string(key) - } - fn get_string_unchecked( - self, - key: [u8; KeyBytes], - ) -> BoundedVec { - self.inner.get_string_unchecked(key) - } - fn get_string_var( - self, - key: BoundedVec, - ) -> Option> { - self.inner.get_string_var(key) - } - fn get_string_unchecked_var( - self, - key: BoundedVec, - ) -> BoundedVec { - self.inner.get_string_unchecked_var(key) - } - fn get_string_from_array( - self, - array_index: Field, - ) -> Option> { - self.inner.get_string_from_array(array_index) - } - fn get_string_from_array_unchecked( - self, - array_index: Field, - ) -> BoundedVec { - self.inner.get_string_from_array_unchecked(array_index) - } - fn get_string_from_path( - self, - keys: [BoundedVec; PathDepth], - ) -> Option> { - self.inner.get_string_from_path(keys) - } - fn get_value( - self, - key: [u8; KeyBytes], - ) -> Option> { - self.inner.get_value(key) - } - fn get_value_unchecked( - self, - key: [u8; KeyBytes], - ) -> crate::JSONValue { - self.inner.get_value_unchecked(key) - } - fn get_value_var( - self, - key: BoundedVec, - ) -> Option> { - self.inner.get_value_var(key) - } - fn get_value_unchecked_var( - self, - key: BoundedVec, - ) -> crate::JSONValue { - self.inner.get_value_unchecked_var(key) - } - fn get_value_from_array( - self, - array_index: Field, - ) -> Option> { - self.inner.get_value_from_array(array_index) - } - fn get_value_from_array_unchecked( - self, - array_index: Field, - ) -> crate::JSONValue { - self.inner.get_value_from_array_unchecked(array_index) - } - fn get_value_from_path( - self, - keys: [BoundedVec; PathDepth], - ) -> Option> { - self.inner.get_value_from_path(keys) - } - fn key_exists(self, key: BoundedVec) -> bool { - self.inner.key_exists(key) - } - fn get_keys_at_root( - self, - ) -> BoundedVec, MaxNumKeys> { - self.inner.get_keys_at_root() - } - } -} - -mod JSON4kb { - struct JSON { - inner: crate::json::JSON<4096, 136, 512, 257, 2>, - } - impl JSON { - fn convert(inner: Option>) -> Option { - Option { _is_some: inner._is_some, _value: JSON { inner: inner._value } } - } - } - impl crate::JSONParserTrait for JSON { - fn parse_json_from_string(s: str) -> Self { - JSON { inner: crate::json::JSON::parse_json_from_string(s) } - } - - fn parse_json(s: [u8; StringBytes]) -> Self { - JSON { inner: crate::json::JSON::parse_json(s) } - } - fn get_length(self) -> u32 { - self.inner.get_length() - } - fn get_array(self, key: [u8; KeyBytes]) -> Option { - JSON::convert(self.inner.get_array(key)) - } - fn get_array_unchecked(self, key: [u8; KeyBytes]) -> Self { - JSON { inner: self.inner.get_array_unchecked(key) } - } - fn get_array_var(self, key: BoundedVec) -> Option { - { - JSON::convert(self.inner.get_array_var(key)) - } - } - fn get_array_unchecked_var(self, key: BoundedVec) -> Self { - JSON { inner: self.inner.get_array_unchecked_var(key) } - } - fn get_array_from_array(self, array_index: Field) -> Option { - JSON::convert(self.inner.get_array_from_array(array_index)) - } - fn get_array_from_array_unchecked(self, array_index: Field) -> Self { - JSON { inner: self.inner.get_array_from_array_unchecked(array_index) } - } - fn map( - self, - f: fn(crate::JSONValue) -> U, - ) -> [U; MaxElements] - where - U: std::default::Default, - { - self.inner.map(f) - } - fn get_object(self, key: [u8; KeyBytes]) -> Option { - { - JSON::convert(self.inner.get_object(key)) - } - } - fn get_object_unchecked(self, key: [u8; KeyBytes]) -> Self { - JSON { inner: self.inner.get_object_unchecked(key) } - } - fn get_object_var(self, key: BoundedVec) -> Option { - { - JSON::convert(self.inner.get_object_var(key)) - } - } - fn get_object_unchecked_var( - self, - key: BoundedVec, - ) -> Self { - JSON { inner: self.inner.get_object_unchecked_var(key) } - } - fn get_object_from_array(self, array_index: Field) -> Option { - JSON::convert(self.inner.get_object_from_array(array_index)) - } - fn get_object_from_array_unchecked(self, array_index: Field) -> Self { - JSON { inner: self.inner.get_object_from_array_unchecked(array_index) } - } - fn get_literal(self, key: [u8; KeyBytes]) -> Option { - self.inner.get_literal(key) - } - fn get_literal_unchecked( - self, - key: [u8; KeyBytes], - ) -> crate::JSONLiteral { - self.inner.get_literal_unchecked(key) - } - fn get_literal_var( - self, - key: BoundedVec, - ) -> Option { - self.inner.get_literal_var(key) - } - fn get_literal_unchecked_var( - self, - key: BoundedVec, - ) -> crate::JSONLiteral { - self.inner.get_literal_unchecked_var(key) - } - fn get_literal_from_array(self, array_index: Field) -> Option { - self.inner.get_literal_from_array(array_index) - } - fn get_literal_from_array_unchecked(self, array_index: Field) -> crate::JSONLiteral { - self.inner.get_literal_from_array_unchecked(array_index) - } - fn get_number(self, key: [u8; KeyBytes]) -> Option { - self.inner.get_number(key) - } - fn get_number_unchecked(self, key: [u8; KeyBytes]) -> u64 { - self.inner.get_number_unchecked(key) - } - fn get_number_var(self, key: BoundedVec) -> Option { - self.inner.get_number_var(key) - } - fn get_number_unchecked_var(self, key: BoundedVec) -> u64 { - self.inner.get_number_unchecked_var(key) - } - fn get_number_from_array(self, array_index: Field) -> Option { - self.inner.get_number_from_array(array_index) - } - fn get_number_from_array_unchecked(self, array_index: Field) -> u64 { - self.inner.get_number_from_array_unchecked(array_index) - } - fn get_string( - self, - key: [u8; KeyBytes], - ) -> Option> { - self.inner.get_string(key) - } - fn get_string_unchecked( - self, - key: [u8; KeyBytes], - ) -> BoundedVec { - self.inner.get_string_unchecked(key) - } - fn get_string_var( - self, - key: BoundedVec, - ) -> Option> { - self.inner.get_string_var(key) - } - fn get_string_unchecked_var( - self, - key: BoundedVec, - ) -> BoundedVec { - self.inner.get_string_unchecked_var(key) - } - fn get_string_from_array( - self, - array_index: Field, - ) -> Option> { - self.inner.get_string_from_array(array_index) - } - fn get_string_from_array_unchecked( - self, - array_index: Field, - ) -> BoundedVec { - self.inner.get_string_from_array_unchecked(array_index) - } - fn get_string_from_path( - self, - keys: [BoundedVec; PathDepth], - ) -> Option> { - self.inner.get_string_from_path(keys) - } - fn get_value( - self, - key: [u8; KeyBytes], - ) -> Option> { - self.inner.get_value(key) - } - fn get_value_unchecked( - self, - key: [u8; KeyBytes], - ) -> crate::JSONValue { - self.inner.get_value_unchecked(key) - } - fn get_value_var( - self, - key: BoundedVec, - ) -> Option> { - self.inner.get_value_var(key) - } - fn get_value_unchecked_var( - self, - key: BoundedVec, - ) -> crate::JSONValue { - self.inner.get_value_unchecked_var(key) - } - fn get_value_from_array( - self, - array_index: Field, - ) -> Option> { - self.inner.get_value_from_array(array_index) - } - fn get_value_from_array_unchecked( - self, - array_index: Field, - ) -> crate::JSONValue { - self.inner.get_value_from_array_unchecked(array_index) - } - fn get_value_from_path( - self, - keys: [BoundedVec; PathDepth], - ) -> Option> { - self.inner.get_value_from_path(keys) - } - fn key_exists(self, key: BoundedVec) -> bool { - self.inner.key_exists(key) - } - fn get_keys_at_root( - self, - ) -> BoundedVec, MaxNumKeys> { - self.inner.get_keys_at_root() - } - } -} - -mod JSON8kb { - struct JSON { - inner: crate::json::JSON<8192, 268, 1024, 513, 2>, - } - impl JSON { - fn convert(inner: Option>) -> Option { - Option { _is_some: inner._is_some, _value: JSON { inner: inner._value } } - } - } - impl crate::JSONParserTrait for JSON { - fn parse_json_from_string(s: str) -> Self { - JSON { inner: crate::json::JSON::parse_json_from_string(s) } - } - - fn parse_json(s: [u8; StringBytes]) -> Self { - JSON { inner: crate::json::JSON::parse_json(s) } - } - fn get_length(self) -> u32 { - self.inner.get_length() - } - fn get_array(self, key: [u8; KeyBytes]) -> Option { - JSON::convert(self.inner.get_array(key)) - } - fn get_array_unchecked(self, key: [u8; KeyBytes]) -> Self { - JSON { inner: self.inner.get_array_unchecked(key) } - } - fn get_array_var(self, key: BoundedVec) -> Option { - { - JSON::convert(self.inner.get_array_var(key)) - } - } - fn get_array_unchecked_var(self, key: BoundedVec) -> Self { - JSON { inner: self.inner.get_array_unchecked_var(key) } - } - fn get_array_from_array(self, array_index: Field) -> Option { - JSON::convert(self.inner.get_array_from_array(array_index)) - } - fn get_array_from_array_unchecked(self, array_index: Field) -> Self { - JSON { inner: self.inner.get_array_from_array_unchecked(array_index) } - } - fn map( - self, - f: fn(crate::JSONValue) -> U, - ) -> [U; MaxElements] - where - U: std::default::Default, - { - self.inner.map(f) - } - fn get_object(self, key: [u8; KeyBytes]) -> Option { - { - JSON::convert(self.inner.get_object(key)) - } - } - fn get_object_unchecked(self, key: [u8; KeyBytes]) -> Self { - JSON { inner: self.inner.get_object_unchecked(key) } - } - fn get_object_var(self, key: BoundedVec) -> Option { - { - JSON::convert(self.inner.get_object_var(key)) - } - } - fn get_object_unchecked_var( - self, - key: BoundedVec, - ) -> Self { - JSON { inner: self.inner.get_object_unchecked_var(key) } - } - fn get_object_from_array(self, array_index: Field) -> Option { - JSON::convert(self.inner.get_object_from_array(array_index)) - } - fn get_object_from_array_unchecked(self, array_index: Field) -> Self { - JSON { inner: self.inner.get_object_from_array_unchecked(array_index) } - } - fn get_literal(self, key: [u8; KeyBytes]) -> Option { - self.inner.get_literal(key) - } - fn get_literal_unchecked( - self, - key: [u8; KeyBytes], - ) -> crate::JSONLiteral { - self.inner.get_literal_unchecked(key) - } - fn get_literal_var( - self, - key: BoundedVec, - ) -> Option { - self.inner.get_literal_var(key) - } - fn get_literal_unchecked_var( - self, - key: BoundedVec, - ) -> crate::JSONLiteral { - self.inner.get_literal_unchecked_var(key) - } - fn get_literal_from_array(self, array_index: Field) -> Option { - self.inner.get_literal_from_array(array_index) - } - fn get_literal_from_array_unchecked(self, array_index: Field) -> crate::JSONLiteral { - self.inner.get_literal_from_array_unchecked(array_index) - } - fn get_number(self, key: [u8; KeyBytes]) -> Option { - self.inner.get_number(key) - } - fn get_number_unchecked(self, key: [u8; KeyBytes]) -> u64 { - self.inner.get_number_unchecked(key) - } - fn get_number_var(self, key: BoundedVec) -> Option { - self.inner.get_number_var(key) - } - fn get_number_unchecked_var(self, key: BoundedVec) -> u64 { - self.inner.get_number_unchecked_var(key) - } - fn get_number_from_array(self, array_index: Field) -> Option { - self.inner.get_number_from_array(array_index) - } - fn get_number_from_array_unchecked(self, array_index: Field) -> u64 { - self.inner.get_number_from_array_unchecked(array_index) - } - fn get_string( - self, - key: [u8; KeyBytes], - ) -> Option> { - self.inner.get_string(key) - } - fn get_string_unchecked( - self, - key: [u8; KeyBytes], - ) -> BoundedVec { - self.inner.get_string_unchecked(key) - } - fn get_string_var( - self, - key: BoundedVec, - ) -> Option> { - self.inner.get_string_var(key) - } - fn get_string_unchecked_var( - self, - key: BoundedVec, - ) -> BoundedVec { - self.inner.get_string_unchecked_var(key) - } - fn get_string_from_array( - self, - array_index: Field, - ) -> Option> { - self.inner.get_string_from_array(array_index) - } - fn get_string_from_array_unchecked( - self, - array_index: Field, - ) -> BoundedVec { - self.inner.get_string_from_array_unchecked(array_index) - } - fn get_string_from_path( - self, - keys: [BoundedVec; PathDepth], - ) -> Option> { - self.inner.get_string_from_path(keys) - } - fn get_value( - self, - key: [u8; KeyBytes], - ) -> Option> { - self.inner.get_value(key) - } - fn get_value_unchecked( - self, - key: [u8; KeyBytes], - ) -> crate::JSONValue { - self.inner.get_value_unchecked(key) - } - fn get_value_var( - self, - key: BoundedVec, - ) -> Option> { - self.inner.get_value_var(key) - } - fn get_value_unchecked_var( - self, - key: BoundedVec, - ) -> crate::JSONValue { - self.inner.get_value_unchecked_var(key) - } - fn get_value_from_array( - self, - array_index: Field, - ) -> Option> { - self.inner.get_value_from_array(array_index) - } - fn get_value_from_array_unchecked( - self, - array_index: Field, - ) -> crate::JSONValue { - self.inner.get_value_from_array_unchecked(array_index) - } - fn get_value_from_path( - self, - keys: [BoundedVec; PathDepth], - ) -> Option> { - self.inner.get_value_from_path(keys) - } - fn key_exists(self, key: BoundedVec) -> bool { - self.inner.key_exists(key) - } - fn get_keys_at_root( - self, - ) -> BoundedVec, MaxNumKeys> { - self.inner.get_keys_at_root() - } - } -} - -mod JSON16kb { - struct JSON { - inner: crate::json::JSON<16384, 532, 2048, 1025, 2>, - } - impl JSON { - fn convert(inner: Option>) -> Option { - Option { _is_some: inner._is_some, _value: JSON { inner: inner._value } } - } - } - impl crate::JSONParserTrait for JSON { - fn parse_json_from_string(s: str) -> Self { - JSON { inner: crate::json::JSON::parse_json_from_string(s) } - } - - fn parse_json(s: [u8; StringBytes]) -> Self { - JSON { inner: crate::json::JSON::parse_json(s) } - } - fn get_length(self) -> u32 { - self.inner.get_length() - } - fn get_array(self, key: [u8; KeyBytes]) -> Option { - JSON::convert(self.inner.get_array(key)) - } - fn get_array_unchecked(self, key: [u8; KeyBytes]) -> Self { - JSON { inner: self.inner.get_array_unchecked(key) } - } - fn get_array_var(self, key: BoundedVec) -> Option { - { - JSON::convert(self.inner.get_array_var(key)) - } - } - fn get_array_unchecked_var(self, key: BoundedVec) -> Self { - JSON { inner: self.inner.get_array_unchecked_var(key) } - } - fn get_array_from_array(self, array_index: Field) -> Option { - JSON::convert(self.inner.get_array_from_array(array_index)) - } - fn get_array_from_array_unchecked(self, array_index: Field) -> Self { - JSON { inner: self.inner.get_array_from_array_unchecked(array_index) } - } - fn map( - self, - f: fn(crate::JSONValue) -> U, - ) -> [U; MaxElements] - where - U: std::default::Default, - { - self.inner.map(f) - } - fn get_object(self, key: [u8; KeyBytes]) -> Option { - { - JSON::convert(self.inner.get_object(key)) - } - } - fn get_object_unchecked(self, key: [u8; KeyBytes]) -> Self { - JSON { inner: self.inner.get_object_unchecked(key) } - } - fn get_object_var(self, key: BoundedVec) -> Option { - { - JSON::convert(self.inner.get_object_var(key)) - } - } - fn get_object_unchecked_var( - self, - key: BoundedVec, - ) -> Self { - JSON { inner: self.inner.get_object_unchecked_var(key) } - } - fn get_object_from_array(self, array_index: Field) -> Option { - JSON::convert(self.inner.get_object_from_array(array_index)) - } - fn get_object_from_array_unchecked(self, array_index: Field) -> Self { - JSON { inner: self.inner.get_object_from_array_unchecked(array_index) } - } - fn get_literal(self, key: [u8; KeyBytes]) -> Option { - self.inner.get_literal(key) - } - fn get_literal_unchecked( - self, - key: [u8; KeyBytes], - ) -> crate::JSONLiteral { - self.inner.get_literal_unchecked(key) - } - fn get_literal_var( - self, - key: BoundedVec, - ) -> Option { - self.inner.get_literal_var(key) - } - fn get_literal_unchecked_var( - self, - key: BoundedVec, - ) -> crate::JSONLiteral { - self.inner.get_literal_unchecked_var(key) - } - fn get_literal_from_array(self, array_index: Field) -> Option { - self.inner.get_literal_from_array(array_index) - } - fn get_literal_from_array_unchecked(self, array_index: Field) -> crate::JSONLiteral { - self.inner.get_literal_from_array_unchecked(array_index) - } - fn get_number(self, key: [u8; KeyBytes]) -> Option { - self.inner.get_number(key) - } - fn get_number_unchecked(self, key: [u8; KeyBytes]) -> u64 { - self.inner.get_number_unchecked(key) - } - fn get_number_var(self, key: BoundedVec) -> Option { - self.inner.get_number_var(key) - } - fn get_number_unchecked_var(self, key: BoundedVec) -> u64 { - self.inner.get_number_unchecked_var(key) - } - fn get_number_from_array(self, array_index: Field) -> Option { - self.inner.get_number_from_array(array_index) - } - fn get_number_from_array_unchecked(self, array_index: Field) -> u64 { - self.inner.get_number_from_array_unchecked(array_index) - } - fn get_string( - self, - key: [u8; KeyBytes], - ) -> Option> { - self.inner.get_string(key) - } - fn get_string_unchecked( - self, - key: [u8; KeyBytes], - ) -> BoundedVec { - self.inner.get_string_unchecked(key) - } - fn get_string_var( - self, - key: BoundedVec, - ) -> Option> { - self.inner.get_string_var(key) - } - fn get_string_unchecked_var( - self, - key: BoundedVec, - ) -> BoundedVec { - self.inner.get_string_unchecked_var(key) - } - fn get_string_from_array( - self, - array_index: Field, - ) -> Option> { - self.inner.get_string_from_array(array_index) - } - fn get_string_from_array_unchecked( - self, - array_index: Field, - ) -> BoundedVec { - self.inner.get_string_from_array_unchecked(array_index) - } - fn get_string_from_path( - self, - keys: [BoundedVec; PathDepth], - ) -> Option> { - self.inner.get_string_from_path(keys) - } - fn get_value( - self, - key: [u8; KeyBytes], - ) -> Option> { - self.inner.get_value(key) - } - fn get_value_unchecked( - self, - key: [u8; KeyBytes], - ) -> crate::JSONValue { - self.inner.get_value_unchecked(key) - } - fn get_value_var( - self, - key: BoundedVec, - ) -> Option> { - self.inner.get_value_var(key) - } - fn get_value_unchecked_var( - self, - key: BoundedVec, - ) -> crate::JSONValue { - self.inner.get_value_unchecked_var(key) - } - fn get_value_from_array( - self, - array_index: Field, - ) -> Option> { - self.inner.get_value_from_array(array_index) - } - fn get_value_from_array_unchecked( - self, - array_index: Field, - ) -> crate::JSONValue { - self.inner.get_value_from_array_unchecked(array_index) - } - fn get_value_from_path( - self, - keys: [BoundedVec; PathDepth], - ) -> Option> { - self.inner.get_value_from_path(keys) - } - fn key_exists(self, key: BoundedVec) -> bool { - self.inner.key_exists(key) - } - fn get_keys_at_root( - self, - ) -> BoundedVec, MaxNumKeys> { - self.inner.get_keys_at_root() - } - } -} +pub type JSON512b = JSON<512, 20, 64, 33, 2>; +pub type JSON1kb = JSON<1024, 37, 128, 65, 2>; +pub type JSON2kb = JSON<2048, 70, 256, 129, 2>; +pub type JSON4kb = JSON<4096, 136, 512, 257, 2>; +pub type JSON8kb = JSON<8192, 268, 1024, 513, 2>; +pub type JSON16kb = JSON<16384, 532, 2048, 1025, 2>;