diff --git a/Cargo.lock b/Cargo.lock index b5a603b..4dde742 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -27,6 +27,8 @@ dependencies = [ "log", "pyo3 0.20.0", "pyo3-log", + "serde", + "serde_json", "sha1", ] @@ -207,6 +209,12 @@ dependencies = [ "cfg-if", ] +[[package]] +name = "itoa" +version = "1.0.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b1a46d1a171d865aa5f83f92695765caa047a9b4cbae2cbf37dbd613a793fd4c" + [[package]] name = "libc" version = "0.2.151" @@ -318,9 +326,9 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.66" +version = "1.0.78" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "18fb31db3f9bddb2ea821cde30a9f70117e3f119938b5ee630b7403aa6e2ead9" +checksum = "e2422ad645d89c99f8f3e6b88a9fdeca7fabeac836b1002371c4367c8f984aae" dependencies = [ "unicode-ident", ] @@ -421,9 +429,9 @@ dependencies = [ [[package]] name = "quote" -version = "1.0.33" +version = "1.0.35" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5267fca4496028628a95160fc423a33e8b2e6af8a5302579e322e4b520293cae" +checksum = "291ec9ab5efd934aaf503a6466c5d5251535d108ee747472c3977cc5acc868ef" dependencies = [ "proc-macro2", ] @@ -452,12 +460,49 @@ version = "0.1.23" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d626bb9dae77e28219937af045c257c28bfd3f69333c512553507f5f9798cb76" +[[package]] +name = "ryu" +version = "1.0.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f98d2aa92eebf49b69786be48e4477826b256916e84a57ff2a4f21923b48eb4c" + [[package]] name = "scopeguard" version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" +[[package]] +name = "serde" +version = "1.0.195" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "63261df402c67811e9ac6def069e4786148c4563f4b50fd4bf30aa370d626b02" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.195" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "46fe8f8603d81ba86327b23a2e9cdf49e1255fb94a4c5f297f6ee0547178ea2c" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "serde_json" +version = "1.0.111" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "176e46fa42316f18edd598015a5166857fc835ec732f5215eac6b7bdbf0a84f4" +dependencies = [ + "itoa", + "ryu", + "serde", +] + [[package]] name = "sha1" version = "0.10.6" @@ -477,9 +522,9 @@ checksum = "62bb4feee49fdd9f707ef802e22365a35de4b7b299de4763d44bfea899442ff9" [[package]] name = "syn" -version = "2.0.29" +version = "2.0.48" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c324c494eba9d92503e6f1ef2e6df781e78f6a7705a0202d9801b198807d518a" +checksum = "0f3531638e407dfc0814761abb7c00a5b54992b849452a0646b7f65c9f770f3f" dependencies = [ "proc-macro2", "quote", diff --git a/androscalpel/Cargo.toml b/androscalpel/Cargo.toml index 1cc2e8a..6393e70 100644 --- a/androscalpel/Cargo.toml +++ b/androscalpel/Cargo.toml @@ -15,4 +15,6 @@ anyhow = { version = "1.0.75", features = ["backtrace"] } log = "0.4.20" pyo3 = { version = "0.20.0", features = ["anyhow"] } pyo3-log = "0.8.3" +serde = { version = "1.0.195", features = ["derive"] } +serde_json = "1.0.111" sha1 = "0.10.6" diff --git a/androscalpel/src/annotation.rs b/androscalpel/src/annotation.rs index 816c3df..e48419f 100644 --- a/androscalpel/src/annotation.rs +++ b/androscalpel/src/annotation.rs @@ -1,15 +1,18 @@ //! Annotations (for class, fields, methods and parameters alike). +use serde::{Deserialize, Serialize}; use std::collections::{HashMap, HashSet}; use pyo3::prelude::*; +use crate::hashmap_vectorize; use crate::{ dex_id::IdType, value::DexValue, DexString, IdField, IdMethod, IdMethodType, MethodHandle, + Result, }; /// Annotation with a visibility #[pyclass] -#[derive(Debug, Clone)] +#[derive(Debug, Clone, PartialEq, Deserialize, Serialize)] pub struct DexAnnotationItem { // TODO: the get/set will probably be wonky on the python side when edditing /// The actual annotation @@ -93,11 +96,20 @@ impl DexAnnotationItem { pub fn get_all_method_handles(&self) -> HashSet { self.annotation.get_all_method_handles() } + + pub fn to_json(&self) -> Result { + Ok(serde_json::to_string(self)?) + } + + #[staticmethod] + pub fn from_json(json: &str) -> Result { + Ok(serde_json::from_str(json)?) + } } /// An annotation. #[pyclass] -#[derive(Debug, Clone)] +#[derive(Debug, Clone, PartialEq, Deserialize, Serialize)] pub struct DexAnnotation { // TODO: check the relation between type and encoded_value. /// The type of the annotation. @@ -106,6 +118,7 @@ pub struct DexAnnotation { // TODO: the get/set will probably be wonky on the python side when edditing /// The annotation elements. #[pyo3(get)] + #[serde(with = "hashmap_vectorize")] pub elements: HashMap, // TODO: check MemberName syntax? } @@ -186,4 +199,13 @@ impl DexAnnotation { } methods } + + pub fn to_json(&self) -> Result { + Ok(serde_json::to_string(self)?) + } + + #[staticmethod] + pub fn from_json(json: &str) -> Result { + Ok(serde_json::from_str(json)?) + } } diff --git a/androscalpel/src/apk.rs b/androscalpel/src/apk.rs index 41581b9..28f1769 100644 --- a/androscalpel/src/apk.rs +++ b/androscalpel/src/apk.rs @@ -1,23 +1,27 @@ //! Representation of an apk. -use anyhow::{anyhow, bail, Context, Result}; +use anyhow::{anyhow, bail, Context}; +use serde::{Deserialize, Serialize}; use std::collections::HashMap; use log::info; use pyo3::prelude::*; use pyo3::types::PyBytes; +use crate::hashmap_vectorize; use crate::ins::CallSite; use crate::instructions; +use crate::Result; use crate::*; use androscalpel_serializer::Instruction as InsFormat; use androscalpel_serializer::*; /// Represent an apk. #[pyclass] -#[derive(Debug, Clone)] +#[derive(Debug, Clone, Deserialize, Serialize, PartialEq)] pub struct Apk { #[pyo3(get)] + #[serde(with = "hashmap_vectorize")] pub classes: HashMap, } @@ -2368,4 +2372,13 @@ impl Apk { .map(|bytes| PyBytes::new(py, &bytes).into()) .collect()) } + + pub fn to_json(&self) -> Result { + Ok(serde_json::to_string(self)?) + } + + #[staticmethod] + pub fn from_json(json: &str) -> Result { + Ok(serde_json::from_str(json)?) + } } diff --git a/androscalpel/src/class.rs b/androscalpel/src/class.rs index df90a33..eff1df7 100644 --- a/androscalpel/src/class.rs +++ b/androscalpel/src/class.rs @@ -1,9 +1,11 @@ //! Representation of a class. +use serde::{Deserialize, Serialize}; use std::collections::{HashMap, HashSet}; use pyo3::prelude::*; +use crate::hashmap_vectorize; use crate::{ DexAnnotationItem, DexString, Field, IdField, IdMethod, IdMethodType, IdType, Method, MethodHandle, Result, @@ -12,7 +14,7 @@ use androscalpel_serializer::consts::*; /// Represent an apk #[pyclass] -#[derive(Debug, Clone)] +#[derive(Debug, Clone, Deserialize, Serialize, PartialEq)] pub struct Class { /// Type, format described at /// @@ -54,15 +56,19 @@ pub struct Class { /// The static fields #[pyo3(get)] + #[serde(with = "hashmap_vectorize")] pub static_fields: HashMap, /// The instance fields #[pyo3(get)] + #[serde(with = "hashmap_vectorize")] pub instance_fields: HashMap, /// The direct (static, private or constructor) methods of the class #[pyo3(get)] + #[serde(with = "hashmap_vectorize")] pub direct_methods: HashMap, /// The virtual (ie non direct) methods of the class #[pyo3(get)] + #[serde(with = "hashmap_vectorize")] pub virtual_methods: HashMap, // Do we need to distinguish direct and virtual (all the other) methods? // Maybe overlapping descriptor (same name, class and proto?) @@ -75,6 +81,15 @@ pub struct Class { #[pymethods] impl Class { + pub fn to_json(&self) -> Result { + Ok(serde_json::to_string(self)?) + } + + #[staticmethod] + pub fn from_json(json: &str) -> Result { + Ok(serde_json::from_str(json)?) + } + #[new] pub fn new(name: DexString) -> Result { Ok(Self { diff --git a/androscalpel/src/code.rs b/androscalpel/src/code.rs index 6c3f9da..be25b69 100644 --- a/androscalpel/src/code.rs +++ b/androscalpel/src/code.rs @@ -1,10 +1,13 @@ //! Representation of a method. +use serde::{Deserialize, Serialize}; use std::collections::HashSet; use pyo3::prelude::*; -use crate::{ins::Instruction, DexString, IdField, IdMethod, IdMethodType, IdType, MethodHandle}; +use crate::{ + ins::Instruction, DexString, IdField, IdMethod, IdMethodType, IdType, MethodHandle, Result, +}; // TODO: make this easy to edit/manipulate, maybe move to Method @@ -12,7 +15,7 @@ use crate::{ins::Instruction, DexString, IdField, IdMethod, IdMethodType, IdType /// The code run by a method. #[pyclass] -#[derive(Debug, Clone)] +#[derive(Debug, Clone, Deserialize, Serialize, PartialEq)] pub struct Code { // TODO: remove and compute this value from code? /// The number of registers used by the code @@ -37,6 +40,15 @@ pub struct Code { #[pymethods] impl Code { + pub fn to_json(&self) -> Result { + Ok(serde_json::to_string(self)?) + } + + #[staticmethod] + pub fn from_json(json: &str) -> Result { + Ok(serde_json::from_str(json)?) + } + #[new] pub fn new( registers_size: u16, diff --git a/androscalpel/src/dex_id.rs b/androscalpel/src/dex_id.rs index a35a9b4..29ffdc9 100644 --- a/androscalpel/src/dex_id.rs +++ b/androscalpel/src/dex_id.rs @@ -1,5 +1,6 @@ //! The class identifying dex structure. +use serde::{Deserialize, Serialize}; use std::cmp::{Ord, Ordering, PartialOrd}; use std::collections::hash_map::DefaultHasher; use std::collections::HashSet; @@ -11,8 +12,10 @@ use pyo3::prelude::*; use crate::{scalar::*, DexString, DexValue, Result}; use androscalpel_serializer::{StringDataItem, Uleb128}; +/// The type of a method. The shorty is formated as described in +/// #[pyclass] -#[derive(Debug, Clone, PartialEq, Eq, Hash)] +#[derive(Debug, Clone, PartialEq, Eq, Hash, Deserialize, Serialize)] pub struct IdMethodType { /// Type formated as described by pub(crate) shorty: DexString, // Redondant, but same as in the encoding, keep it in case we ever @@ -37,9 +40,16 @@ impl PartialOrd for IdMethodType { } #[pymethods] -/// The type of a method. The shorty is formated as described in -/// impl IdMethodType { + pub fn to_json(&self) -> Result { + Ok(serde_json::to_string(self)?) + } + + #[staticmethod] + pub fn from_json(json: &str) -> Result { + Ok(serde_json::from_str(json)?) + } + #[new] pub fn new(return_type: IdType, parameters: Vec) -> Self { Self { @@ -62,7 +72,15 @@ impl IdMethodType { } pub fn __repr__(&self) -> String { - format!("DexMethodType({})", self.__str__()) + format!( + "IdMethodType({}, [{}])", + self.return_type.__repr__(), + self.parameters + .iter() + .map(|param| param.__repr__()) + .collect::>() + .join(", ") + ) } pub fn get_shorty(&self) -> DexString { @@ -133,10 +151,19 @@ impl IdMethodType { // Not a clean rust enum because we want to be compatible with python, and maybe support strange // malware edge case? #[pyclass] -#[derive(Debug, Clone, PartialEq, Eq, Hash, PartialOrd, Ord)] +#[derive(Debug, Clone, PartialEq, Eq, Hash, PartialOrd, Ord, Deserialize, Serialize)] pub struct IdType(pub(crate) DexString); #[pymethods] impl IdType { + pub fn to_json(&self) -> Result { + Ok(serde_json::to_string(self)?) + } + + #[staticmethod] + pub fn from_json(json: &str) -> Result { + Ok(serde_json::from_str(json)?) + } + #[new] pub fn new( #[pyo3(from_py_with = "crate::dex_string::as_dex_string")] ty: DexString, @@ -231,7 +258,7 @@ impl IdType { pub fn __repr__(&self) -> String { let name: String = (&self.0).into(); - format!("IdType({name})") + format!("IdType(\"{name}\")") } /// Check if the type is void (return type) @@ -426,7 +453,7 @@ impl IdType { } #[pyclass] -#[derive(Debug, Clone, PartialEq, Eq, Hash)] +#[derive(Debug, Clone, PartialEq, Eq, Hash, Deserialize, Serialize)] pub struct IdField { /// The name of the field, format described at /// @@ -442,6 +469,15 @@ pub struct IdField { #[pymethods] impl IdField { + pub fn to_json(&self) -> Result { + Ok(serde_json::to_string(self)?) + } + + #[staticmethod] + pub fn from_json(json: &str) -> Result { + Ok(serde_json::from_str(json)?) + } + #[new] pub fn new( #[pyo3(from_py_with = "crate::dex_string::as_dex_string")] name: DexString, @@ -467,7 +503,7 @@ impl IdField { let class: String = self.class_.__repr__(); let name: String = (&self.name).into(); let ty: String = self.type_.__repr__(); - format!("IdField(({ty}){class}.{name})") + format!("IdField(\"{name}\", {ty}, {class})") } pub fn __eq__(&self, other: &Self) -> bool { @@ -522,7 +558,7 @@ impl PartialOrd for IdField { /// The Id of a method. #[pyclass] -#[derive(Debug, Clone, PartialEq, Eq, Hash)] +#[derive(Debug, Clone, PartialEq, Eq, Hash, Deserialize, Serialize)] pub struct IdMethod { /// The class containing the method. #[pyo3(get)] @@ -537,6 +573,15 @@ pub struct IdMethod { #[pymethods] impl IdMethod { + pub fn to_json(&self) -> Result { + Ok(serde_json::to_string(self)?) + } + + #[staticmethod] + pub fn from_json(json: &str) -> Result { + Ok(serde_json::from_str(json)?) + } + #[new] pub fn new( #[pyo3(from_py_with = "crate::dex_string::as_dex_string")] name: DexString, @@ -566,7 +611,12 @@ impl IdMethod { } pub fn __repr__(&self) -> String { - format!("DexMethod({})", self.__str__()) + format!( + "IdMethod(\"{}\", {}, {})", + self.name.__str__(), + self.proto.__repr__(), + self.class_.__repr__() + ) } pub fn __eq__(&self, other: &Self) -> bool { @@ -627,10 +677,19 @@ impl PartialOrd for IdMethod { } #[pyclass] -#[derive(Debug, Clone, PartialEq, Eq)] +#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize)] pub struct IdEnum(pub IdField); #[pymethods] impl IdEnum { + pub fn to_json(&self) -> Result { + Ok(serde_json::to_string(self)?) + } + + #[staticmethod] + pub fn from_json(json: &str) -> Result { + Ok(serde_json::from_str(json)?) + } + #[new] pub fn new(val: IdField) -> Self { Self(val) @@ -645,7 +704,7 @@ impl IdEnum { } pub fn __repr__(&self) -> String { - format!("DexEnum({})", self.__str__()) + format!("DexEnum({})", self.0.__repr__()) } /// Return all strings referenced in the Id. diff --git a/androscalpel/src/dex_string.rs b/androscalpel/src/dex_string.rs index 0980896..adf3cf8 100644 --- a/androscalpel/src/dex_string.rs +++ b/androscalpel/src/dex_string.rs @@ -1,3 +1,5 @@ +use crate::Result; +use serde::{Deserialize, Deserializer, Serialize, Serializer}; use std::cmp::{Ord, PartialOrd}; use std::collections::hash_map::DefaultHasher; use std::collections::HashSet; @@ -11,6 +13,59 @@ use pyo3::prelude::*; #[derive(Clone, PartialEq, Eq, Debug, Ord, PartialOrd)] pub struct DexString(pub androscalpel_serializer::StringDataItem); +impl Serialize for DexString { + fn serialize(&self, serializer: S) -> Result + where + S: Serializer, + { + Serialize::serialize(&SerdeDexString::from(self), serializer) + } +} + +impl<'de> Deserialize<'de> for DexString { + fn deserialize(deserializer: D) -> Result + where + D: Deserializer<'de>, + { + ::deserialize(deserializer).map(|string| (&string).into()) + } +} + +#[derive(Serialize, Deserialize)] +#[serde(rename = "DexString")] +enum SerdeDexString { + String(String), + BinString(Vec, u32), +} + +impl From<&DexString> for SerdeDexString { + fn from(DexString(string): &DexString) -> Self { + if let Ok(string) = string.try_into() { + SerdeDexString::String(string) + } else { + let androscalpel_serializer::StringDataItem { + data, + utf16_size: androscalpel_serializer::Uleb128(len), + } = string; + SerdeDexString::BinString(data.to_vec(), *len) + } + } +} + +impl From<&SerdeDexString> for DexString { + fn from(string: &SerdeDexString) -> Self { + match string { + SerdeDexString::String(string) => string.as_str().into(), + SerdeDexString::BinString(data, len) => { + DexString(androscalpel_serializer::StringDataItem { + data: data.clone(), + utf16_size: androscalpel_serializer::Uleb128(*len), + }) + } + } + } +} + impl From for androscalpel_serializer::StringDataItem { fn from(DexString(string): DexString) -> Self { string @@ -71,6 +126,15 @@ pub fn as_dex_string(obj: &PyAny) -> PyResult { #[pymethods] impl DexString { + pub fn to_json(&self) -> Result { + Ok(serde_json::to_string(self)?) + } + + #[staticmethod] + pub fn from_json(json: &str) -> Result { + Ok(serde_json::from_str(json)?) + } + #[new] pub fn new(s: &str) -> Self { s.into() diff --git a/androscalpel/src/dex_writer.rs b/androscalpel/src/dex_writer.rs index c8e7581..0d2fb3b 100644 --- a/androscalpel/src/dex_writer.rs +++ b/androscalpel/src/dex_writer.rs @@ -2625,7 +2625,7 @@ impl DexWriter { /// given section. fn fix_section_alignement(buffer: &mut Cursor>, section: Section) -> Result<()> { while buffer.position() % section.get_item_alignment() as u64 != 0 { - 0u8.serialize(buffer)?; + Serializable::serialize(&0u8, buffer)?; } Ok(()) } diff --git a/androscalpel/src/field.rs b/androscalpel/src/field.rs index 2e97fff..df19d3d 100644 --- a/androscalpel/src/field.rs +++ b/androscalpel/src/field.rs @@ -1,17 +1,19 @@ //! Representation of the fields of a class. +use serde::{Deserialize, Serialize}; use std::collections::HashSet; use pyo3::prelude::*; use crate::{ DexAnnotationItem, DexString, DexValue, IdField, IdMethod, IdMethodType, IdType, MethodHandle, + Result, }; use androscalpel_serializer::consts::*; /// Represent a field. #[pyclass] -#[derive(Debug, Clone)] +#[derive(Debug, Clone, PartialEq, Deserialize, Serialize)] pub struct Field { /// The structure used to reference this field. #[pyo3(get)] @@ -46,7 +48,7 @@ pub struct Field { /// Represent the visibility of a field #[pyclass] -#[derive(Debug, Clone, Copy, PartialEq, Eq)] +#[derive(Debug, Clone, Copy, PartialEq, Eq, Deserialize, Serialize)] pub enum FieldVisibility { Public, Private, @@ -56,6 +58,15 @@ pub enum FieldVisibility { #[pymethods] impl Field { + pub fn to_json(&self) -> Result { + Ok(serde_json::to_string(self)?) + } + + #[staticmethod] + pub fn from_json(json: &str) -> Result { + Ok(serde_json::from_str(json)?) + } + #[new] pub fn new(descriptor: IdField) -> Self { Self { diff --git a/androscalpel/src/hashmap_vectorize.rs b/androscalpel/src/hashmap_vectorize.rs new file mode 100644 index 0000000..a2666ab --- /dev/null +++ b/androscalpel/src/hashmap_vectorize.rs @@ -0,0 +1,23 @@ +use serde::{Deserialize, Deserializer, Serialize, Serializer}; +use std::iter::FromIterator; +pub fn serialize<'a, T, K, V, S>(target: T, ser: S) -> Result +where + S: Serializer, + T: IntoIterator, + K: Serialize + 'a, + V: Serialize + 'a, +{ + let container: Vec<_> = target.into_iter().collect(); + serde::Serialize::serialize(&container, ser) +} + +pub fn deserialize<'de, T, K, V, D>(des: D) -> Result +where + D: Deserializer<'de>, + T: FromIterator<(K, V)>, + K: Deserialize<'de>, + V: Deserialize<'de>, +{ + let container: Vec<_> = serde::Deserialize::deserialize(des)?; + Ok(T::from_iter(container.into_iter())) +} diff --git a/androscalpel/src/instructions.rs b/androscalpel/src/instructions.rs index 7f6150d..d3888f6 100644 --- a/androscalpel/src/instructions.rs +++ b/androscalpel/src/instructions.rs @@ -3,6 +3,9 @@ //! Instruction at a sligthly higher level than //! +use serde::{Deserialize, Serialize}; + +use crate::hashmap_vectorize; use crate::{DexString, DexValue, IdField, IdMethod, IdMethodType, IdType, MethodHandle, Result}; use androscalpel_serializer::Instruction as InsFormat; use androscalpel_serializer::Serializable; @@ -26,7 +29,7 @@ const I32_MAX_AS_I64: i64 = i32::MAX as i64; const U16_MAX_AS_USIZE: usize = u16::MAX as usize; // TODO: impl PartialEq and Eq for call site to derive them here -#[derive(Debug, Clone)] +#[derive(Debug, Clone, PartialEq, Deserialize, Serialize)] pub enum Instruction { Nop(Nop), Move(Move), @@ -3461,7 +3464,7 @@ impl IntoPy for Instruction { } #[pyclass] -#[derive(Debug, Clone)] +#[derive(Debug, Clone, PartialEq, Deserialize, Serialize)] pub struct CallSite { #[pyo3(get)] pub method_handle: MethodHandle, @@ -3475,6 +3478,15 @@ pub struct CallSite { #[pymethods] impl CallSite { + pub fn to_json(&self) -> Result { + Ok(serde_json::to_string(self)?) + } + + #[staticmethod] + pub fn from_json(json: &str) -> Result { + Ok(serde_json::from_str(json)?) + } + #[new] pub fn new( method_handle: MethodHandle, @@ -3590,7 +3602,7 @@ impl CallSite { /// Waste a cycle. #[pyclass] -#[derive(Debug, Clone, Copy, PartialEq, Eq)] +#[derive(Debug, Clone, Copy, PartialEq, Eq, Deserialize, Serialize)] pub struct Nop; impl Default for Nop { @@ -3601,6 +3613,15 @@ impl Default for Nop { #[pymethods] impl Nop { + pub fn to_json(&self) -> Result { + Ok(serde_json::to_string(self)?) + } + + #[staticmethod] + pub fn from_json(json: &str) -> Result { + Ok(serde_json::from_str(json)?) + } + #[new] pub fn new() -> Self { Self @@ -3694,7 +3715,7 @@ impl Nop { /// move/16 vAAAA, vBBBB /// #[pyclass] -#[derive(Debug, Clone, Copy, PartialEq, Eq)] +#[derive(Debug, Clone, Copy, PartialEq, Eq, Deserialize, Serialize)] pub struct Move { #[pyo3(get)] pub from: u16, @@ -3704,6 +3725,15 @@ pub struct Move { #[pymethods] impl Move { + pub fn to_json(&self) -> Result { + Ok(serde_json::to_string(self)?) + } + + #[staticmethod] + pub fn from_json(json: &str) -> Result { + Ok(serde_json::from_str(json)?) + } + #[new] pub fn new(from: u16, to: u16) -> Self { Self { from, to } @@ -3813,7 +3843,7 @@ impl Move { /// move-wide/16 vAAAA, vBBBB /// #[pyclass] -#[derive(Debug, Clone, Copy, PartialEq, Eq)] +#[derive(Debug, Clone, Copy, PartialEq, Eq, Deserialize, Serialize)] pub struct MoveWide { #[pyo3(get)] pub from: u16, @@ -3823,6 +3853,15 @@ pub struct MoveWide { #[pymethods] impl MoveWide { + pub fn to_json(&self) -> Result { + Ok(serde_json::to_string(self)?) + } + + #[staticmethod] + pub fn from_json(json: &str) -> Result { + Ok(serde_json::from_str(json)?) + } + #[new] pub fn new(from: u16, to: u16) -> Self { Self { from, to } @@ -3931,7 +3970,7 @@ impl MoveWide { /// move-object/16 vAAAA, vBBBB /// #[pyclass] -#[derive(Debug, Clone, Copy, PartialEq, Eq)] +#[derive(Debug, Clone, Copy, PartialEq, Eq, Deserialize, Serialize)] pub struct MoveObject { #[pyo3(get)] pub from: u16, @@ -3941,6 +3980,15 @@ pub struct MoveObject { #[pymethods] impl MoveObject { + pub fn to_json(&self) -> Result { + Ok(serde_json::to_string(self)?) + } + + #[staticmethod] + pub fn from_json(json: &str) -> Result { + Ok(serde_json::from_str(json)?) + } + #[new] pub fn new(from: u16, to: u16) -> Self { Self { from, to } @@ -4042,7 +4090,7 @@ impl MoveObject { /// Move the single word non object result of the preciding invoke-kind into a register. #[pyclass] -#[derive(Debug, Clone, Copy, PartialEq, Eq)] +#[derive(Debug, Clone, Copy, PartialEq, Eq, Deserialize, Serialize)] pub struct MoveResult { #[pyo3(get)] pub to: u8, @@ -4050,6 +4098,15 @@ pub struct MoveResult { #[pymethods] impl MoveResult { + pub fn to_json(&self) -> Result { + Ok(serde_json::to_string(self)?) + } + + #[staticmethod] + pub fn from_json(json: &str) -> Result { + Ok(serde_json::from_str(json)?) + } + #[new] pub fn new(to: u8) -> Self { Self { to } @@ -4138,7 +4195,7 @@ impl MoveResult { /// Move the double word non object result of the preciding invoke-kind into a register pair. #[pyclass] -#[derive(Debug, Clone, Copy, PartialEq, Eq)] +#[derive(Debug, Clone, Copy, PartialEq, Eq, Deserialize, Serialize)] pub struct MoveResultWide { #[pyo3(get)] pub to: u8, @@ -4146,6 +4203,15 @@ pub struct MoveResultWide { #[pymethods] impl MoveResultWide { + pub fn to_json(&self) -> Result { + Ok(serde_json::to_string(self)?) + } + + #[staticmethod] + pub fn from_json(json: &str) -> Result { + Ok(serde_json::from_str(json)?) + } + #[new] pub fn new(to: u8) -> Self { Self { to } @@ -4234,7 +4300,7 @@ impl MoveResultWide { /// Move the object result of the preciding invoke-kind or filled-new-array into a register. #[pyclass] -#[derive(Debug, Clone, Copy, PartialEq, Eq)] +#[derive(Debug, Clone, Copy, PartialEq, Eq, Deserialize, Serialize)] pub struct MoveResultObject { #[pyo3(get)] pub to: u8, @@ -4242,6 +4308,15 @@ pub struct MoveResultObject { #[pymethods] impl MoveResultObject { + pub fn to_json(&self) -> Result { + Ok(serde_json::to_string(self)?) + } + + #[staticmethod] + pub fn from_json(json: &str) -> Result { + Ok(serde_json::from_str(json)?) + } + #[new] pub fn new(to: u8) -> Self { Self { to } @@ -4330,7 +4405,7 @@ impl MoveResultObject { /// Move the just caught exception into a register. #[pyclass] -#[derive(Debug, Clone, Copy, PartialEq, Eq)] +#[derive(Debug, Clone, Copy, PartialEq, Eq, Deserialize, Serialize)] pub struct MoveException { #[pyo3(get)] pub to: u8, @@ -4338,6 +4413,15 @@ pub struct MoveException { #[pymethods] impl MoveException { + pub fn to_json(&self) -> Result { + Ok(serde_json::to_string(self)?) + } + + #[staticmethod] + pub fn from_json(json: &str) -> Result { + Ok(serde_json::from_str(json)?) + } + #[new] pub fn new(to: u8) -> Self { Self { to } @@ -4426,7 +4510,7 @@ impl MoveException { /// Return a void method #[pyclass] -#[derive(Debug, Clone, Copy, PartialEq, Eq)] +#[derive(Debug, Clone, Copy, PartialEq, Eq, Deserialize, Serialize)] pub struct ReturnVoid; impl Default for ReturnVoid { @@ -4437,6 +4521,15 @@ impl Default for ReturnVoid { #[pymethods] impl ReturnVoid { + pub fn to_json(&self) -> Result { + Ok(serde_json::to_string(self)?) + } + + #[staticmethod] + pub fn from_json(json: &str) -> Result { + Ok(serde_json::from_str(json)?) + } + #[new] pub fn new() -> Self { Self @@ -4522,7 +4615,7 @@ impl ReturnVoid { /// Return the 32 bits non object value from the method. #[pyclass] -#[derive(Debug, Clone, Copy, PartialEq, Eq)] +#[derive(Debug, Clone, Copy, PartialEq, Eq, Deserialize, Serialize)] pub struct Return { #[pyo3(get)] pub reg: u8, @@ -4530,6 +4623,15 @@ pub struct Return { #[pymethods] impl Return { + pub fn to_json(&self) -> Result { + Ok(serde_json::to_string(self)?) + } + + #[staticmethod] + pub fn from_json(json: &str) -> Result { + Ok(serde_json::from_str(json)?) + } + #[new] pub fn new(reg: u8) -> Self { Self { reg } @@ -4618,7 +4720,7 @@ impl Return { /// Return the 64 bits non object value from the method. #[pyclass] -#[derive(Debug, Clone, Copy, PartialEq, Eq)] +#[derive(Debug, Clone, Copy, PartialEq, Eq, Deserialize, Serialize)] pub struct ReturnWide { #[pyo3(get)] pub reg: u8, @@ -4626,6 +4728,15 @@ pub struct ReturnWide { #[pymethods] impl ReturnWide { + pub fn to_json(&self) -> Result { + Ok(serde_json::to_string(self)?) + } + + #[staticmethod] + pub fn from_json(json: &str) -> Result { + Ok(serde_json::from_str(json)?) + } + #[new] pub fn new(reg: u8) -> Self { Self { reg } @@ -4714,7 +4825,7 @@ impl ReturnWide { /// Return the object value from the method. #[pyclass] -#[derive(Debug, Clone, Copy, PartialEq, Eq)] +#[derive(Debug, Clone, Copy, PartialEq, Eq, Deserialize, Serialize)] pub struct ReturnObject { #[pyo3(get)] pub reg: u8, @@ -4722,6 +4833,15 @@ pub struct ReturnObject { #[pymethods] impl ReturnObject { + pub fn to_json(&self) -> Result { + Ok(serde_json::to_string(self)?) + } + + #[staticmethod] + pub fn from_json(json: &str) -> Result { + Ok(serde_json::from_str(json)?) + } + #[new] pub fn new(reg: u8) -> Self { Self { reg } @@ -4818,7 +4938,7 @@ impl ReturnObject { /// const/high 16 vAA #+BBBB0000 /// #[pyclass] -#[derive(Debug, Clone, Copy, PartialEq, Eq)] +#[derive(Debug, Clone, Copy, PartialEq, Eq, Deserialize, Serialize)] pub struct Const { #[pyo3(get)] pub reg: u8, @@ -4828,6 +4948,15 @@ pub struct Const { #[pymethods] impl Const { + pub fn to_json(&self) -> Result { + Ok(serde_json::to_string(self)?) + } + + #[staticmethod] + pub fn from_json(json: &str) -> Result { + Ok(serde_json::from_str(json)?) + } + #[new] pub fn new(reg: u8, lit: i32) -> Self { Self { reg, lit } @@ -4942,7 +5071,7 @@ impl Const { /// const-wide/hight 16 vAA #+BBBB000000000000 /// #[pyclass] -#[derive(Debug, Clone, Copy, PartialEq, Eq)] +#[derive(Debug, Clone, Copy, PartialEq, Eq, Deserialize, Serialize)] pub struct ConstWide { #[pyo3(get)] pub reg: u8, @@ -4952,6 +5081,15 @@ pub struct ConstWide { #[pymethods] impl ConstWide { + pub fn to_json(&self) -> Result { + Ok(serde_json::to_string(self)?) + } + + #[staticmethod] + pub fn from_json(json: &str) -> Result { + Ok(serde_json::from_str(json)?) + } + #[new] pub fn new(reg: u8, lit: i64) -> Self { Self { reg, lit } @@ -5064,7 +5202,7 @@ impl ConstWide { /// const-string/jumbo vAA string@BBBBBBBB /// #[pyclass] -#[derive(Debug, Clone, PartialEq, Eq)] +#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize)] pub struct ConstString { #[pyo3(get)] pub reg: u8, @@ -5074,6 +5212,15 @@ pub struct ConstString { #[pymethods] impl ConstString { + pub fn to_json(&self) -> Result { + Ok(serde_json::to_string(self)?) + } + + #[staticmethod] + pub fn from_json(json: &str) -> Result { + Ok(serde_json::from_str(json)?) + } + #[new] pub fn new(reg: u8, lit: DexString) -> Self { Self { reg, lit } @@ -5165,7 +5312,7 @@ impl ConstString { /// Move a reference to a class in a register. #[pyclass] -#[derive(Debug, Clone, PartialEq, Eq)] +#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize)] pub struct ConstClass { #[pyo3(get)] pub reg: u8, @@ -5175,6 +5322,15 @@ pub struct ConstClass { #[pymethods] impl ConstClass { + pub fn to_json(&self) -> Result { + Ok(serde_json::to_string(self)?) + } + + #[staticmethod] + pub fn from_json(json: &str) -> Result { + Ok(serde_json::from_str(json)?) + } + #[new] pub fn new(reg: u8, lit: IdType) -> Self { Self { reg, lit } @@ -5270,7 +5426,7 @@ impl ConstClass { /// Acquire the monitor for the object in the register. #[pyclass] -#[derive(Debug, Clone, Copy, PartialEq, Eq)] +#[derive(Debug, Clone, Copy, PartialEq, Eq, Deserialize, Serialize)] pub struct MonitorEnter { #[pyo3(get)] pub reg: u8, @@ -5278,6 +5434,15 @@ pub struct MonitorEnter { #[pymethods] impl MonitorEnter { + pub fn to_json(&self) -> Result { + Ok(serde_json::to_string(self)?) + } + + #[staticmethod] + pub fn from_json(json: &str) -> Result { + Ok(serde_json::from_str(json)?) + } + #[new] pub fn new(reg: u8) -> Self { Self { reg } @@ -5366,7 +5531,7 @@ impl MonitorEnter { /// Release the monitor for the object in the register. #[pyclass] -#[derive(Debug, Clone, Copy, PartialEq, Eq)] +#[derive(Debug, Clone, Copy, PartialEq, Eq, Deserialize, Serialize)] pub struct MonitorExit { #[pyo3(get)] pub reg: u8, @@ -5374,6 +5539,15 @@ pub struct MonitorExit { #[pymethods] impl MonitorExit { + pub fn to_json(&self) -> Result { + Ok(serde_json::to_string(self)?) + } + + #[staticmethod] + pub fn from_json(json: &str) -> Result { + Ok(serde_json::from_str(json)?) + } + #[new] pub fn new(reg: u8) -> Self { Self { reg } @@ -5463,7 +5637,7 @@ impl MonitorExit { /// Check if the object in the register can be cast to the type. /// (Raise a `ClassCastException` if not) #[pyclass] -#[derive(Debug, Clone, PartialEq, Eq)] +#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize)] pub struct CheckCast { #[pyo3(get)] pub reg: u8, @@ -5473,6 +5647,15 @@ pub struct CheckCast { #[pymethods] impl CheckCast { + pub fn to_json(&self) -> Result { + Ok(serde_json::to_string(self)?) + } + + #[staticmethod] + pub fn from_json(json: &str) -> Result { + Ok(serde_json::from_str(json)?) + } + #[new] pub fn new(reg: u8, lit: IdType) -> Self { Self { reg, lit } @@ -5569,7 +5752,7 @@ impl CheckCast { /// Check if an object if an instance of a type. /// (put 1 in the dest register if yes, else 0) #[pyclass] -#[derive(Debug, Clone, PartialEq, Eq)] +#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize)] pub struct InstanceOf { #[pyo3(get)] pub dest: u8, @@ -5581,6 +5764,15 @@ pub struct InstanceOf { #[pymethods] impl InstanceOf { + pub fn to_json(&self) -> Result { + Ok(serde_json::to_string(self)?) + } + + #[staticmethod] + pub fn from_json(json: &str) -> Result { + Ok(serde_json::from_str(json)?) + } + #[new] pub fn new(dest: u8, obj: u8, lit: IdType) -> Result { let ins = Self { dest, obj, lit }; @@ -5702,7 +5894,7 @@ impl InstanceOf { /// Get the number of item in an array. /// (put the lenght in the dest register) #[pyclass] -#[derive(Debug, Clone, Copy, PartialEq, Eq)] +#[derive(Debug, Clone, Copy, PartialEq, Eq, Deserialize, Serialize)] pub struct ArrayLength { #[pyo3(get)] pub dest: u8, @@ -5712,6 +5904,15 @@ pub struct ArrayLength { #[pymethods] impl ArrayLength { + pub fn to_json(&self) -> Result { + Ok(serde_json::to_string(self)?) + } + + #[staticmethod] + pub fn from_json(json: &str) -> Result { + Ok(serde_json::from_str(json)?) + } + #[new] pub fn new(dest: u8, arr: u8) -> Result { let ins = Self { dest, arr }; @@ -5819,7 +6020,7 @@ impl ArrayLength { /// Construct a new instance of the indicated type and store a reference to it. #[pyclass] -#[derive(Debug, Clone, PartialEq, Eq)] +#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize)] pub struct NewInstance { #[pyo3(get)] pub reg: u8, @@ -5829,6 +6030,15 @@ pub struct NewInstance { #[pymethods] impl NewInstance { + pub fn to_json(&self) -> Result { + Ok(serde_json::to_string(self)?) + } + + #[staticmethod] + pub fn from_json(json: &str) -> Result { + Ok(serde_json::from_str(json)?) + } + #[new] pub fn new(reg: u8, lit: IdType) -> Self { Self { reg, lit } @@ -5924,7 +6134,7 @@ impl NewInstance { /// Construct a new array of the indicated type and size in size_reg and store a reference to it. #[pyclass] -#[derive(Debug, Clone, PartialEq, Eq)] +#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize)] pub struct NewArray { #[pyo3(get)] pub reg: u8, @@ -5936,6 +6146,15 @@ pub struct NewArray { #[pymethods] impl NewArray { + pub fn to_json(&self) -> Result { + Ok(serde_json::to_string(self)?) + } + + #[staticmethod] + pub fn from_json(json: &str) -> Result { + Ok(serde_json::from_str(json)?) + } + #[new] pub fn new(reg: u8, size_reg: u8, lit: IdType) -> Result { let ins = Self { reg, size_reg, lit }; @@ -6065,7 +6284,7 @@ impl NewArray { /// /// The newly created array can be retreived with a move-result-object instruction. #[pyclass] -#[derive(Debug, Clone, PartialEq, Eq)] +#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize)] pub struct FilledNewArray { #[pyo3(get)] pub type_: IdType, @@ -6075,6 +6294,15 @@ pub struct FilledNewArray { #[pymethods] impl FilledNewArray { + pub fn to_json(&self) -> Result { + Ok(serde_json::to_string(self)?) + } + + #[staticmethod] + pub fn from_json(json: &str) -> Result { + Ok(serde_json::from_str(json)?) + } + #[new] pub fn new(type_: IdType, reg_values: Vec) -> Result { let array = Self { type_, reg_values }; @@ -6277,7 +6505,7 @@ impl FilledNewArray { } #[pyclass] -#[derive(Debug, Clone, PartialEq, Eq)] +#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize)] pub struct FillArrayData { #[pyo3(get)] pub arr: u8, @@ -6289,6 +6517,15 @@ pub struct FillArrayData { #[pymethods] impl FillArrayData { + pub fn to_json(&self) -> Result { + Ok(serde_json::to_string(self)?) + } + + #[staticmethod] + pub fn from_json(json: &str) -> Result { + Ok(serde_json::from_str(json)?) + } + #[new] pub fn new(arr: u8, elt_width: u16, data: Vec) -> Self { Self { @@ -6435,7 +6672,7 @@ impl FillArrayData { /// Throws the exception in the register. #[pyclass] -#[derive(Debug, Clone, Copy, PartialEq, Eq)] +#[derive(Debug, Clone, Copy, PartialEq, Eq, Deserialize, Serialize)] pub struct Throw { #[pyo3(get)] pub reg: u8, @@ -6443,6 +6680,15 @@ pub struct Throw { #[pymethods] impl Throw { + pub fn to_json(&self) -> Result { + Ok(serde_json::to_string(self)?) + } + + #[staticmethod] + pub fn from_json(json: &str) -> Result { + Ok(serde_json::from_str(json)?) + } + #[new] pub fn new(reg: u8) -> Self { Self { reg } @@ -6531,7 +6777,7 @@ impl Throw { /// Jump to the label. #[pyclass] -#[derive(Debug, Clone, PartialEq, Eq)] +#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize)] pub struct Goto { #[pyo3(get)] pub label: String, @@ -6539,6 +6785,15 @@ pub struct Goto { #[pymethods] impl Goto { + pub fn to_json(&self) -> Result { + Ok(serde_json::to_string(self)?) + } + + #[staticmethod] + pub fn from_json(json: &str) -> Result { + Ok(serde_json::from_str(json)?) + } + #[new] pub fn new(label: String) -> Self { Self { label } @@ -6671,16 +6926,26 @@ impl Goto { /// Jump to a label depending on the value of a register. If the value /// is not matched, continue the extecution at the next instruction. #[pyclass] -#[derive(Debug, Clone, PartialEq, Eq)] +#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize)] pub struct Switch { #[pyo3(get)] pub reg: u8, #[pyo3(get)] + #[serde(with = "hashmap_vectorize")] pub branches: HashMap, } #[pymethods] impl Switch { + pub fn to_json(&self) -> Result { + Ok(serde_json::to_string(self)?) + } + + #[staticmethod] + pub fn from_json(json: &str) -> Result { + Ok(serde_json::from_str(json)?) + } + #[new] pub fn new(reg: u8, branches: HashMap) -> Self { Self { reg, branches } @@ -6798,7 +7063,7 @@ impl Switch { /// - b > c : a = 1 /// - b == c == Nan: a = -1 #[pyclass] -#[derive(Debug, Clone, Copy, PartialEq, Eq)] +#[derive(Debug, Clone, Copy, PartialEq, Eq, Deserialize, Serialize)] pub struct CmpLFloat { #[pyo3(get)] pub dest: u8, @@ -6810,6 +7075,15 @@ pub struct CmpLFloat { #[pymethods] impl CmpLFloat { + pub fn to_json(&self) -> Result { + Ok(serde_json::to_string(self)?) + } + + #[staticmethod] + pub fn from_json(json: &str) -> Result { + Ok(serde_json::from_str(json)?) + } + #[new] pub fn new(dest: u8, b: u8, c: u8) -> Self { Self { dest, b, c } @@ -6908,7 +7182,7 @@ impl CmpLFloat { /// - b > c : a = 1 /// - b == c == Nan: a = 1 #[pyclass] -#[derive(Debug, Clone, Copy, PartialEq, Eq)] +#[derive(Debug, Clone, Copy, PartialEq, Eq, Deserialize, Serialize)] pub struct CmpGFloat { #[pyo3(get)] pub dest: u8, @@ -6920,6 +7194,15 @@ pub struct CmpGFloat { #[pymethods] impl CmpGFloat { + pub fn to_json(&self) -> Result { + Ok(serde_json::to_string(self)?) + } + + #[staticmethod] + pub fn from_json(json: &str) -> Result { + Ok(serde_json::from_str(json)?) + } + #[new] pub fn new(dest: u8, b: u8, c: u8) -> Self { Self { dest, b, c } @@ -7018,7 +7301,7 @@ impl CmpGFloat { /// - b > c : a = 1 /// - b == c == Nan: a = -1 #[pyclass] -#[derive(Debug, Clone, Copy, PartialEq, Eq)] +#[derive(Debug, Clone, Copy, PartialEq, Eq, Deserialize, Serialize)] pub struct CmpLDouble { #[pyo3(get)] pub dest: u8, @@ -7030,6 +7313,15 @@ pub struct CmpLDouble { #[pymethods] impl CmpLDouble { + pub fn to_json(&self) -> Result { + Ok(serde_json::to_string(self)?) + } + + #[staticmethod] + pub fn from_json(json: &str) -> Result { + Ok(serde_json::from_str(json)?) + } + #[new] pub fn new(dest: u8, b: u8, c: u8) -> Self { Self { dest, b, c } @@ -7128,7 +7420,7 @@ impl CmpLDouble { /// - b > c : a = 1 /// - b == c == Nan: a = 1 #[pyclass] -#[derive(Debug, Clone, Copy, PartialEq, Eq)] +#[derive(Debug, Clone, Copy, PartialEq, Eq, Deserialize, Serialize)] pub struct CmpGDouble { #[pyo3(get)] pub dest: u8, @@ -7140,6 +7432,15 @@ pub struct CmpGDouble { #[pymethods] impl CmpGDouble { + pub fn to_json(&self) -> Result { + Ok(serde_json::to_string(self)?) + } + + #[staticmethod] + pub fn from_json(json: &str) -> Result { + Ok(serde_json::from_str(json)?) + } + #[new] pub fn new(dest: u8, b: u8, c: u8) -> Self { Self { dest, b, c } @@ -7237,7 +7538,7 @@ impl CmpGDouble { /// - b == c: a = 0 /// - b > c : a = 1 #[pyclass] -#[derive(Debug, Clone, Copy, PartialEq, Eq)] +#[derive(Debug, Clone, Copy, PartialEq, Eq, Deserialize, Serialize)] pub struct CmpLong { #[pyo3(get)] pub dest: u8, @@ -7249,6 +7550,15 @@ pub struct CmpLong { #[pymethods] impl CmpLong { + pub fn to_json(&self) -> Result { + Ok(serde_json::to_string(self)?) + } + + #[staticmethod] + pub fn from_json(json: &str) -> Result { + Ok(serde_json::from_str(json)?) + } + #[new] pub fn new(dest: u8, b: u8, c: u8) -> Self { Self { dest, b, c } @@ -7342,7 +7652,7 @@ impl CmpLong { /// Jump to the label if a == b #[pyclass] -#[derive(Debug, Clone, PartialEq, Eq)] +#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize)] pub struct IfEq { #[pyo3(get)] pub a: u8, @@ -7354,6 +7664,15 @@ pub struct IfEq { #[pymethods] impl IfEq { + pub fn to_json(&self) -> Result { + Ok(serde_json::to_string(self)?) + } + + #[staticmethod] + pub fn from_json(json: &str) -> Result { + Ok(serde_json::from_str(json)?) + } + #[new] pub fn new(a: u8, b: u8, label: String) -> Result { let ins = Self { a, b, label }; @@ -7464,7 +7783,7 @@ impl IfEq { /// Jump to the label if a != b #[pyclass] -#[derive(Debug, Clone, PartialEq, Eq)] +#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize)] pub struct IfNe { #[pyo3(get)] pub a: u8, @@ -7476,6 +7795,15 @@ pub struct IfNe { #[pymethods] impl IfNe { + pub fn to_json(&self) -> Result { + Ok(serde_json::to_string(self)?) + } + + #[staticmethod] + pub fn from_json(json: &str) -> Result { + Ok(serde_json::from_str(json)?) + } + #[new] pub fn new(a: u8, b: u8, label: String) -> Result { let ins = Self { a, b, label }; @@ -7587,7 +7915,7 @@ impl IfNe { /// Jump to the label if a < b #[pyclass] -#[derive(Debug, Clone, PartialEq, Eq)] +#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize)] pub struct IfLt { #[pyo3(get)] pub a: u8, @@ -7599,6 +7927,15 @@ pub struct IfLt { #[pymethods] impl IfLt { + pub fn to_json(&self) -> Result { + Ok(serde_json::to_string(self)?) + } + + #[staticmethod] + pub fn from_json(json: &str) -> Result { + Ok(serde_json::from_str(json)?) + } + #[new] pub fn new(a: u8, b: u8, label: String) -> Result { let ins = Self { a, b, label }; @@ -7710,7 +8047,7 @@ impl IfLt { /// Jump to the label if a >= b #[pyclass] -#[derive(Debug, Clone, PartialEq, Eq)] +#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize)] pub struct IfGe { #[pyo3(get)] pub a: u8, @@ -7722,6 +8059,15 @@ pub struct IfGe { #[pymethods] impl IfGe { + pub fn to_json(&self) -> Result { + Ok(serde_json::to_string(self)?) + } + + #[staticmethod] + pub fn from_json(json: &str) -> Result { + Ok(serde_json::from_str(json)?) + } + #[new] pub fn new(a: u8, b: u8, label: String) -> Result { let ins = Self { a, b, label }; @@ -7833,7 +8179,7 @@ impl IfGe { /// Jump to the label if a > b #[pyclass] -#[derive(Debug, Clone, PartialEq, Eq)] +#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize)] pub struct IfGt { #[pyo3(get)] pub a: u8, @@ -7845,6 +8191,15 @@ pub struct IfGt { #[pymethods] impl IfGt { + pub fn to_json(&self) -> Result { + Ok(serde_json::to_string(self)?) + } + + #[staticmethod] + pub fn from_json(json: &str) -> Result { + Ok(serde_json::from_str(json)?) + } + #[new] pub fn new(a: u8, b: u8, label: String) -> Result { let ins = Self { a, b, label }; @@ -7956,7 +8311,7 @@ impl IfGt { /// Jump to the label if a <= b #[pyclass] -#[derive(Debug, Clone, PartialEq, Eq)] +#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize)] pub struct IfLe { #[pyo3(get)] pub a: u8, @@ -7968,6 +8323,15 @@ pub struct IfLe { #[pymethods] impl IfLe { + pub fn to_json(&self) -> Result { + Ok(serde_json::to_string(self)?) + } + + #[staticmethod] + pub fn from_json(json: &str) -> Result { + Ok(serde_json::from_str(json)?) + } + #[new] pub fn new(a: u8, b: u8, label: String) -> Result { let ins = Self { a, b, label }; @@ -8079,7 +8443,7 @@ impl IfLe { /// Jump to the label if a == 0 #[pyclass] -#[derive(Debug, Clone, PartialEq, Eq)] +#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize)] pub struct IfEqZ { #[pyo3(get)] pub a: u8, @@ -8089,6 +8453,15 @@ pub struct IfEqZ { #[pymethods] impl IfEqZ { + pub fn to_json(&self) -> Result { + Ok(serde_json::to_string(self)?) + } + + #[staticmethod] + pub fn from_json(json: &str) -> Result { + Ok(serde_json::from_str(json)?) + } + #[new] pub fn new(a: u8, label: String) -> Result { let ins = Self { a, label }; @@ -8182,7 +8555,7 @@ impl IfEqZ { /// Jump to the label if a != 0 #[pyclass] -#[derive(Debug, Clone, PartialEq, Eq)] +#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize)] pub struct IfNeZ { #[pyo3(get)] pub a: u8, @@ -8192,6 +8565,15 @@ pub struct IfNeZ { #[pymethods] impl IfNeZ { + pub fn to_json(&self) -> Result { + Ok(serde_json::to_string(self)?) + } + + #[staticmethod] + pub fn from_json(json: &str) -> Result { + Ok(serde_json::from_str(json)?) + } + #[new] pub fn new(a: u8, label: String) -> Result { let ins = Self { a, label }; @@ -8285,7 +8667,7 @@ impl IfNeZ { /// Jump to the label if a < 0 #[pyclass] -#[derive(Debug, Clone, PartialEq, Eq)] +#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize)] pub struct IfLtZ { #[pyo3(get)] pub a: u8, @@ -8295,6 +8677,15 @@ pub struct IfLtZ { #[pymethods] impl IfLtZ { + pub fn to_json(&self) -> Result { + Ok(serde_json::to_string(self)?) + } + + #[staticmethod] + pub fn from_json(json: &str) -> Result { + Ok(serde_json::from_str(json)?) + } + #[new] pub fn new(a: u8, label: String) -> Result { let ins = Self { a, label }; @@ -8388,7 +8779,7 @@ impl IfLtZ { /// Jump to the label if a >= 0 #[pyclass] -#[derive(Debug, Clone, PartialEq, Eq)] +#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize)] pub struct IfGeZ { #[pyo3(get)] pub a: u8, @@ -8398,6 +8789,15 @@ pub struct IfGeZ { #[pymethods] impl IfGeZ { + pub fn to_json(&self) -> Result { + Ok(serde_json::to_string(self)?) + } + + #[staticmethod] + pub fn from_json(json: &str) -> Result { + Ok(serde_json::from_str(json)?) + } + #[new] pub fn new(a: u8, label: String) -> Result { let ins = Self { a, label }; @@ -8491,7 +8891,7 @@ impl IfGeZ { /// Jump to the label if a > 0 #[pyclass] -#[derive(Debug, Clone, PartialEq, Eq)] +#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize)] pub struct IfGtZ { #[pyo3(get)] pub a: u8, @@ -8501,6 +8901,15 @@ pub struct IfGtZ { #[pymethods] impl IfGtZ { + pub fn to_json(&self) -> Result { + Ok(serde_json::to_string(self)?) + } + + #[staticmethod] + pub fn from_json(json: &str) -> Result { + Ok(serde_json::from_str(json)?) + } + #[new] pub fn new(a: u8, label: String) -> Result { let ins = Self { a, label }; @@ -8594,7 +9003,7 @@ impl IfGtZ { /// Jump to the label if a <= 0 #[pyclass] -#[derive(Debug, Clone, PartialEq, Eq)] +#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize)] pub struct IfLeZ { #[pyo3(get)] pub a: u8, @@ -8604,6 +9013,15 @@ pub struct IfLeZ { #[pymethods] impl IfLeZ { + pub fn to_json(&self) -> Result { + Ok(serde_json::to_string(self)?) + } + + #[staticmethod] + pub fn from_json(json: &str) -> Result { + Ok(serde_json::from_str(json)?) + } + #[new] pub fn new(a: u8, label: String) -> Result { let ins = Self { a, label }; @@ -8697,7 +9115,7 @@ impl IfLeZ { /// Put the value at `arr[idx]` in register dest (all values are in registers) #[pyclass] -#[derive(Debug, Clone, Copy, PartialEq, Eq)] +#[derive(Debug, Clone, Copy, PartialEq, Eq, Deserialize, Serialize)] pub struct AGet { #[pyo3(get)] pub dest: u8, @@ -8709,6 +9127,15 @@ pub struct AGet { #[pymethods] impl AGet { + pub fn to_json(&self) -> Result { + Ok(serde_json::to_string(self)?) + } + + #[staticmethod] + pub fn from_json(json: &str) -> Result { + Ok(serde_json::from_str(json)?) + } + #[new] pub fn new(dest: u8, arr: u8, idx: u8) -> Self { Self { dest, arr, idx } @@ -8802,7 +9229,7 @@ impl AGet { /// Put the value at `arr[idx]` in register pair dest (all values are in registers) #[pyclass] -#[derive(Debug, Clone, Copy, PartialEq, Eq)] +#[derive(Debug, Clone, Copy, PartialEq, Eq, Deserialize, Serialize)] pub struct AGetWide { #[pyo3(get)] pub dest: u8, @@ -8814,6 +9241,15 @@ pub struct AGetWide { #[pymethods] impl AGetWide { + pub fn to_json(&self) -> Result { + Ok(serde_json::to_string(self)?) + } + + #[staticmethod] + pub fn from_json(json: &str) -> Result { + Ok(serde_json::from_str(json)?) + } + #[new] pub fn new(dest: u8, arr: u8, idx: u8) -> Self { Self { dest, arr, idx } @@ -8907,7 +9343,7 @@ impl AGetWide { /// Put the reference at `arr[idx]` in register (all values are in registers) #[pyclass] -#[derive(Debug, Clone, Copy, PartialEq, Eq)] +#[derive(Debug, Clone, Copy, PartialEq, Eq, Deserialize, Serialize)] pub struct AGetObject { #[pyo3(get)] pub dest: u8, @@ -8919,6 +9355,15 @@ pub struct AGetObject { #[pymethods] impl AGetObject { + pub fn to_json(&self) -> Result { + Ok(serde_json::to_string(self)?) + } + + #[staticmethod] + pub fn from_json(json: &str) -> Result { + Ok(serde_json::from_str(json)?) + } + #[new] pub fn new(dest: u8, arr: u8, idx: u8) -> Self { Self { dest, arr, idx } @@ -9012,7 +9457,7 @@ impl AGetObject { /// Put the boolean at `arr[idx]` in register dest (all values are in registers) #[pyclass] -#[derive(Debug, Clone, Copy, PartialEq, Eq)] +#[derive(Debug, Clone, Copy, PartialEq, Eq, Deserialize, Serialize)] pub struct AGetBoolean { #[pyo3(get)] pub dest: u8, @@ -9024,6 +9469,15 @@ pub struct AGetBoolean { #[pymethods] impl AGetBoolean { + pub fn to_json(&self) -> Result { + Ok(serde_json::to_string(self)?) + } + + #[staticmethod] + pub fn from_json(json: &str) -> Result { + Ok(serde_json::from_str(json)?) + } + #[new] pub fn new(dest: u8, arr: u8, idx: u8) -> Self { Self { dest, arr, idx } @@ -9117,7 +9571,7 @@ impl AGetBoolean { /// Put the byte at `arr[idx]` in register dest (all values are in registers) #[pyclass] -#[derive(Debug, Clone, Copy, PartialEq, Eq)] +#[derive(Debug, Clone, Copy, PartialEq, Eq, Deserialize, Serialize)] pub struct AGetByte { #[pyo3(get)] pub dest: u8, @@ -9129,6 +9583,15 @@ pub struct AGetByte { #[pymethods] impl AGetByte { + pub fn to_json(&self) -> Result { + Ok(serde_json::to_string(self)?) + } + + #[staticmethod] + pub fn from_json(json: &str) -> Result { + Ok(serde_json::from_str(json)?) + } + #[new] pub fn new(dest: u8, arr: u8, idx: u8) -> Self { Self { dest, arr, idx } @@ -9222,7 +9685,7 @@ impl AGetByte { /// Put the char at `arr[idx]` in register dest (all values are in registers) #[pyclass] -#[derive(Debug, Clone, Copy, PartialEq, Eq)] +#[derive(Debug, Clone, Copy, PartialEq, Eq, Deserialize, Serialize)] pub struct AGetChar { #[pyo3(get)] pub dest: u8, @@ -9234,6 +9697,15 @@ pub struct AGetChar { #[pymethods] impl AGetChar { + pub fn to_json(&self) -> Result { + Ok(serde_json::to_string(self)?) + } + + #[staticmethod] + pub fn from_json(json: &str) -> Result { + Ok(serde_json::from_str(json)?) + } + #[new] pub fn new(dest: u8, arr: u8, idx: u8) -> Self { Self { dest, arr, idx } @@ -9327,7 +9799,7 @@ impl AGetChar { /// Put the short at `arr[idx]` in register dest (all values are in registers) #[pyclass] -#[derive(Debug, Clone, Copy, PartialEq, Eq)] +#[derive(Debug, Clone, Copy, PartialEq, Eq, Deserialize, Serialize)] pub struct AGetShort { #[pyo3(get)] pub dest: u8, @@ -9339,6 +9811,15 @@ pub struct AGetShort { #[pymethods] impl AGetShort { + pub fn to_json(&self) -> Result { + Ok(serde_json::to_string(self)?) + } + + #[staticmethod] + pub fn from_json(json: &str) -> Result { + Ok(serde_json::from_str(json)?) + } + #[new] pub fn new(dest: u8, arr: u8, idx: u8) -> Self { Self { dest, arr, idx } @@ -9432,7 +9913,7 @@ impl AGetShort { /// Put the value of register 'from' in `arr[idx]` (all values are in registers) #[pyclass] -#[derive(Debug, Clone, Copy, PartialEq, Eq)] +#[derive(Debug, Clone, Copy, PartialEq, Eq, Deserialize, Serialize)] pub struct APut { #[pyo3(get)] pub from: u8, @@ -9444,6 +9925,15 @@ pub struct APut { #[pymethods] impl APut { + pub fn to_json(&self) -> Result { + Ok(serde_json::to_string(self)?) + } + + #[staticmethod] + pub fn from_json(json: &str) -> Result { + Ok(serde_json::from_str(json)?) + } + #[new] pub fn new(from: u8, arr: u8, idx: u8) -> Self { Self { from, arr, idx } @@ -9537,7 +10027,7 @@ impl APut { /// Put the value of the register pair 'from' in `arr[idx]` (all values are in registers) #[pyclass] -#[derive(Debug, Clone, Copy, PartialEq, Eq)] +#[derive(Debug, Clone, Copy, PartialEq, Eq, Deserialize, Serialize)] pub struct APutWide { #[pyo3(get)] pub from: u8, @@ -9549,6 +10039,15 @@ pub struct APutWide { #[pymethods] impl APutWide { + pub fn to_json(&self) -> Result { + Ok(serde_json::to_string(self)?) + } + + #[staticmethod] + pub fn from_json(json: &str) -> Result { + Ok(serde_json::from_str(json)?) + } + #[new] pub fn new(from: u8, arr: u8, idx: u8) -> Self { Self { from, arr, idx } @@ -9642,7 +10141,7 @@ impl APutWide { /// Put the object reference in 'from' in `arr[idx]` (all values are in registers) #[pyclass] -#[derive(Debug, Clone, Copy, PartialEq, Eq)] +#[derive(Debug, Clone, Copy, PartialEq, Eq, Deserialize, Serialize)] pub struct APutObject { #[pyo3(get)] pub from: u8, @@ -9654,6 +10153,15 @@ pub struct APutObject { #[pymethods] impl APutObject { + pub fn to_json(&self) -> Result { + Ok(serde_json::to_string(self)?) + } + + #[staticmethod] + pub fn from_json(json: &str) -> Result { + Ok(serde_json::from_str(json)?) + } + #[new] pub fn new(from: u8, arr: u8, idx: u8) -> Self { Self { from, arr, idx } @@ -9747,7 +10255,7 @@ impl APutObject { /// Put the boolean in 'from' in `arr[idx]` (all values are in registers) #[pyclass] -#[derive(Debug, Clone, Copy, PartialEq, Eq)] +#[derive(Debug, Clone, Copy, PartialEq, Eq, Deserialize, Serialize)] pub struct APutBoolean { #[pyo3(get)] pub from: u8, @@ -9759,6 +10267,15 @@ pub struct APutBoolean { #[pymethods] impl APutBoolean { + pub fn to_json(&self) -> Result { + Ok(serde_json::to_string(self)?) + } + + #[staticmethod] + pub fn from_json(json: &str) -> Result { + Ok(serde_json::from_str(json)?) + } + #[new] pub fn new(from: u8, arr: u8, idx: u8) -> Self { Self { from, arr, idx } @@ -9852,7 +10369,7 @@ impl APutBoolean { /// Put the byte in 'from' in `arr[idx]` (all values are in registers) #[pyclass] -#[derive(Debug, Clone, Copy, PartialEq, Eq)] +#[derive(Debug, Clone, Copy, PartialEq, Eq, Deserialize, Serialize)] pub struct APutByte { #[pyo3(get)] pub from: u8, @@ -9864,6 +10381,15 @@ pub struct APutByte { #[pymethods] impl APutByte { + pub fn to_json(&self) -> Result { + Ok(serde_json::to_string(self)?) + } + + #[staticmethod] + pub fn from_json(json: &str) -> Result { + Ok(serde_json::from_str(json)?) + } + #[new] pub fn new(from: u8, arr: u8, idx: u8) -> Self { Self { from, arr, idx } @@ -9957,7 +10483,7 @@ impl APutByte { /// Put the char in 'from' in `arr[idx]` (all values are in registers) #[pyclass] -#[derive(Debug, Clone, Copy, PartialEq, Eq)] +#[derive(Debug, Clone, Copy, PartialEq, Eq, Deserialize, Serialize)] pub struct APutChar { #[pyo3(get)] pub from: u8, @@ -9969,6 +10495,15 @@ pub struct APutChar { #[pymethods] impl APutChar { + pub fn to_json(&self) -> Result { + Ok(serde_json::to_string(self)?) + } + + #[staticmethod] + pub fn from_json(json: &str) -> Result { + Ok(serde_json::from_str(json)?) + } + #[new] pub fn new(from: u8, arr: u8, idx: u8) -> Self { Self { from, arr, idx } @@ -10062,7 +10597,7 @@ impl APutChar { /// Put the short in 'from' in `arr[idx]` (all values are in registers) #[pyclass] -#[derive(Debug, Clone, Copy, PartialEq, Eq)] +#[derive(Debug, Clone, Copy, PartialEq, Eq, Deserialize, Serialize)] pub struct APutShort { #[pyo3(get)] pub from: u8, @@ -10074,6 +10609,15 @@ pub struct APutShort { #[pymethods] impl APutShort { + pub fn to_json(&self) -> Result { + Ok(serde_json::to_string(self)?) + } + + #[staticmethod] + pub fn from_json(json: &str) -> Result { + Ok(serde_json::from_str(json)?) + } + #[new] pub fn new(from: u8, arr: u8, idx: u8) -> Self { Self { from, arr, idx } @@ -10169,7 +10713,7 @@ impl APutShort { /// /// The registers 'to' and 'obj' are idexed on 4 bits. #[pyclass] -#[derive(Debug, Clone, PartialEq, Eq)] +#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize)] pub struct IGet { #[pyo3(get)] pub to: u8, @@ -10181,6 +10725,15 @@ pub struct IGet { #[pymethods] impl IGet { + pub fn to_json(&self) -> Result { + Ok(serde_json::to_string(self)?) + } + + #[staticmethod] + pub fn from_json(json: &str) -> Result { + Ok(serde_json::from_str(json)?) + } + #[new] pub fn new(to: u8, obj: u8, field: IdField) -> Result { let ins = Self { to, obj, field }; @@ -10301,7 +10854,7 @@ impl IGet { /// /// The registers 'to' and 'obj' are idexed on 4 bits. #[pyclass] -#[derive(Debug, Clone, PartialEq, Eq)] +#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize)] pub struct IGetWide { #[pyo3(get)] pub to: u8, @@ -10313,6 +10866,15 @@ pub struct IGetWide { #[pymethods] impl IGetWide { + pub fn to_json(&self) -> Result { + Ok(serde_json::to_string(self)?) + } + + #[staticmethod] + pub fn from_json(json: &str) -> Result { + Ok(serde_json::from_str(json)?) + } + #[new] pub fn new(to: u8, obj: u8, field: IdField) -> Result { let ins = Self { to, obj, field }; @@ -10437,7 +10999,7 @@ impl IGetWide { /// /// The registers 'to' and 'obj' are idexed on 4 bits. #[pyclass] -#[derive(Debug, Clone, PartialEq, Eq)] +#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize)] pub struct IGetObject { #[pyo3(get)] pub to: u8, @@ -10449,6 +11011,15 @@ pub struct IGetObject { #[pymethods] impl IGetObject { + pub fn to_json(&self) -> Result { + Ok(serde_json::to_string(self)?) + } + + #[staticmethod] + pub fn from_json(json: &str) -> Result { + Ok(serde_json::from_str(json)?) + } + #[new] pub fn new(to: u8, obj: u8, field: IdField) -> Result { let ins = Self { to, obj, field }; @@ -10573,7 +11144,7 @@ impl IGetObject { /// /// The registers 'to' and 'obj' are idexed on 4 bits. #[pyclass] -#[derive(Debug, Clone, PartialEq, Eq)] +#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize)] pub struct IGetBoolean { #[pyo3(get)] pub to: u8, @@ -10585,6 +11156,15 @@ pub struct IGetBoolean { #[pymethods] impl IGetBoolean { + pub fn to_json(&self) -> Result { + Ok(serde_json::to_string(self)?) + } + + #[staticmethod] + pub fn from_json(json: &str) -> Result { + Ok(serde_json::from_str(json)?) + } + #[new] pub fn new(to: u8, obj: u8, field: IdField) -> Result { let ins = Self { to, obj, field }; @@ -10710,7 +11290,7 @@ impl IGetBoolean { /// /// The registers 'to' and 'obj' are idexed on 4 bits. #[pyclass] -#[derive(Debug, Clone, PartialEq, Eq)] +#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize)] pub struct IGetByte { #[pyo3(get)] pub to: u8, @@ -10722,6 +11302,15 @@ pub struct IGetByte { #[pymethods] impl IGetByte { + pub fn to_json(&self) -> Result { + Ok(serde_json::to_string(self)?) + } + + #[staticmethod] + pub fn from_json(json: &str) -> Result { + Ok(serde_json::from_str(json)?) + } + #[new] pub fn new(to: u8, obj: u8, field: IdField) -> Result { let ins = Self { to, obj, field }; @@ -10846,7 +11435,7 @@ impl IGetByte { /// /// The registers 'to' and 'obj' are idexed on 4 bits. #[pyclass] -#[derive(Debug, Clone, PartialEq, Eq)] +#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize)] pub struct IGetChar { #[pyo3(get)] pub to: u8, @@ -10858,6 +11447,15 @@ pub struct IGetChar { #[pymethods] impl IGetChar { + pub fn to_json(&self) -> Result { + Ok(serde_json::to_string(self)?) + } + + #[staticmethod] + pub fn from_json(json: &str) -> Result { + Ok(serde_json::from_str(json)?) + } + #[new] pub fn new(to: u8, obj: u8, field: IdField) -> Result { let ins = Self { to, obj, field }; @@ -10982,7 +11580,7 @@ impl IGetChar { /// /// The registers 'to' and 'obj' are idexed on 4 bits. #[pyclass] -#[derive(Debug, Clone, PartialEq, Eq)] +#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize)] pub struct IGetShort { #[pyo3(get)] pub to: u8, @@ -10994,6 +11592,15 @@ pub struct IGetShort { #[pymethods] impl IGetShort { + pub fn to_json(&self) -> Result { + Ok(serde_json::to_string(self)?) + } + + #[staticmethod] + pub fn from_json(json: &str) -> Result { + Ok(serde_json::from_str(json)?) + } + #[new] pub fn new(to: u8, obj: u8, field: IdField) -> Result { let ins = Self { to, obj, field }; @@ -11118,7 +11725,7 @@ impl IGetShort { /// /// The registers 'from' and 'obj' are idexed on 4 bits. #[pyclass] -#[derive(Debug, Clone, PartialEq, Eq)] +#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize)] pub struct IPut { #[pyo3(get)] pub from: u8, @@ -11130,6 +11737,15 @@ pub struct IPut { #[pymethods] impl IPut { + pub fn to_json(&self) -> Result { + Ok(serde_json::to_string(self)?) + } + + #[staticmethod] + pub fn from_json(json: &str) -> Result { + Ok(serde_json::from_str(json)?) + } + #[new] pub fn new(from: u8, obj: u8, field: IdField) -> Result { let ins = Self { from, obj, field }; @@ -11250,7 +11866,7 @@ impl IPut { /// /// The registers 'from' and 'obj' are idexed on 4 bits. #[pyclass] -#[derive(Debug, Clone, PartialEq, Eq)] +#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize)] pub struct IPutWide { #[pyo3(get)] pub from: u8, @@ -11262,6 +11878,15 @@ pub struct IPutWide { #[pymethods] impl IPutWide { + pub fn to_json(&self) -> Result { + Ok(serde_json::to_string(self)?) + } + + #[staticmethod] + pub fn from_json(json: &str) -> Result { + Ok(serde_json::from_str(json)?) + } + #[new] pub fn new(from: u8, obj: u8, field: IdField) -> Result { let ins = Self { from, obj, field }; @@ -11386,7 +12011,7 @@ impl IPutWide { /// /// The registers 'from' and 'obj' are idexed on 4 bits. #[pyclass] -#[derive(Debug, Clone, PartialEq, Eq)] +#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize)] pub struct IPutObject { #[pyo3(get)] pub from: u8, @@ -11398,6 +12023,15 @@ pub struct IPutObject { #[pymethods] impl IPutObject { + pub fn to_json(&self) -> Result { + Ok(serde_json::to_string(self)?) + } + + #[staticmethod] + pub fn from_json(json: &str) -> Result { + Ok(serde_json::from_str(json)?) + } + #[new] pub fn new(from: u8, obj: u8, field: IdField) -> Result { let ins = Self { from, obj, field }; @@ -11522,7 +12156,7 @@ impl IPutObject { /// /// The registers 'from' and 'obj' are idexed on 4 bits. #[pyclass] -#[derive(Debug, Clone, PartialEq, Eq)] +#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize)] pub struct IPutBoolean { #[pyo3(get)] pub from: u8, @@ -11534,6 +12168,15 @@ pub struct IPutBoolean { #[pymethods] impl IPutBoolean { + pub fn to_json(&self) -> Result { + Ok(serde_json::to_string(self)?) + } + + #[staticmethod] + pub fn from_json(json: &str) -> Result { + Ok(serde_json::from_str(json)?) + } + #[new] pub fn new(from: u8, obj: u8, field: IdField) -> Result { let ins = Self { from, obj, field }; @@ -11658,7 +12301,7 @@ impl IPutBoolean { /// /// The registers 'from' and 'obj' are idexed on 4 bits. #[pyclass] -#[derive(Debug, Clone, PartialEq, Eq)] +#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize)] pub struct IPutByte { #[pyo3(get)] pub from: u8, @@ -11670,6 +12313,15 @@ pub struct IPutByte { #[pymethods] impl IPutByte { + pub fn to_json(&self) -> Result { + Ok(serde_json::to_string(self)?) + } + + #[staticmethod] + pub fn from_json(json: &str) -> Result { + Ok(serde_json::from_str(json)?) + } + #[new] pub fn new(from: u8, obj: u8, field: IdField) -> Result { let ins = Self { from, obj, field }; @@ -11794,7 +12446,7 @@ impl IPutByte { /// /// The registers 'from' and 'obj' are idexed on 4 bits. #[pyclass] -#[derive(Debug, Clone, PartialEq, Eq)] +#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize)] pub struct IPutChar { #[pyo3(get)] pub from: u8, @@ -11806,6 +12458,15 @@ pub struct IPutChar { #[pymethods] impl IPutChar { + pub fn to_json(&self) -> Result { + Ok(serde_json::to_string(self)?) + } + + #[staticmethod] + pub fn from_json(json: &str) -> Result { + Ok(serde_json::from_str(json)?) + } + #[new] pub fn new(from: u8, obj: u8, field: IdField) -> Result { let ins = Self { from, obj, field }; @@ -11930,7 +12591,7 @@ impl IPutChar { /// /// The registers 'from' and 'obj' are idexed on 4 bits. #[pyclass] -#[derive(Debug, Clone, PartialEq, Eq)] +#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize)] pub struct IPutShort { #[pyo3(get)] pub from: u8, @@ -11942,6 +12603,15 @@ pub struct IPutShort { #[pymethods] impl IPutShort { + pub fn to_json(&self) -> Result { + Ok(serde_json::to_string(self)?) + } + + #[staticmethod] + pub fn from_json(json: &str) -> Result { + Ok(serde_json::from_str(json)?) + } + #[new] pub fn new(from: u8, obj: u8, field: IdField) -> Result { let ins = Self { from, obj, field }; @@ -12064,7 +12734,7 @@ impl IPutShort { /// Put the value in 'to' in the static field 'field' ('to' is a register) #[pyclass] -#[derive(Debug, Clone, PartialEq, Eq)] +#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize)] pub struct SGet { #[pyo3(get)] pub to: u8, @@ -12074,6 +12744,15 @@ pub struct SGet { #[pymethods] impl SGet { + pub fn to_json(&self) -> Result { + Ok(serde_json::to_string(self)?) + } + + #[staticmethod] + pub fn from_json(json: &str) -> Result { + Ok(serde_json::from_str(json)?) + } + #[new] pub fn new(to: u8, field: IdField) -> Self { Self { to, field } @@ -12167,7 +12846,7 @@ impl SGet { /// Put the value in the register pair 'to' in the static field 'field' ('to' is a register) #[pyclass] -#[derive(Debug, Clone, PartialEq, Eq)] +#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize)] pub struct SGetWide { #[pyo3(get)] pub to: u8, @@ -12177,6 +12856,15 @@ pub struct SGetWide { #[pymethods] impl SGetWide { + pub fn to_json(&self) -> Result { + Ok(serde_json::to_string(self)?) + } + + #[staticmethod] + pub fn from_json(json: &str) -> Result { + Ok(serde_json::from_str(json)?) + } + #[new] pub fn new(to: u8, field: IdField) -> Self { Self { to, field } @@ -12274,7 +12962,7 @@ impl SGetWide { /// Put the object reference 'to' in the static field 'field' ('to' is a register) #[pyclass] -#[derive(Debug, Clone, PartialEq, Eq)] +#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize)] pub struct SGetObject { #[pyo3(get)] pub to: u8, @@ -12284,6 +12972,15 @@ pub struct SGetObject { #[pymethods] impl SGetObject { + pub fn to_json(&self) -> Result { + Ok(serde_json::to_string(self)?) + } + + #[staticmethod] + pub fn from_json(json: &str) -> Result { + Ok(serde_json::from_str(json)?) + } + #[new] pub fn new(to: u8, field: IdField) -> Self { Self { to, field } @@ -12381,7 +13078,7 @@ impl SGetObject { /// Put the boolean in 'to' in the static field 'field' ('to' is a register) #[pyclass] -#[derive(Debug, Clone, PartialEq, Eq)] +#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize)] pub struct SGetBoolean { #[pyo3(get)] pub to: u8, @@ -12391,6 +13088,15 @@ pub struct SGetBoolean { #[pymethods] impl SGetBoolean { + pub fn to_json(&self) -> Result { + Ok(serde_json::to_string(self)?) + } + + #[staticmethod] + pub fn from_json(json: &str) -> Result { + Ok(serde_json::from_str(json)?) + } + #[new] pub fn new(to: u8, field: IdField) -> Self { Self { to, field } @@ -12488,7 +13194,7 @@ impl SGetBoolean { /// Put the byte in 'to' in the static field 'field' ('to' is a register) #[pyclass] -#[derive(Debug, Clone, PartialEq, Eq)] +#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize)] pub struct SGetByte { #[pyo3(get)] pub to: u8, @@ -12498,6 +13204,15 @@ pub struct SGetByte { #[pymethods] impl SGetByte { + pub fn to_json(&self) -> Result { + Ok(serde_json::to_string(self)?) + } + + #[staticmethod] + pub fn from_json(json: &str) -> Result { + Ok(serde_json::from_str(json)?) + } + #[new] pub fn new(to: u8, field: IdField) -> Self { Self { to, field } @@ -12595,7 +13310,7 @@ impl SGetByte { /// Put the char in 'to' in the static field 'field' ('to' is a register) #[pyclass] -#[derive(Debug, Clone, PartialEq, Eq)] +#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize)] pub struct SGetChar { #[pyo3(get)] pub to: u8, @@ -12605,6 +13320,15 @@ pub struct SGetChar { #[pymethods] impl SGetChar { + pub fn to_json(&self) -> Result { + Ok(serde_json::to_string(self)?) + } + + #[staticmethod] + pub fn from_json(json: &str) -> Result { + Ok(serde_json::from_str(json)?) + } + #[new] pub fn new(to: u8, field: IdField) -> Self { Self { to, field } @@ -12702,7 +13426,7 @@ impl SGetChar { /// Put the short in 'to' in the static field 'field' ('to' is a register) #[pyclass] -#[derive(Debug, Clone, PartialEq, Eq)] +#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize)] pub struct SGetShort { #[pyo3(get)] pub to: u8, @@ -12712,6 +13436,15 @@ pub struct SGetShort { #[pymethods] impl SGetShort { + pub fn to_json(&self) -> Result { + Ok(serde_json::to_string(self)?) + } + + #[staticmethod] + pub fn from_json(json: &str) -> Result { + Ok(serde_json::from_str(json)?) + } + #[new] pub fn new(to: u8, field: IdField) -> Self { Self { to, field } @@ -12809,7 +13542,7 @@ impl SGetShort { /// Put the value in the static field 'field' in 'from' ('from' is a register) #[pyclass] -#[derive(Debug, Clone, PartialEq, Eq)] +#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize)] pub struct SPut { #[pyo3(get)] pub from: u8, @@ -12819,6 +13552,15 @@ pub struct SPut { #[pymethods] impl SPut { + pub fn to_json(&self) -> Result { + Ok(serde_json::to_string(self)?) + } + + #[staticmethod] + pub fn from_json(json: &str) -> Result { + Ok(serde_json::from_str(json)?) + } + #[new] pub fn new(from: u8, field: IdField) -> Self { Self { from, field } @@ -12917,7 +13659,7 @@ impl SPut { /// Put the value in the static field 'field' in the register pair 'from' /// ('from' is a register) #[pyclass] -#[derive(Debug, Clone, PartialEq, Eq)] +#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize)] pub struct SPutWide { #[pyo3(get)] pub from: u8, @@ -12927,6 +13669,15 @@ pub struct SPutWide { #[pymethods] impl SPutWide { + pub fn to_json(&self) -> Result { + Ok(serde_json::to_string(self)?) + } + + #[staticmethod] + pub fn from_json(json: &str) -> Result { + Ok(serde_json::from_str(json)?) + } + #[new] pub fn new(from: u8, field: IdField) -> Self { Self { from, field } @@ -13024,7 +13775,7 @@ impl SPutWide { /// Put the object reference in the static field 'field' in 'from' ('from' is a register) #[pyclass] -#[derive(Debug, Clone, PartialEq, Eq)] +#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize)] pub struct SPutObject { #[pyo3(get)] pub from: u8, @@ -13034,6 +13785,15 @@ pub struct SPutObject { #[pymethods] impl SPutObject { + pub fn to_json(&self) -> Result { + Ok(serde_json::to_string(self)?) + } + + #[staticmethod] + pub fn from_json(json: &str) -> Result { + Ok(serde_json::from_str(json)?) + } + #[new] pub fn new(from: u8, field: IdField) -> Self { Self { from, field } @@ -13131,7 +13891,7 @@ impl SPutObject { /// Put the boolean in the static field 'field' in 'from' ('from' is a register) #[pyclass] -#[derive(Debug, Clone, PartialEq, Eq)] +#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize)] pub struct SPutBoolean { #[pyo3(get)] pub from: u8, @@ -13141,6 +13901,15 @@ pub struct SPutBoolean { #[pymethods] impl SPutBoolean { + pub fn to_json(&self) -> Result { + Ok(serde_json::to_string(self)?) + } + + #[staticmethod] + pub fn from_json(json: &str) -> Result { + Ok(serde_json::from_str(json)?) + } + #[new] pub fn new(from: u8, field: IdField) -> Self { Self { from, field } @@ -13238,7 +14007,7 @@ impl SPutBoolean { /// Put the byte in the static field 'field' in 'from' ('from' is a register) #[pyclass] -#[derive(Debug, Clone, PartialEq, Eq)] +#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize)] pub struct SPutByte { #[pyo3(get)] pub from: u8, @@ -13248,6 +14017,15 @@ pub struct SPutByte { #[pymethods] impl SPutByte { + pub fn to_json(&self) -> Result { + Ok(serde_json::to_string(self)?) + } + + #[staticmethod] + pub fn from_json(json: &str) -> Result { + Ok(serde_json::from_str(json)?) + } + #[new] pub fn new(from: u8, field: IdField) -> Self { Self { from, field } @@ -13345,7 +14123,7 @@ impl SPutByte { /// Put the char in the static field 'field' in 'from' ('from' is a register) #[pyclass] -#[derive(Debug, Clone, PartialEq, Eq)] +#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize)] pub struct SPutChar { #[pyo3(get)] pub from: u8, @@ -13355,6 +14133,15 @@ pub struct SPutChar { #[pymethods] impl SPutChar { + pub fn to_json(&self) -> Result { + Ok(serde_json::to_string(self)?) + } + + #[staticmethod] + pub fn from_json(json: &str) -> Result { + Ok(serde_json::from_str(json)?) + } + #[new] pub fn new(from: u8, field: IdField) -> Self { Self { from, field } @@ -13452,7 +14239,7 @@ impl SPutChar { /// Put the short in the static field 'field' in 'from' ('from' is a register) #[pyclass] -#[derive(Debug, Clone, PartialEq, Eq)] +#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize)] pub struct SPutShort { #[pyo3(get)] pub from: u8, @@ -13462,6 +14249,15 @@ pub struct SPutShort { #[pymethods] impl SPutShort { + pub fn to_json(&self) -> Result { + Ok(serde_json::to_string(self)?) + } + + #[staticmethod] + pub fn from_json(json: &str) -> Result { + Ok(serde_json::from_str(json)?) + } + #[new] pub fn new(from: u8, field: IdField) -> Self { Self { from, field } @@ -13559,7 +14355,7 @@ impl SPutShort { /// Call a normal virtual method. #[pyclass] -#[derive(Debug, Clone, PartialEq, Eq)] +#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize)] pub struct InvokeVirtual { #[pyo3(get)] pub method: IdMethod, @@ -13569,6 +14365,15 @@ pub struct InvokeVirtual { #[pymethods] impl InvokeVirtual { + pub fn to_json(&self) -> Result { + Ok(serde_json::to_string(self)?) + } + + #[staticmethod] + pub fn from_json(json: &str) -> Result { + Ok(serde_json::from_str(json)?) + } + #[new] pub fn new(method: IdMethod, args: Vec) -> Result { let invoke = Self { method, args }; @@ -13766,7 +14571,7 @@ impl InvokeVirtual { /// Call the closest superclass's virtual method of a non interface class. #[pyclass] -#[derive(Debug, Clone, PartialEq, Eq)] +#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize)] pub struct InvokeSuper { #[pyo3(get)] pub method: IdMethod, @@ -13776,6 +14581,15 @@ pub struct InvokeSuper { #[pymethods] impl InvokeSuper { + pub fn to_json(&self) -> Result { + Ok(serde_json::to_string(self)?) + } + + #[staticmethod] + pub fn from_json(json: &str) -> Result { + Ok(serde_json::from_str(json)?) + } + #[new] pub fn new(method: IdMethod, args: Vec) -> Result { let invoke = Self { method, args }; @@ -13973,7 +14787,7 @@ impl InvokeSuper { /// Call a direct method (non static non overridable, like private). #[pyclass] -#[derive(Debug, Clone, PartialEq, Eq)] +#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize)] pub struct InvokeDirect { #[pyo3(get)] pub method: IdMethod, @@ -13983,6 +14797,15 @@ pub struct InvokeDirect { #[pymethods] impl InvokeDirect { + pub fn to_json(&self) -> Result { + Ok(serde_json::to_string(self)?) + } + + #[staticmethod] + pub fn from_json(json: &str) -> Result { + Ok(serde_json::from_str(json)?) + } + #[new] pub fn new(method: IdMethod, args: Vec) -> Result { let invoke = Self { method, args }; @@ -14180,7 +15003,7 @@ impl InvokeDirect { /// Call a static method. #[pyclass] -#[derive(Debug, Clone, PartialEq, Eq)] +#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize)] pub struct InvokeStatic { #[pyo3(get)] pub method: IdMethod, @@ -14190,6 +15013,15 @@ pub struct InvokeStatic { #[pymethods] impl InvokeStatic { + pub fn to_json(&self) -> Result { + Ok(serde_json::to_string(self)?) + } + + #[staticmethod] + pub fn from_json(json: &str) -> Result { + Ok(serde_json::from_str(json)?) + } + #[new] pub fn new(method: IdMethod, args: Vec) -> Result { let invoke = Self { method, args }; @@ -14387,7 +15219,7 @@ impl InvokeStatic { /// Call a interface method (method from an interface on an object whose class is unknown) #[pyclass] -#[derive(Debug, Clone, PartialEq, Eq)] +#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize)] pub struct InvokeInterface { #[pyo3(get)] pub method: IdMethod, @@ -14397,6 +15229,15 @@ pub struct InvokeInterface { #[pymethods] impl InvokeInterface { + pub fn to_json(&self) -> Result { + Ok(serde_json::to_string(self)?) + } + + #[staticmethod] + pub fn from_json(json: &str) -> Result { + Ok(serde_json::from_str(json)?) + } + #[new] pub fn new(method: IdMethod, args: Vec) -> Result { let invoke = Self { method, args }; @@ -14596,7 +15437,7 @@ impl InvokeInterface { /// /// `dest` and `val` are registered indexed on 4 bits. #[pyclass] -#[derive(Debug, Clone, Copy, PartialEq, Eq)] +#[derive(Debug, Clone, Copy, PartialEq, Eq, Deserialize, Serialize)] pub struct NegInt { dest: u8, val: u8, @@ -14604,6 +15445,15 @@ pub struct NegInt { #[pymethods] impl NegInt { + pub fn to_json(&self) -> Result { + Ok(serde_json::to_string(self)?) + } + + #[staticmethod] + pub fn from_json(json: &str) -> Result { + Ok(serde_json::from_str(json)?) + } + #[new] pub fn new(dest: u8, val: u8) -> Result { let ins = Self { dest, val }; @@ -14713,7 +15563,7 @@ impl NegInt { /// /// `dest` and `val` are registered indexed on 4 bits. #[pyclass] -#[derive(Debug, Clone, Copy, PartialEq, Eq)] +#[derive(Debug, Clone, Copy, PartialEq, Eq, Deserialize, Serialize)] pub struct NotInt { dest: u8, val: u8, @@ -14721,6 +15571,15 @@ pub struct NotInt { #[pymethods] impl NotInt { + pub fn to_json(&self) -> Result { + Ok(serde_json::to_string(self)?) + } + + #[staticmethod] + pub fn from_json(json: &str) -> Result { + Ok(serde_json::from_str(json)?) + } + #[new] pub fn new(dest: u8, val: u8) -> Result { let ins = Self { dest, val }; @@ -14830,7 +15689,7 @@ impl NotInt { /// /// `dest` and `val` are registered indexed on 4 bits. #[pyclass] -#[derive(Debug, Clone, Copy, PartialEq, Eq)] +#[derive(Debug, Clone, Copy, PartialEq, Eq, Deserialize, Serialize)] pub struct NegLong { dest: u8, val: u8, @@ -14838,6 +15697,15 @@ pub struct NegLong { #[pymethods] impl NegLong { + pub fn to_json(&self) -> Result { + Ok(serde_json::to_string(self)?) + } + + #[staticmethod] + pub fn from_json(json: &str) -> Result { + Ok(serde_json::from_str(json)?) + } + #[new] pub fn new(dest: u8, val: u8) -> Result { let ins = Self { dest, val }; @@ -14947,7 +15815,7 @@ impl NegLong { /// /// `dest` and `val` are registered indexed on 4 bits. #[pyclass] -#[derive(Debug, Clone, Copy, PartialEq, Eq)] +#[derive(Debug, Clone, Copy, PartialEq, Eq, Deserialize, Serialize)] pub struct NotLong { dest: u8, val: u8, @@ -14955,6 +15823,15 @@ pub struct NotLong { #[pymethods] impl NotLong { + pub fn to_json(&self) -> Result { + Ok(serde_json::to_string(self)?) + } + + #[staticmethod] + pub fn from_json(json: &str) -> Result { + Ok(serde_json::from_str(json)?) + } + #[new] pub fn new(dest: u8, val: u8) -> Result { let ins = Self { dest, val }; @@ -15064,7 +15941,7 @@ impl NotLong { /// /// `dest` and `val` are registered indexed on 4 bits. #[pyclass] -#[derive(Debug, Clone, Copy, PartialEq, Eq)] +#[derive(Debug, Clone, Copy, PartialEq, Eq, Deserialize, Serialize)] pub struct NegFloat { dest: u8, val: u8, @@ -15072,6 +15949,15 @@ pub struct NegFloat { #[pymethods] impl NegFloat { + pub fn to_json(&self) -> Result { + Ok(serde_json::to_string(self)?) + } + + #[staticmethod] + pub fn from_json(json: &str) -> Result { + Ok(serde_json::from_str(json)?) + } + #[new] pub fn new(dest: u8, val: u8) -> Result { let ins = Self { dest, val }; @@ -15181,7 +16067,7 @@ impl NegFloat { /// /// `dest` and `val` are registered indexed on 4 bits. #[pyclass] -#[derive(Debug, Clone, Copy, PartialEq, Eq)] +#[derive(Debug, Clone, Copy, PartialEq, Eq, Deserialize, Serialize)] pub struct NegDouble { dest: u8, val: u8, @@ -15189,6 +16075,15 @@ pub struct NegDouble { #[pymethods] impl NegDouble { + pub fn to_json(&self) -> Result { + Ok(serde_json::to_string(self)?) + } + + #[staticmethod] + pub fn from_json(json: &str) -> Result { + Ok(serde_json::from_str(json)?) + } + #[new] pub fn new(dest: u8, val: u8) -> Result { let ins = Self { dest, val }; @@ -15300,7 +16195,7 @@ impl NegDouble { /// /// `dest` and `val` are registered indexed on 4 bits. #[pyclass] -#[derive(Debug, Clone, Copy, PartialEq, Eq)] +#[derive(Debug, Clone, Copy, PartialEq, Eq, Deserialize, Serialize)] pub struct IntToLong { dest: u8, val: u8, @@ -15308,6 +16203,15 @@ pub struct IntToLong { #[pymethods] impl IntToLong { + pub fn to_json(&self) -> Result { + Ok(serde_json::to_string(self)?) + } + + #[staticmethod] + pub fn from_json(json: &str) -> Result { + Ok(serde_json::from_str(json)?) + } + #[new] pub fn new(dest: u8, val: u8) -> Result { let ins = Self { dest, val }; @@ -15417,7 +16321,7 @@ impl IntToLong { /// /// `dest` and `val` are registered indexed on 4 bits. #[pyclass] -#[derive(Debug, Clone, Copy, PartialEq, Eq)] +#[derive(Debug, Clone, Copy, PartialEq, Eq, Deserialize, Serialize)] pub struct IntToFloat { dest: u8, val: u8, @@ -15425,6 +16329,15 @@ pub struct IntToFloat { #[pymethods] impl IntToFloat { + pub fn to_json(&self) -> Result { + Ok(serde_json::to_string(self)?) + } + + #[staticmethod] + pub fn from_json(json: &str) -> Result { + Ok(serde_json::from_str(json)?) + } + #[new] pub fn new(dest: u8, val: u8) -> Result { let ins = Self { dest, val }; @@ -15536,7 +16449,7 @@ impl IntToFloat { /// /// `dest` and `val` are registered indexed on 4 bits. #[pyclass] -#[derive(Debug, Clone, Copy, PartialEq, Eq)] +#[derive(Debug, Clone, Copy, PartialEq, Eq, Deserialize, Serialize)] pub struct IntToDouble { dest: u8, val: u8, @@ -15544,6 +16457,15 @@ pub struct IntToDouble { #[pymethods] impl IntToDouble { + pub fn to_json(&self) -> Result { + Ok(serde_json::to_string(self)?) + } + + #[staticmethod] + pub fn from_json(json: &str) -> Result { + Ok(serde_json::from_str(json)?) + } + #[new] pub fn new(dest: u8, val: u8) -> Result { let ins = Self { dest, val }; @@ -15655,7 +16577,7 @@ impl IntToDouble { /// /// `dest` and `val` are registered indexed on 4 bits. #[pyclass] -#[derive(Debug, Clone, Copy, PartialEq, Eq)] +#[derive(Debug, Clone, Copy, PartialEq, Eq, Deserialize, Serialize)] pub struct LongToInt { dest: u8, val: u8, @@ -15663,6 +16585,15 @@ pub struct LongToInt { #[pymethods] impl LongToInt { + pub fn to_json(&self) -> Result { + Ok(serde_json::to_string(self)?) + } + + #[staticmethod] + pub fn from_json(json: &str) -> Result { + Ok(serde_json::from_str(json)?) + } + #[new] pub fn new(dest: u8, val: u8) -> Result { let ins = Self { dest, val }; @@ -15774,7 +16705,7 @@ impl LongToInt { /// /// `dest` and `val` are registered indexed on 4 bits. #[pyclass] -#[derive(Debug, Clone, Copy, PartialEq, Eq)] +#[derive(Debug, Clone, Copy, PartialEq, Eq, Deserialize, Serialize)] pub struct LongToFloat { dest: u8, val: u8, @@ -15782,6 +16713,15 @@ pub struct LongToFloat { #[pymethods] impl LongToFloat { + pub fn to_json(&self) -> Result { + Ok(serde_json::to_string(self)?) + } + + #[staticmethod] + pub fn from_json(json: &str) -> Result { + Ok(serde_json::from_str(json)?) + } + #[new] pub fn new(dest: u8, val: u8) -> Result { let ins = Self { dest, val }; @@ -15893,7 +16833,7 @@ impl LongToFloat { /// /// `dest` and `val` are registered indexed on 4 bits. #[pyclass] -#[derive(Debug, Clone, Copy, PartialEq, Eq)] +#[derive(Debug, Clone, Copy, PartialEq, Eq, Deserialize, Serialize)] pub struct LongToDouble { dest: u8, val: u8, @@ -15901,6 +16841,15 @@ pub struct LongToDouble { #[pymethods] impl LongToDouble { + pub fn to_json(&self) -> Result { + Ok(serde_json::to_string(self)?) + } + + #[staticmethod] + pub fn from_json(json: &str) -> Result { + Ok(serde_json::from_str(json)?) + } + #[new] pub fn new(dest: u8, val: u8) -> Result { let ins = Self { dest, val }; @@ -16010,7 +16959,7 @@ impl LongToDouble { /// /// `dest` and `val` are registered indexed on 4 bits. #[pyclass] -#[derive(Debug, Clone, Copy, PartialEq, Eq)] +#[derive(Debug, Clone, Copy, PartialEq, Eq, Deserialize, Serialize)] pub struct FloatToInt { dest: u8, val: u8, @@ -16018,6 +16967,15 @@ pub struct FloatToInt { #[pymethods] impl FloatToInt { + pub fn to_json(&self) -> Result { + Ok(serde_json::to_string(self)?) + } + + #[staticmethod] + pub fn from_json(json: &str) -> Result { + Ok(serde_json::from_str(json)?) + } + #[new] pub fn new(dest: u8, val: u8) -> Result { let ins = Self { dest, val }; @@ -16129,7 +17087,7 @@ impl FloatToInt { /// /// `dest` and `val` are registered indexed on 4 bits. #[pyclass] -#[derive(Debug, Clone, Copy, PartialEq, Eq)] +#[derive(Debug, Clone, Copy, PartialEq, Eq, Deserialize, Serialize)] pub struct FloatToLong { dest: u8, val: u8, @@ -16137,6 +17095,15 @@ pub struct FloatToLong { #[pymethods] impl FloatToLong { + pub fn to_json(&self) -> Result { + Ok(serde_json::to_string(self)?) + } + + #[staticmethod] + pub fn from_json(json: &str) -> Result { + Ok(serde_json::from_str(json)?) + } + #[new] pub fn new(dest: u8, val: u8) -> Result { let ins = Self { dest, val }; @@ -16248,7 +17215,7 @@ impl FloatToLong { /// /// `dest` and `val` are registered indexed on 4 bits. #[pyclass] -#[derive(Debug, Clone, Copy, PartialEq, Eq)] +#[derive(Debug, Clone, Copy, PartialEq, Eq, Deserialize, Serialize)] pub struct FloatToDouble { dest: u8, val: u8, @@ -16256,6 +17223,15 @@ pub struct FloatToDouble { #[pymethods] impl FloatToDouble { + pub fn to_json(&self) -> Result { + Ok(serde_json::to_string(self)?) + } + + #[staticmethod] + pub fn from_json(json: &str) -> Result { + Ok(serde_json::from_str(json)?) + } + #[new] pub fn new(dest: u8, val: u8) -> Result { let ins = Self { dest, val }; @@ -16367,7 +17343,7 @@ impl FloatToDouble { /// /// `dest` and `val` are registered indexed on 4 bits. #[pyclass] -#[derive(Debug, Clone, Copy, PartialEq, Eq)] +#[derive(Debug, Clone, Copy, PartialEq, Eq, Deserialize, Serialize)] pub struct DoubleToInt { dest: u8, val: u8, @@ -16375,6 +17351,15 @@ pub struct DoubleToInt { #[pymethods] impl DoubleToInt { + pub fn to_json(&self) -> Result { + Ok(serde_json::to_string(self)?) + } + + #[staticmethod] + pub fn from_json(json: &str) -> Result { + Ok(serde_json::from_str(json)?) + } + #[new] pub fn new(dest: u8, val: u8) -> Result { let ins = Self { dest, val }; @@ -16486,7 +17471,7 @@ impl DoubleToInt { /// /// `dest` and `val` are registered indexed on 4 bits. #[pyclass] -#[derive(Debug, Clone, Copy, PartialEq, Eq)] +#[derive(Debug, Clone, Copy, PartialEq, Eq, Deserialize, Serialize)] pub struct DoubleToLong { dest: u8, val: u8, @@ -16494,6 +17479,15 @@ pub struct DoubleToLong { #[pymethods] impl DoubleToLong { + pub fn to_json(&self) -> Result { + Ok(serde_json::to_string(self)?) + } + + #[staticmethod] + pub fn from_json(json: &str) -> Result { + Ok(serde_json::from_str(json)?) + } + #[new] pub fn new(dest: u8, val: u8) -> Result { let ins = Self { dest, val }; @@ -16605,7 +17599,7 @@ impl DoubleToLong { /// /// `dest` and `val` are registered indexed on 4 bits. #[pyclass] -#[derive(Debug, Clone, Copy, PartialEq, Eq)] +#[derive(Debug, Clone, Copy, PartialEq, Eq, Deserialize, Serialize)] pub struct DoubleToFloat { dest: u8, val: u8, @@ -16613,6 +17607,15 @@ pub struct DoubleToFloat { #[pymethods] impl DoubleToFloat { + pub fn to_json(&self) -> Result { + Ok(serde_json::to_string(self)?) + } + + #[staticmethod] + pub fn from_json(json: &str) -> Result { + Ok(serde_json::from_str(json)?) + } + #[new] pub fn new(dest: u8, val: u8) -> Result { let ins = Self { dest, val }; @@ -16722,7 +17725,7 @@ impl DoubleToFloat { /// /// `dest` and `val` are registered indexed on 4 bits. #[pyclass] -#[derive(Debug, Clone, Copy, PartialEq, Eq)] +#[derive(Debug, Clone, Copy, PartialEq, Eq, Deserialize, Serialize)] pub struct IntToByte { dest: u8, val: u8, @@ -16730,6 +17733,15 @@ pub struct IntToByte { #[pymethods] impl IntToByte { + pub fn to_json(&self) -> Result { + Ok(serde_json::to_string(self)?) + } + + #[staticmethod] + pub fn from_json(json: &str) -> Result { + Ok(serde_json::from_str(json)?) + } + #[new] pub fn new(dest: u8, val: u8) -> Result { let ins = Self { dest, val }; @@ -16839,7 +17851,7 @@ impl IntToByte { /// /// `dest` and `val` are registered indexed on 4 bits. #[pyclass] -#[derive(Debug, Clone, Copy, PartialEq, Eq)] +#[derive(Debug, Clone, Copy, PartialEq, Eq, Deserialize, Serialize)] pub struct IntToChar { dest: u8, val: u8, @@ -16847,6 +17859,15 @@ pub struct IntToChar { #[pymethods] impl IntToChar { + pub fn to_json(&self) -> Result { + Ok(serde_json::to_string(self)?) + } + + #[staticmethod] + pub fn from_json(json: &str) -> Result { + Ok(serde_json::from_str(json)?) + } + #[new] pub fn new(dest: u8, val: u8) -> Result { let ins = Self { dest, val }; @@ -16956,7 +17977,7 @@ impl IntToChar { /// /// `dest` and `val` are registered indexed on 4 bits. #[pyclass] -#[derive(Debug, Clone, Copy, PartialEq, Eq)] +#[derive(Debug, Clone, Copy, PartialEq, Eq, Deserialize, Serialize)] pub struct IntToShort { dest: u8, val: u8, @@ -16964,6 +17985,15 @@ pub struct IntToShort { #[pymethods] impl IntToShort { + pub fn to_json(&self) -> Result { + Ok(serde_json::to_string(self)?) + } + + #[staticmethod] + pub fn from_json(json: &str) -> Result { + Ok(serde_json::from_str(json)?) + } + #[new] pub fn new(dest: u8, val: u8) -> Result { let ins = Self { dest, val }; @@ -17071,7 +18101,7 @@ impl IntToShort { /// Put a + b in dest. #[pyclass] -#[derive(Debug, Clone, Copy, PartialEq, Eq)] +#[derive(Debug, Clone, Copy, PartialEq, Eq, Deserialize, Serialize)] pub struct AddInt { dest: u8, b: u8, @@ -17080,6 +18110,15 @@ pub struct AddInt { #[pymethods] impl AddInt { + pub fn to_json(&self) -> Result { + Ok(serde_json::to_string(self)?) + } + + #[staticmethod] + pub fn from_json(json: &str) -> Result { + Ok(serde_json::from_str(json)?) + } + #[new] pub fn new(dest: u8, b: u8, c: u8) -> Self { Self { dest, b, c } @@ -17170,7 +18209,7 @@ impl AddInt { /// Put a - b in dest. #[pyclass] -#[derive(Debug, Clone, Copy, PartialEq, Eq)] +#[derive(Debug, Clone, Copy, PartialEq, Eq, Deserialize, Serialize)] pub struct SubInt { dest: u8, b: u8, @@ -17179,6 +18218,15 @@ pub struct SubInt { #[pymethods] impl SubInt { + pub fn to_json(&self) -> Result { + Ok(serde_json::to_string(self)?) + } + + #[staticmethod] + pub fn from_json(json: &str) -> Result { + Ok(serde_json::from_str(json)?) + } + #[new] pub fn new(dest: u8, b: u8, c: u8) -> Self { Self { dest, b, c } @@ -17269,7 +18317,7 @@ impl SubInt { /// Put a * b in dest. #[pyclass] -#[derive(Debug, Clone, Copy, PartialEq, Eq)] +#[derive(Debug, Clone, Copy, PartialEq, Eq, Deserialize, Serialize)] pub struct MulInt { dest: u8, b: u8, @@ -17278,6 +18326,15 @@ pub struct MulInt { #[pymethods] impl MulInt { + pub fn to_json(&self) -> Result { + Ok(serde_json::to_string(self)?) + } + + #[staticmethod] + pub fn from_json(json: &str) -> Result { + Ok(serde_json::from_str(json)?) + } + #[new] pub fn new(dest: u8, b: u8, c: u8) -> Self { Self { dest, b, c } @@ -17368,7 +18425,7 @@ impl MulInt { /// Put a / b in dest. #[pyclass] -#[derive(Debug, Clone, Copy, PartialEq, Eq)] +#[derive(Debug, Clone, Copy, PartialEq, Eq, Deserialize, Serialize)] pub struct DivInt { dest: u8, b: u8, @@ -17377,6 +18434,15 @@ pub struct DivInt { #[pymethods] impl DivInt { + pub fn to_json(&self) -> Result { + Ok(serde_json::to_string(self)?) + } + + #[staticmethod] + pub fn from_json(json: &str) -> Result { + Ok(serde_json::from_str(json)?) + } + #[new] pub fn new(dest: u8, b: u8, c: u8) -> Self { Self { dest, b, c } @@ -17467,7 +18533,7 @@ impl DivInt { /// Put a % b in dest. #[pyclass] -#[derive(Debug, Clone, Copy, PartialEq, Eq)] +#[derive(Debug, Clone, Copy, PartialEq, Eq, Deserialize, Serialize)] pub struct RemInt { dest: u8, b: u8, @@ -17476,6 +18542,15 @@ pub struct RemInt { #[pymethods] impl RemInt { + pub fn to_json(&self) -> Result { + Ok(serde_json::to_string(self)?) + } + + #[staticmethod] + pub fn from_json(json: &str) -> Result { + Ok(serde_json::from_str(json)?) + } + #[new] pub fn new(dest: u8, b: u8, c: u8) -> Self { Self { dest, b, c } @@ -17566,7 +18641,7 @@ impl RemInt { /// Put a & b in dest. #[pyclass] -#[derive(Debug, Clone, Copy, PartialEq, Eq)] +#[derive(Debug, Clone, Copy, PartialEq, Eq, Deserialize, Serialize)] pub struct AndInt { dest: u8, b: u8, @@ -17575,6 +18650,15 @@ pub struct AndInt { #[pymethods] impl AndInt { + pub fn to_json(&self) -> Result { + Ok(serde_json::to_string(self)?) + } + + #[staticmethod] + pub fn from_json(json: &str) -> Result { + Ok(serde_json::from_str(json)?) + } + #[new] pub fn new(dest: u8, b: u8, c: u8) -> Self { Self { dest, b, c } @@ -17665,7 +18749,7 @@ impl AndInt { /// Put a | b in dest. #[pyclass] -#[derive(Debug, Clone, Copy, PartialEq, Eq)] +#[derive(Debug, Clone, Copy, PartialEq, Eq, Deserialize, Serialize)] pub struct OrInt { dest: u8, b: u8, @@ -17674,6 +18758,15 @@ pub struct OrInt { #[pymethods] impl OrInt { + pub fn to_json(&self) -> Result { + Ok(serde_json::to_string(self)?) + } + + #[staticmethod] + pub fn from_json(json: &str) -> Result { + Ok(serde_json::from_str(json)?) + } + #[new] pub fn new(dest: u8, b: u8, c: u8) -> Self { Self { dest, b, c } @@ -17764,7 +18857,7 @@ impl OrInt { /// Put a ^ b in dest. #[pyclass] -#[derive(Debug, Clone, Copy, PartialEq, Eq)] +#[derive(Debug, Clone, Copy, PartialEq, Eq, Deserialize, Serialize)] pub struct XorInt { dest: u8, b: u8, @@ -17773,6 +18866,15 @@ pub struct XorInt { #[pymethods] impl XorInt { + pub fn to_json(&self) -> Result { + Ok(serde_json::to_string(self)?) + } + + #[staticmethod] + pub fn from_json(json: &str) -> Result { + Ok(serde_json::from_str(json)?) + } + #[new] pub fn new(dest: u8, b: u8, c: u8) -> Self { Self { dest, b, c } @@ -17863,7 +18965,7 @@ impl XorInt { /// Put a << b in dest. #[pyclass] -#[derive(Debug, Clone, Copy, PartialEq, Eq)] +#[derive(Debug, Clone, Copy, PartialEq, Eq, Deserialize, Serialize)] pub struct ShlInt { dest: u8, b: u8, @@ -17872,6 +18974,15 @@ pub struct ShlInt { #[pymethods] impl ShlInt { + pub fn to_json(&self) -> Result { + Ok(serde_json::to_string(self)?) + } + + #[staticmethod] + pub fn from_json(json: &str) -> Result { + Ok(serde_json::from_str(json)?) + } + #[new] pub fn new(dest: u8, b: u8, c: u8) -> Self { Self { dest, b, c } @@ -17962,7 +19073,7 @@ impl ShlInt { /// Put a >> b (signed) in dest. #[pyclass] -#[derive(Debug, Clone, Copy, PartialEq, Eq)] +#[derive(Debug, Clone, Copy, PartialEq, Eq, Deserialize, Serialize)] pub struct ShrInt { dest: u8, b: u8, @@ -17971,6 +19082,15 @@ pub struct ShrInt { #[pymethods] impl ShrInt { + pub fn to_json(&self) -> Result { + Ok(serde_json::to_string(self)?) + } + + #[staticmethod] + pub fn from_json(json: &str) -> Result { + Ok(serde_json::from_str(json)?) + } + #[new] pub fn new(dest: u8, b: u8, c: u8) -> Self { Self { dest, b, c } @@ -18061,7 +19181,7 @@ impl ShrInt { /// Put a >> b in dest. #[pyclass] -#[derive(Debug, Clone, Copy, PartialEq, Eq)] +#[derive(Debug, Clone, Copy, PartialEq, Eq, Deserialize, Serialize)] pub struct UshrInt { dest: u8, b: u8, @@ -18070,6 +19190,15 @@ pub struct UshrInt { #[pymethods] impl UshrInt { + pub fn to_json(&self) -> Result { + Ok(serde_json::to_string(self)?) + } + + #[staticmethod] + pub fn from_json(json: &str) -> Result { + Ok(serde_json::from_str(json)?) + } + #[new] pub fn new(dest: u8, b: u8, c: u8) -> Self { Self { dest, b, c } @@ -18165,7 +19294,7 @@ impl UshrInt { /// /// dest, b and c are register pairs #[pyclass] -#[derive(Debug, Clone, Copy, PartialEq, Eq)] +#[derive(Debug, Clone, Copy, PartialEq, Eq, Deserialize, Serialize)] pub struct AddLong { dest: u8, b: u8, @@ -18174,6 +19303,15 @@ pub struct AddLong { #[pymethods] impl AddLong { + pub fn to_json(&self) -> Result { + Ok(serde_json::to_string(self)?) + } + + #[staticmethod] + pub fn from_json(json: &str) -> Result { + Ok(serde_json::from_str(json)?) + } + #[new] pub fn new(dest: u8, b: u8, c: u8) -> Self { Self { dest, b, c } @@ -18269,7 +19407,7 @@ impl AddLong { /// /// dest, b and c are register pairs #[pyclass] -#[derive(Debug, Clone, Copy, PartialEq, Eq)] +#[derive(Debug, Clone, Copy, PartialEq, Eq, Deserialize, Serialize)] pub struct SubLong { dest: u8, b: u8, @@ -18278,6 +19416,15 @@ pub struct SubLong { #[pymethods] impl SubLong { + pub fn to_json(&self) -> Result { + Ok(serde_json::to_string(self)?) + } + + #[staticmethod] + pub fn from_json(json: &str) -> Result { + Ok(serde_json::from_str(json)?) + } + #[new] pub fn new(dest: u8, b: u8, c: u8) -> Self { Self { dest, b, c } @@ -18373,7 +19520,7 @@ impl SubLong { /// /// dest, b and c are register pairs #[pyclass] -#[derive(Debug, Clone, Copy, PartialEq, Eq)] +#[derive(Debug, Clone, Copy, PartialEq, Eq, Deserialize, Serialize)] pub struct MulLong { dest: u8, b: u8, @@ -18382,6 +19529,15 @@ pub struct MulLong { #[pymethods] impl MulLong { + pub fn to_json(&self) -> Result { + Ok(serde_json::to_string(self)?) + } + + #[staticmethod] + pub fn from_json(json: &str) -> Result { + Ok(serde_json::from_str(json)?) + } + #[new] pub fn new(dest: u8, b: u8, c: u8) -> Self { Self { dest, b, c } @@ -18477,7 +19633,7 @@ impl MulLong { /// /// dest, b and c are register pairs #[pyclass] -#[derive(Debug, Clone, Copy, PartialEq, Eq)] +#[derive(Debug, Clone, Copy, PartialEq, Eq, Deserialize, Serialize)] pub struct DivLong { dest: u8, b: u8, @@ -18486,6 +19642,15 @@ pub struct DivLong { #[pymethods] impl DivLong { + pub fn to_json(&self) -> Result { + Ok(serde_json::to_string(self)?) + } + + #[staticmethod] + pub fn from_json(json: &str) -> Result { + Ok(serde_json::from_str(json)?) + } + #[new] pub fn new(dest: u8, b: u8, c: u8) -> Self { Self { dest, b, c } @@ -18581,7 +19746,7 @@ impl DivLong { /// /// dest, b and c are register pairs #[pyclass] -#[derive(Debug, Clone, Copy, PartialEq, Eq)] +#[derive(Debug, Clone, Copy, PartialEq, Eq, Deserialize, Serialize)] pub struct RemLong { dest: u8, b: u8, @@ -18590,6 +19755,15 @@ pub struct RemLong { #[pymethods] impl RemLong { + pub fn to_json(&self) -> Result { + Ok(serde_json::to_string(self)?) + } + + #[staticmethod] + pub fn from_json(json: &str) -> Result { + Ok(serde_json::from_str(json)?) + } + #[new] pub fn new(dest: u8, b: u8, c: u8) -> Self { Self { dest, b, c } @@ -18685,7 +19859,7 @@ impl RemLong { /// /// dest, b and c are register pairs #[pyclass] -#[derive(Debug, Clone, Copy, PartialEq, Eq)] +#[derive(Debug, Clone, Copy, PartialEq, Eq, Deserialize, Serialize)] pub struct AndLong { dest: u8, b: u8, @@ -18694,6 +19868,15 @@ pub struct AndLong { #[pymethods] impl AndLong { + pub fn to_json(&self) -> Result { + Ok(serde_json::to_string(self)?) + } + + #[staticmethod] + pub fn from_json(json: &str) -> Result { + Ok(serde_json::from_str(json)?) + } + #[new] pub fn new(dest: u8, b: u8, c: u8) -> Self { Self { dest, b, c } @@ -18789,7 +19972,7 @@ impl AndLong { /// /// dest, b and c are register pairs #[pyclass] -#[derive(Debug, Clone, Copy, PartialEq, Eq)] +#[derive(Debug, Clone, Copy, PartialEq, Eq, Deserialize, Serialize)] pub struct OrLong { dest: u8, b: u8, @@ -18798,6 +19981,15 @@ pub struct OrLong { #[pymethods] impl OrLong { + pub fn to_json(&self) -> Result { + Ok(serde_json::to_string(self)?) + } + + #[staticmethod] + pub fn from_json(json: &str) -> Result { + Ok(serde_json::from_str(json)?) + } + #[new] pub fn new(dest: u8, b: u8, c: u8) -> Self { Self { dest, b, c } @@ -18890,7 +20082,7 @@ impl OrLong { /// /// dest, b and c are register pairs #[pyclass] -#[derive(Debug, Clone, Copy, PartialEq, Eq)] +#[derive(Debug, Clone, Copy, PartialEq, Eq, Deserialize, Serialize)] pub struct XorLong { dest: u8, b: u8, @@ -18899,6 +20091,15 @@ pub struct XorLong { #[pymethods] impl XorLong { + pub fn to_json(&self) -> Result { + Ok(serde_json::to_string(self)?) + } + + #[staticmethod] + pub fn from_json(json: &str) -> Result { + Ok(serde_json::from_str(json)?) + } + #[new] pub fn new(dest: u8, b: u8, c: u8) -> Self { Self { dest, b, c } @@ -18994,7 +20195,7 @@ impl XorLong { /// /// dest, and b are register pairs, and c is a single register #[pyclass] -#[derive(Debug, Clone, Copy, PartialEq, Eq)] +#[derive(Debug, Clone, Copy, PartialEq, Eq, Deserialize, Serialize)] pub struct ShlLong { dest: u8, b: u8, @@ -19003,6 +20204,15 @@ pub struct ShlLong { #[pymethods] impl ShlLong { + pub fn to_json(&self) -> Result { + Ok(serde_json::to_string(self)?) + } + + #[staticmethod] + pub fn from_json(json: &str) -> Result { + Ok(serde_json::from_str(json)?) + } + #[new] pub fn new(dest: u8, b: u8, c: u8) -> Self { Self { dest, b, c } @@ -19098,7 +20308,7 @@ impl ShlLong { /// /// dest, and b are register pairs, and c is a single register #[pyclass] -#[derive(Debug, Clone, Copy, PartialEq, Eq)] +#[derive(Debug, Clone, Copy, PartialEq, Eq, Deserialize, Serialize)] pub struct ShrLong { dest: u8, b: u8, @@ -19107,6 +20317,15 @@ pub struct ShrLong { #[pymethods] impl ShrLong { + pub fn to_json(&self) -> Result { + Ok(serde_json::to_string(self)?) + } + + #[staticmethod] + pub fn from_json(json: &str) -> Result { + Ok(serde_json::from_str(json)?) + } + #[new] pub fn new(dest: u8, b: u8, c: u8) -> Self { Self { dest, b, c } @@ -19202,7 +20421,7 @@ impl ShrLong { /// /// dest, and b are register pairs, and c is a single register #[pyclass] -#[derive(Debug, Clone, Copy, PartialEq, Eq)] +#[derive(Debug, Clone, Copy, PartialEq, Eq, Deserialize, Serialize)] pub struct UshrLong { dest: u8, b: u8, @@ -19211,6 +20430,15 @@ pub struct UshrLong { #[pymethods] impl UshrLong { + pub fn to_json(&self) -> Result { + Ok(serde_json::to_string(self)?) + } + + #[staticmethod] + pub fn from_json(json: &str) -> Result { + Ok(serde_json::from_str(json)?) + } + #[new] pub fn new(dest: u8, b: u8, c: u8) -> Self { Self { dest, b, c } @@ -19304,7 +20532,7 @@ impl UshrLong { /// Put a + b in dest. #[pyclass] -#[derive(Debug, Clone, Copy, PartialEq, Eq)] +#[derive(Debug, Clone, Copy, PartialEq, Eq, Deserialize, Serialize)] pub struct AddFloat { dest: u8, b: u8, @@ -19313,6 +20541,15 @@ pub struct AddFloat { #[pymethods] impl AddFloat { + pub fn to_json(&self) -> Result { + Ok(serde_json::to_string(self)?) + } + + #[staticmethod] + pub fn from_json(json: &str) -> Result { + Ok(serde_json::from_str(json)?) + } + #[new] pub fn new(dest: u8, b: u8, c: u8) -> Self { Self { dest, b, c } @@ -19406,7 +20643,7 @@ impl AddFloat { /// Put a - b in dest. #[pyclass] -#[derive(Debug, Clone, Copy, PartialEq, Eq)] +#[derive(Debug, Clone, Copy, PartialEq, Eq, Deserialize, Serialize)] pub struct SubFloat { dest: u8, b: u8, @@ -19415,6 +20652,15 @@ pub struct SubFloat { #[pymethods] impl SubFloat { + pub fn to_json(&self) -> Result { + Ok(serde_json::to_string(self)?) + } + + #[staticmethod] + pub fn from_json(json: &str) -> Result { + Ok(serde_json::from_str(json)?) + } + #[new] pub fn new(dest: u8, b: u8, c: u8) -> Self { Self { dest, b, c } @@ -19508,7 +20754,7 @@ impl SubFloat { /// Put a * b in dest. #[pyclass] -#[derive(Debug, Clone, Copy, PartialEq, Eq)] +#[derive(Debug, Clone, Copy, PartialEq, Eq, Deserialize, Serialize)] pub struct MulFloat { dest: u8, b: u8, @@ -19517,6 +20763,15 @@ pub struct MulFloat { #[pymethods] impl MulFloat { + pub fn to_json(&self) -> Result { + Ok(serde_json::to_string(self)?) + } + + #[staticmethod] + pub fn from_json(json: &str) -> Result { + Ok(serde_json::from_str(json)?) + } + #[new] pub fn new(dest: u8, b: u8, c: u8) -> Self { Self { dest, b, c } @@ -19610,7 +20865,7 @@ impl MulFloat { /// Put a / b in dest. #[pyclass] -#[derive(Debug, Clone, Copy, PartialEq, Eq)] +#[derive(Debug, Clone, Copy, PartialEq, Eq, Deserialize, Serialize)] pub struct DivFloat { dest: u8, b: u8, @@ -19619,6 +20874,15 @@ pub struct DivFloat { #[pymethods] impl DivFloat { + pub fn to_json(&self) -> Result { + Ok(serde_json::to_string(self)?) + } + + #[staticmethod] + pub fn from_json(json: &str) -> Result { + Ok(serde_json::from_str(json)?) + } + #[new] pub fn new(dest: u8, b: u8, c: u8) -> Self { Self { dest, b, c } @@ -19712,7 +20976,7 @@ impl DivFloat { /// Put a % b in dest. #[pyclass] -#[derive(Debug, Clone, Copy, PartialEq, Eq)] +#[derive(Debug, Clone, Copy, PartialEq, Eq, Deserialize, Serialize)] pub struct RemFloat { dest: u8, b: u8, @@ -19721,6 +20985,15 @@ pub struct RemFloat { #[pymethods] impl RemFloat { + pub fn to_json(&self) -> Result { + Ok(serde_json::to_string(self)?) + } + + #[staticmethod] + pub fn from_json(json: &str) -> Result { + Ok(serde_json::from_str(json)?) + } + #[new] pub fn new(dest: u8, b: u8, c: u8) -> Self { Self { dest, b, c } @@ -19816,7 +21089,7 @@ impl RemFloat { /// /// dest, b and c are register pairs #[pyclass] -#[derive(Debug, Clone, Copy, PartialEq, Eq)] +#[derive(Debug, Clone, Copy, PartialEq, Eq, Deserialize, Serialize)] pub struct AddDouble { dest: u8, b: u8, @@ -19825,6 +21098,15 @@ pub struct AddDouble { #[pymethods] impl AddDouble { + pub fn to_json(&self) -> Result { + Ok(serde_json::to_string(self)?) + } + + #[staticmethod] + pub fn from_json(json: &str) -> Result { + Ok(serde_json::from_str(json)?) + } + #[new] pub fn new(dest: u8, b: u8, c: u8) -> Self { Self { dest, b, c } @@ -19920,7 +21202,7 @@ impl AddDouble { /// /// dest, b and c are register pairs #[pyclass] -#[derive(Debug, Clone, Copy, PartialEq, Eq)] +#[derive(Debug, Clone, Copy, PartialEq, Eq, Deserialize, Serialize)] pub struct SubDouble { dest: u8, b: u8, @@ -19929,6 +21211,15 @@ pub struct SubDouble { #[pymethods] impl SubDouble { + pub fn to_json(&self) -> Result { + Ok(serde_json::to_string(self)?) + } + + #[staticmethod] + pub fn from_json(json: &str) -> Result { + Ok(serde_json::from_str(json)?) + } + #[new] pub fn new(dest: u8, b: u8, c: u8) -> Self { Self { dest, b, c } @@ -20024,7 +21315,7 @@ impl SubDouble { /// /// dest, b and c are register pairs #[pyclass] -#[derive(Debug, Clone, Copy, PartialEq, Eq)] +#[derive(Debug, Clone, Copy, PartialEq, Eq, Deserialize, Serialize)] pub struct MulDouble { dest: u8, b: u8, @@ -20033,6 +21324,15 @@ pub struct MulDouble { #[pymethods] impl MulDouble { + pub fn to_json(&self) -> Result { + Ok(serde_json::to_string(self)?) + } + + #[staticmethod] + pub fn from_json(json: &str) -> Result { + Ok(serde_json::from_str(json)?) + } + #[new] pub fn new(dest: u8, b: u8, c: u8) -> Self { Self { dest, b, c } @@ -20128,7 +21428,7 @@ impl MulDouble { /// /// dest, b and c are register pairs #[pyclass] -#[derive(Debug, Clone, Copy, PartialEq, Eq)] +#[derive(Debug, Clone, Copy, PartialEq, Eq, Deserialize, Serialize)] pub struct DivDouble { dest: u8, b: u8, @@ -20137,6 +21437,15 @@ pub struct DivDouble { #[pymethods] impl DivDouble { + pub fn to_json(&self) -> Result { + Ok(serde_json::to_string(self)?) + } + + #[staticmethod] + pub fn from_json(json: &str) -> Result { + Ok(serde_json::from_str(json)?) + } + #[new] pub fn new(dest: u8, b: u8, c: u8) -> Self { Self { dest, b, c } @@ -20232,7 +21541,7 @@ impl DivDouble { /// /// dest, b and c are register pairs #[pyclass] -#[derive(Debug, Clone, Copy, PartialEq, Eq)] +#[derive(Debug, Clone, Copy, PartialEq, Eq, Deserialize, Serialize)] pub struct RemDouble { dest: u8, b: u8, @@ -20241,6 +21550,15 @@ pub struct RemDouble { #[pymethods] impl RemDouble { + pub fn to_json(&self) -> Result { + Ok(serde_json::to_string(self)?) + } + + #[staticmethod] + pub fn from_json(json: &str) -> Result { + Ok(serde_json::from_str(json)?) + } + #[new] pub fn new(dest: u8, b: u8, c: u8) -> Self { Self { dest, b, c } @@ -20336,7 +21654,7 @@ impl RemDouble { /// /// `dest` and `b` are registers indexed on 4 bits #[pyclass] -#[derive(Debug, Clone, Copy, PartialEq, Eq)] +#[derive(Debug, Clone, Copy, PartialEq, Eq, Deserialize, Serialize)] pub struct AddInt2Addr { dest: u8, b: u8, @@ -20344,6 +21662,15 @@ pub struct AddInt2Addr { #[pymethods] impl AddInt2Addr { + pub fn to_json(&self) -> Result { + Ok(serde_json::to_string(self)?) + } + + #[staticmethod] + pub fn from_json(json: &str) -> Result { + Ok(serde_json::from_str(json)?) + } + #[new] pub fn new(dest: u8, b: u8) -> Result { let ins = Self { dest, b }; @@ -20453,7 +21780,7 @@ impl AddInt2Addr { /// /// `dest` and `b` are registers indexed on 4 bits #[pyclass] -#[derive(Debug, Clone, Copy, PartialEq, Eq)] +#[derive(Debug, Clone, Copy, PartialEq, Eq, Deserialize, Serialize)] pub struct SubInt2Addr { dest: u8, b: u8, @@ -20461,6 +21788,15 @@ pub struct SubInt2Addr { #[pymethods] impl SubInt2Addr { + pub fn to_json(&self) -> Result { + Ok(serde_json::to_string(self)?) + } + + #[staticmethod] + pub fn from_json(json: &str) -> Result { + Ok(serde_json::from_str(json)?) + } + #[new] pub fn new(dest: u8, b: u8) -> Result { let ins = Self { dest, b }; @@ -20570,7 +21906,7 @@ impl SubInt2Addr { /// /// `dest` and `b` are registers indexed on 4 bits #[pyclass] -#[derive(Debug, Clone, Copy, PartialEq, Eq)] +#[derive(Debug, Clone, Copy, PartialEq, Eq, Deserialize, Serialize)] pub struct MulInt2Addr { dest: u8, b: u8, @@ -20578,6 +21914,15 @@ pub struct MulInt2Addr { #[pymethods] impl MulInt2Addr { + pub fn to_json(&self) -> Result { + Ok(serde_json::to_string(self)?) + } + + #[staticmethod] + pub fn from_json(json: &str) -> Result { + Ok(serde_json::from_str(json)?) + } + #[new] pub fn new(dest: u8, b: u8) -> Result { let ins = Self { dest, b }; @@ -20687,7 +22032,7 @@ impl MulInt2Addr { /// /// `dest` and `b` are registers indexed on 4 bits #[pyclass] -#[derive(Debug, Clone, Copy, PartialEq, Eq)] +#[derive(Debug, Clone, Copy, PartialEq, Eq, Deserialize, Serialize)] pub struct DivInt2Addr { dest: u8, b: u8, @@ -20695,6 +22040,15 @@ pub struct DivInt2Addr { #[pymethods] impl DivInt2Addr { + pub fn to_json(&self) -> Result { + Ok(serde_json::to_string(self)?) + } + + #[staticmethod] + pub fn from_json(json: &str) -> Result { + Ok(serde_json::from_str(json)?) + } + #[new] pub fn new(dest: u8, b: u8) -> Result { let ins = Self { dest, b }; @@ -20804,7 +22158,7 @@ impl DivInt2Addr { /// /// `dest` and `b` are registers indexed on 4 bits #[pyclass] -#[derive(Debug, Clone, Copy, PartialEq, Eq)] +#[derive(Debug, Clone, Copy, PartialEq, Eq, Deserialize, Serialize)] pub struct RemInt2Addr { dest: u8, b: u8, @@ -20812,6 +22166,15 @@ pub struct RemInt2Addr { #[pymethods] impl RemInt2Addr { + pub fn to_json(&self) -> Result { + Ok(serde_json::to_string(self)?) + } + + #[staticmethod] + pub fn from_json(json: &str) -> Result { + Ok(serde_json::from_str(json)?) + } + #[new] pub fn new(dest: u8, b: u8) -> Result { let ins = Self { dest, b }; @@ -20921,7 +22284,7 @@ impl RemInt2Addr { /// /// `dest` and `b` are registers indexed on 4 bits #[pyclass] -#[derive(Debug, Clone, Copy, PartialEq, Eq)] +#[derive(Debug, Clone, Copy, PartialEq, Eq, Deserialize, Serialize)] pub struct AndInt2Addr { dest: u8, b: u8, @@ -20929,6 +22292,15 @@ pub struct AndInt2Addr { #[pymethods] impl AndInt2Addr { + pub fn to_json(&self) -> Result { + Ok(serde_json::to_string(self)?) + } + + #[staticmethod] + pub fn from_json(json: &str) -> Result { + Ok(serde_json::from_str(json)?) + } + #[new] pub fn new(dest: u8, b: u8) -> Result { let ins = Self { dest, b }; @@ -21038,7 +22410,7 @@ impl AndInt2Addr { /// /// `dest` and `b` are registers indexed on 4 bits #[pyclass] -#[derive(Debug, Clone, Copy, PartialEq, Eq)] +#[derive(Debug, Clone, Copy, PartialEq, Eq, Deserialize, Serialize)] pub struct OrInt2Addr { dest: u8, b: u8, @@ -21046,6 +22418,15 @@ pub struct OrInt2Addr { #[pymethods] impl OrInt2Addr { + pub fn to_json(&self) -> Result { + Ok(serde_json::to_string(self)?) + } + + #[staticmethod] + pub fn from_json(json: &str) -> Result { + Ok(serde_json::from_str(json)?) + } + #[new] pub fn new(dest: u8, b: u8) -> Result { let ins = Self { dest, b }; @@ -21155,7 +22536,7 @@ impl OrInt2Addr { /// /// `dest` and `b` are registers indexed on 4 bits #[pyclass] -#[derive(Debug, Clone, Copy, PartialEq, Eq)] +#[derive(Debug, Clone, Copy, PartialEq, Eq, Deserialize, Serialize)] pub struct XorInt2Addr { dest: u8, b: u8, @@ -21163,6 +22544,15 @@ pub struct XorInt2Addr { #[pymethods] impl XorInt2Addr { + pub fn to_json(&self) -> Result { + Ok(serde_json::to_string(self)?) + } + + #[staticmethod] + pub fn from_json(json: &str) -> Result { + Ok(serde_json::from_str(json)?) + } + #[new] pub fn new(dest: u8, b: u8) -> Result { let ins = Self { dest, b }; @@ -21272,7 +22662,7 @@ impl XorInt2Addr { /// /// `dest` and `b` are registers indexed on 4 bits #[pyclass] -#[derive(Debug, Clone, Copy, PartialEq, Eq)] +#[derive(Debug, Clone, Copy, PartialEq, Eq, Deserialize, Serialize)] pub struct ShlInt2Addr { dest: u8, b: u8, @@ -21280,6 +22670,15 @@ pub struct ShlInt2Addr { #[pymethods] impl ShlInt2Addr { + pub fn to_json(&self) -> Result { + Ok(serde_json::to_string(self)?) + } + + #[staticmethod] + pub fn from_json(json: &str) -> Result { + Ok(serde_json::from_str(json)?) + } + #[new] pub fn new(dest: u8, b: u8) -> Result { let ins = Self { dest, b }; @@ -21389,7 +22788,7 @@ impl ShlInt2Addr { /// /// `dest` and `b` are registers indexed on 4 bits #[pyclass] -#[derive(Debug, Clone, Copy, PartialEq, Eq)] +#[derive(Debug, Clone, Copy, PartialEq, Eq, Deserialize, Serialize)] pub struct ShrInt2Addr { dest: u8, b: u8, @@ -21397,6 +22796,15 @@ pub struct ShrInt2Addr { #[pymethods] impl ShrInt2Addr { + pub fn to_json(&self) -> Result { + Ok(serde_json::to_string(self)?) + } + + #[staticmethod] + pub fn from_json(json: &str) -> Result { + Ok(serde_json::from_str(json)?) + } + #[new] pub fn new(dest: u8, b: u8) -> Result { let ins = Self { dest, b }; @@ -21506,7 +22914,7 @@ impl ShrInt2Addr { /// /// `dest` and `b` are registers indexed on 4 bits #[pyclass] -#[derive(Debug, Clone, Copy, PartialEq, Eq)] +#[derive(Debug, Clone, Copy, PartialEq, Eq, Deserialize, Serialize)] pub struct UshrInt2Addr { dest: u8, b: u8, @@ -21514,6 +22922,15 @@ pub struct UshrInt2Addr { #[pymethods] impl UshrInt2Addr { + pub fn to_json(&self) -> Result { + Ok(serde_json::to_string(self)?) + } + + #[staticmethod] + pub fn from_json(json: &str) -> Result { + Ok(serde_json::from_str(json)?) + } + #[new] pub fn new(dest: u8, b: u8) -> Result { let ins = Self { dest, b }; @@ -21625,7 +23042,7 @@ impl UshrInt2Addr { /// /// `dest` and `b` are registers indexed on 4 bits #[pyclass] -#[derive(Debug, Clone, Copy, PartialEq, Eq)] +#[derive(Debug, Clone, Copy, PartialEq, Eq, Deserialize, Serialize)] pub struct AddLong2Addr { dest: u8, b: u8, @@ -21633,6 +23050,15 @@ pub struct AddLong2Addr { #[pymethods] impl AddLong2Addr { + pub fn to_json(&self) -> Result { + Ok(serde_json::to_string(self)?) + } + + #[staticmethod] + pub fn from_json(json: &str) -> Result { + Ok(serde_json::from_str(json)?) + } + #[new] pub fn new(dest: u8, b: u8) -> Result { let ins = Self { dest, b }; @@ -21744,7 +23170,7 @@ impl AddLong2Addr { /// /// `dest` and `b` are registers indexed on 4 bits #[pyclass] -#[derive(Debug, Clone, Copy, PartialEq, Eq)] +#[derive(Debug, Clone, Copy, PartialEq, Eq, Deserialize, Serialize)] pub struct SubLong2Addr { dest: u8, b: u8, @@ -21752,6 +23178,15 @@ pub struct SubLong2Addr { #[pymethods] impl SubLong2Addr { + pub fn to_json(&self) -> Result { + Ok(serde_json::to_string(self)?) + } + + #[staticmethod] + pub fn from_json(json: &str) -> Result { + Ok(serde_json::from_str(json)?) + } + #[new] pub fn new(dest: u8, b: u8) -> Result { let ins = Self { dest, b }; @@ -21863,7 +23298,7 @@ impl SubLong2Addr { /// /// `dest` and `b` are registers indexed on 4 bits #[pyclass] -#[derive(Debug, Clone, Copy, PartialEq, Eq)] +#[derive(Debug, Clone, Copy, PartialEq, Eq, Deserialize, Serialize)] pub struct MulLong2Addr { dest: u8, b: u8, @@ -21871,6 +23306,15 @@ pub struct MulLong2Addr { #[pymethods] impl MulLong2Addr { + pub fn to_json(&self) -> Result { + Ok(serde_json::to_string(self)?) + } + + #[staticmethod] + pub fn from_json(json: &str) -> Result { + Ok(serde_json::from_str(json)?) + } + #[new] pub fn new(dest: u8, b: u8) -> Result { let ins = Self { dest, b }; @@ -21982,7 +23426,7 @@ impl MulLong2Addr { /// /// `dest` and `b` are registers indexed on 4 bits #[pyclass] -#[derive(Debug, Clone, Copy, PartialEq, Eq)] +#[derive(Debug, Clone, Copy, PartialEq, Eq, Deserialize, Serialize)] pub struct DivLong2Addr { dest: u8, b: u8, @@ -21990,6 +23434,15 @@ pub struct DivLong2Addr { #[pymethods] impl DivLong2Addr { + pub fn to_json(&self) -> Result { + Ok(serde_json::to_string(self)?) + } + + #[staticmethod] + pub fn from_json(json: &str) -> Result { + Ok(serde_json::from_str(json)?) + } + #[new] pub fn new(dest: u8, b: u8) -> Result { let ins = Self { dest, b }; @@ -22101,7 +23554,7 @@ impl DivLong2Addr { /// /// `dest` and `b` are registers indexed on 4 bits #[pyclass] -#[derive(Debug, Clone, Copy, PartialEq, Eq)] +#[derive(Debug, Clone, Copy, PartialEq, Eq, Deserialize, Serialize)] pub struct RemLong2Addr { dest: u8, b: u8, @@ -22109,6 +23562,15 @@ pub struct RemLong2Addr { #[pymethods] impl RemLong2Addr { + pub fn to_json(&self) -> Result { + Ok(serde_json::to_string(self)?) + } + + #[staticmethod] + pub fn from_json(json: &str) -> Result { + Ok(serde_json::from_str(json)?) + } + #[new] pub fn new(dest: u8, b: u8) -> Result { let ins = Self { dest, b }; @@ -22220,7 +23682,7 @@ impl RemLong2Addr { /// /// `dest` and `b` are registers indexed on 4 bits #[pyclass] -#[derive(Debug, Clone, Copy, PartialEq, Eq)] +#[derive(Debug, Clone, Copy, PartialEq, Eq, Deserialize, Serialize)] pub struct AndLong2Addr { dest: u8, b: u8, @@ -22228,6 +23690,15 @@ pub struct AndLong2Addr { #[pymethods] impl AndLong2Addr { + pub fn to_json(&self) -> Result { + Ok(serde_json::to_string(self)?) + } + + #[staticmethod] + pub fn from_json(json: &str) -> Result { + Ok(serde_json::from_str(json)?) + } + #[new] pub fn new(dest: u8, b: u8) -> Result { let ins = Self { dest, b }; @@ -22339,7 +23810,7 @@ impl AndLong2Addr { /// /// `dest` and `b` are registers indexed on 4 bits #[pyclass] -#[derive(Debug, Clone, Copy, PartialEq, Eq)] +#[derive(Debug, Clone, Copy, PartialEq, Eq, Deserialize, Serialize)] pub struct OrLong2Addr { dest: u8, b: u8, @@ -22347,6 +23818,15 @@ pub struct OrLong2Addr { #[pymethods] impl OrLong2Addr { + pub fn to_json(&self) -> Result { + Ok(serde_json::to_string(self)?) + } + + #[staticmethod] + pub fn from_json(json: &str) -> Result { + Ok(serde_json::from_str(json)?) + } + #[new] pub fn new(dest: u8, b: u8) -> Result { let ins = Self { dest, b }; @@ -22458,7 +23938,7 @@ impl OrLong2Addr { /// /// `dest` and `b` are registers indexed on 4 bits #[pyclass] -#[derive(Debug, Clone, Copy, PartialEq, Eq)] +#[derive(Debug, Clone, Copy, PartialEq, Eq, Deserialize, Serialize)] pub struct XorLong2Addr { dest: u8, b: u8, @@ -22466,6 +23946,15 @@ pub struct XorLong2Addr { #[pymethods] impl XorLong2Addr { + pub fn to_json(&self) -> Result { + Ok(serde_json::to_string(self)?) + } + + #[staticmethod] + pub fn from_json(json: &str) -> Result { + Ok(serde_json::from_str(json)?) + } + #[new] pub fn new(dest: u8, b: u8) -> Result { let ins = Self { dest, b }; @@ -22577,7 +24066,7 @@ impl XorLong2Addr { /// /// `dest` and `b` are registers indexed on 4 bits #[pyclass] -#[derive(Debug, Clone, Copy, PartialEq, Eq)] +#[derive(Debug, Clone, Copy, PartialEq, Eq, Deserialize, Serialize)] pub struct ShlLong2Addr { dest: u8, b: u8, @@ -22585,6 +24074,15 @@ pub struct ShlLong2Addr { #[pymethods] impl ShlLong2Addr { + pub fn to_json(&self) -> Result { + Ok(serde_json::to_string(self)?) + } + + #[staticmethod] + pub fn from_json(json: &str) -> Result { + Ok(serde_json::from_str(json)?) + } + #[new] pub fn new(dest: u8, b: u8) -> Result { let ins = Self { dest, b }; @@ -22696,7 +24194,7 @@ impl ShlLong2Addr { /// /// `dest` and `b` are registers indexed on 4 bits #[pyclass] -#[derive(Debug, Clone, Copy, PartialEq, Eq)] +#[derive(Debug, Clone, Copy, PartialEq, Eq, Deserialize, Serialize)] pub struct ShrLong2Addr { dest: u8, b: u8, @@ -22704,6 +24202,15 @@ pub struct ShrLong2Addr { #[pymethods] impl ShrLong2Addr { + pub fn to_json(&self) -> Result { + Ok(serde_json::to_string(self)?) + } + + #[staticmethod] + pub fn from_json(json: &str) -> Result { + Ok(serde_json::from_str(json)?) + } + #[new] pub fn new(dest: u8, b: u8) -> Result { let ins = Self { dest, b }; @@ -22815,7 +24322,7 @@ impl ShrLong2Addr { /// /// `dest` and `b` are registers indexed on 4 bits #[pyclass] -#[derive(Debug, Clone, Copy, PartialEq, Eq)] +#[derive(Debug, Clone, Copy, PartialEq, Eq, Deserialize, Serialize)] pub struct UshrLong2Addr { dest: u8, b: u8, @@ -22823,6 +24330,15 @@ pub struct UshrLong2Addr { #[pymethods] impl UshrLong2Addr { + pub fn to_json(&self) -> Result { + Ok(serde_json::to_string(self)?) + } + + #[staticmethod] + pub fn from_json(json: &str) -> Result { + Ok(serde_json::from_str(json)?) + } + #[new] pub fn new(dest: u8, b: u8) -> Result { let ins = Self { dest, b }; @@ -22932,7 +24448,7 @@ impl UshrLong2Addr { /// /// `dest` and `b` are registers indexed on 4 bits #[pyclass] -#[derive(Debug, Clone, Copy, PartialEq, Eq)] +#[derive(Debug, Clone, Copy, PartialEq, Eq, Deserialize, Serialize)] pub struct AddFloat2Addr { dest: u8, b: u8, @@ -22940,6 +24456,15 @@ pub struct AddFloat2Addr { #[pymethods] impl AddFloat2Addr { + pub fn to_json(&self) -> Result { + Ok(serde_json::to_string(self)?) + } + + #[staticmethod] + pub fn from_json(json: &str) -> Result { + Ok(serde_json::from_str(json)?) + } + #[new] pub fn new(dest: u8, b: u8) -> Result { let ins = Self { dest, b }; @@ -23049,7 +24574,7 @@ impl AddFloat2Addr { /// /// `dest` and `b` are registers indexed on 4 bits #[pyclass] -#[derive(Debug, Clone, Copy, PartialEq, Eq)] +#[derive(Debug, Clone, Copy, PartialEq, Eq, Deserialize, Serialize)] pub struct SubFloat2Addr { dest: u8, b: u8, @@ -23057,6 +24582,15 @@ pub struct SubFloat2Addr { #[pymethods] impl SubFloat2Addr { + pub fn to_json(&self) -> Result { + Ok(serde_json::to_string(self)?) + } + + #[staticmethod] + pub fn from_json(json: &str) -> Result { + Ok(serde_json::from_str(json)?) + } + #[new] pub fn new(dest: u8, b: u8) -> Result { let ins = Self { dest, b }; @@ -23166,7 +24700,7 @@ impl SubFloat2Addr { /// /// `dest` and `b` are registers indexed on 4 bits #[pyclass] -#[derive(Debug, Clone, Copy, PartialEq, Eq)] +#[derive(Debug, Clone, Copy, PartialEq, Eq, Deserialize, Serialize)] pub struct MulFloat2Addr { dest: u8, b: u8, @@ -23174,6 +24708,15 @@ pub struct MulFloat2Addr { #[pymethods] impl MulFloat2Addr { + pub fn to_json(&self) -> Result { + Ok(serde_json::to_string(self)?) + } + + #[staticmethod] + pub fn from_json(json: &str) -> Result { + Ok(serde_json::from_str(json)?) + } + #[new] pub fn new(dest: u8, b: u8) -> Result { let ins = Self { dest, b }; @@ -23283,7 +24826,7 @@ impl MulFloat2Addr { /// /// `dest` and `b` are registers indexed on 4 bits #[pyclass] -#[derive(Debug, Clone, Copy, PartialEq, Eq)] +#[derive(Debug, Clone, Copy, PartialEq, Eq, Deserialize, Serialize)] pub struct DivFloat2Addr { dest: u8, b: u8, @@ -23291,6 +24834,15 @@ pub struct DivFloat2Addr { #[pymethods] impl DivFloat2Addr { + pub fn to_json(&self) -> Result { + Ok(serde_json::to_string(self)?) + } + + #[staticmethod] + pub fn from_json(json: &str) -> Result { + Ok(serde_json::from_str(json)?) + } + #[new] pub fn new(dest: u8, b: u8) -> Result { let ins = Self { dest, b }; @@ -23400,7 +24952,7 @@ impl DivFloat2Addr { /// /// `dest` and `b` are registers indexed on 4 bits #[pyclass] -#[derive(Debug, Clone, Copy, PartialEq, Eq)] +#[derive(Debug, Clone, Copy, PartialEq, Eq, Deserialize, Serialize)] pub struct RemFloat2Addr { dest: u8, b: u8, @@ -23408,6 +24960,15 @@ pub struct RemFloat2Addr { #[pymethods] impl RemFloat2Addr { + pub fn to_json(&self) -> Result { + Ok(serde_json::to_string(self)?) + } + + #[staticmethod] + pub fn from_json(json: &str) -> Result { + Ok(serde_json::from_str(json)?) + } + #[new] pub fn new(dest: u8, b: u8) -> Result { let ins = Self { dest, b }; @@ -23519,7 +25080,7 @@ impl RemFloat2Addr { /// /// `dest` and `b` are registers indexed on 4 bits #[pyclass] -#[derive(Debug, Clone, Copy, PartialEq, Eq)] +#[derive(Debug, Clone, Copy, PartialEq, Eq, Deserialize, Serialize)] pub struct AddDouble2Addr { dest: u8, b: u8, @@ -23527,6 +25088,15 @@ pub struct AddDouble2Addr { #[pymethods] impl AddDouble2Addr { + pub fn to_json(&self) -> Result { + Ok(serde_json::to_string(self)?) + } + + #[staticmethod] + pub fn from_json(json: &str) -> Result { + Ok(serde_json::from_str(json)?) + } + #[new] pub fn new(dest: u8, b: u8) -> Result { let ins = Self { dest, b }; @@ -23638,7 +25208,7 @@ impl AddDouble2Addr { /// /// `dest` and `b` are registers indexed on 4 bits #[pyclass] -#[derive(Debug, Clone, Copy, PartialEq, Eq)] +#[derive(Debug, Clone, Copy, PartialEq, Eq, Deserialize, Serialize)] pub struct SubDouble2Addr { dest: u8, b: u8, @@ -23646,6 +25216,15 @@ pub struct SubDouble2Addr { #[pymethods] impl SubDouble2Addr { + pub fn to_json(&self) -> Result { + Ok(serde_json::to_string(self)?) + } + + #[staticmethod] + pub fn from_json(json: &str) -> Result { + Ok(serde_json::from_str(json)?) + } + #[new] pub fn new(dest: u8, b: u8) -> Result { let ins = Self { dest, b }; @@ -23757,7 +25336,7 @@ impl SubDouble2Addr { /// /// `dest` and `b` are registers indexed on 4 bits #[pyclass] -#[derive(Debug, Clone, Copy, PartialEq, Eq)] +#[derive(Debug, Clone, Copy, PartialEq, Eq, Deserialize, Serialize)] pub struct MulDouble2Addr { dest: u8, b: u8, @@ -23765,6 +25344,15 @@ pub struct MulDouble2Addr { #[pymethods] impl MulDouble2Addr { + pub fn to_json(&self) -> Result { + Ok(serde_json::to_string(self)?) + } + + #[staticmethod] + pub fn from_json(json: &str) -> Result { + Ok(serde_json::from_str(json)?) + } + #[new] pub fn new(dest: u8, b: u8) -> Result { let ins = Self { dest, b }; @@ -23876,7 +25464,7 @@ impl MulDouble2Addr { /// /// `dest` and `b` are registers indexed on 4 bits #[pyclass] -#[derive(Debug, Clone, Copy, PartialEq, Eq)] +#[derive(Debug, Clone, Copy, PartialEq, Eq, Deserialize, Serialize)] pub struct DivDouble2Addr { dest: u8, b: u8, @@ -23884,6 +25472,15 @@ pub struct DivDouble2Addr { #[pymethods] impl DivDouble2Addr { + pub fn to_json(&self) -> Result { + Ok(serde_json::to_string(self)?) + } + + #[staticmethod] + pub fn from_json(json: &str) -> Result { + Ok(serde_json::from_str(json)?) + } + #[new] pub fn new(dest: u8, b: u8) -> Result { let ins = Self { dest, b }; @@ -23995,7 +25592,7 @@ impl DivDouble2Addr { /// /// `dest` and `b` are registers indexed on 4 bits #[pyclass] -#[derive(Debug, Clone, Copy, PartialEq, Eq)] +#[derive(Debug, Clone, Copy, PartialEq, Eq, Deserialize, Serialize)] pub struct RemDouble2Addr { dest: u8, b: u8, @@ -24003,6 +25600,15 @@ pub struct RemDouble2Addr { #[pymethods] impl RemDouble2Addr { + pub fn to_json(&self) -> Result { + Ok(serde_json::to_string(self)?) + } + + #[staticmethod] + pub fn from_json(json: &str) -> Result { + Ok(serde_json::from_str(json)?) + } + #[new] pub fn new(dest: u8, b: u8) -> Result { let ins = Self { dest, b }; @@ -24113,7 +25719,7 @@ impl RemDouble2Addr { /// Either `dest` and `b` are registers indexed on 4 bits and lit is encoded in 16 bits /// or `dest` and `b` are registers indexed on 8 bits and lit is encoded in 8 bits #[pyclass] -#[derive(Debug, Clone, Copy, PartialEq, Eq)] +#[derive(Debug, Clone, Copy, PartialEq, Eq, Deserialize, Serialize)] pub struct AddIntLit { dest: u8, b: u8, @@ -24122,6 +25728,15 @@ pub struct AddIntLit { #[pymethods] impl AddIntLit { + pub fn to_json(&self) -> Result { + Ok(serde_json::to_string(self)?) + } + + #[staticmethod] + pub fn from_json(json: &str) -> Result { + Ok(serde_json::from_str(json)?) + } + #[new] pub fn new(dest: u8, b: u8, lit: i16) -> Result { let ins = Self { dest, b, lit }; @@ -24276,7 +25891,7 @@ impl AddIntLit { /// Either `dest` and `b` are registers indexed on 4 bits and lit is encoded in 16 bits /// or `dest` and `b` are registers indexed on 8 bits and lit is encoded in 8 bits #[pyclass] -#[derive(Debug, Clone, Copy, PartialEq, Eq)] +#[derive(Debug, Clone, Copy, PartialEq, Eq, Deserialize, Serialize)] pub struct RsubIntLit { dest: u8, b: u8, @@ -24285,6 +25900,15 @@ pub struct RsubIntLit { #[pymethods] impl RsubIntLit { + pub fn to_json(&self) -> Result { + Ok(serde_json::to_string(self)?) + } + + #[staticmethod] + pub fn from_json(json: &str) -> Result { + Ok(serde_json::from_str(json)?) + } + #[new] pub fn new(dest: u8, b: u8, lit: i16) -> Result { let ins = Self { dest, b, lit }; @@ -24439,7 +26063,7 @@ impl RsubIntLit { /// Either `dest` and `b` are registers indexed on 4 bits and lit is encoded in 16 bits /// or `dest` and `b` are registers indexed on 8 bits and lit is encoded in 8 bits #[pyclass] -#[derive(Debug, Clone, Copy, PartialEq, Eq)] +#[derive(Debug, Clone, Copy, PartialEq, Eq, Deserialize, Serialize)] pub struct MulIntLit { dest: u8, b: u8, @@ -24448,6 +26072,15 @@ pub struct MulIntLit { #[pymethods] impl MulIntLit { + pub fn to_json(&self) -> Result { + Ok(serde_json::to_string(self)?) + } + + #[staticmethod] + pub fn from_json(json: &str) -> Result { + Ok(serde_json::from_str(json)?) + } + #[new] pub fn new(dest: u8, b: u8, lit: i16) -> Result { let ins = Self { dest, b, lit }; @@ -24602,7 +26235,7 @@ impl MulIntLit { /// Either `dest` and `b` are registers indexed on 4 bits and lit is encoded in 16 bits /// or `dest` and `b` are registers indexed on 8 bits and lit is encoded in 8 bits #[pyclass] -#[derive(Debug, Clone, Copy, PartialEq, Eq)] +#[derive(Debug, Clone, Copy, PartialEq, Eq, Deserialize, Serialize)] pub struct DivIntLit { dest: u8, b: u8, @@ -24611,6 +26244,15 @@ pub struct DivIntLit { #[pymethods] impl DivIntLit { + pub fn to_json(&self) -> Result { + Ok(serde_json::to_string(self)?) + } + + #[staticmethod] + pub fn from_json(json: &str) -> Result { + Ok(serde_json::from_str(json)?) + } + #[new] pub fn new(dest: u8, b: u8, lit: i16) -> Result { let ins = Self { dest, b, lit }; @@ -24765,7 +26407,7 @@ impl DivIntLit { /// Either `dest` and `b` are registers indexed on 4 bits and lit is encoded in 16 bits /// or `dest` and `b` are registers indexed on 8 bits and lit is encoded in 8 bits #[pyclass] -#[derive(Debug, Clone, Copy, PartialEq, Eq)] +#[derive(Debug, Clone, Copy, PartialEq, Eq, Deserialize, Serialize)] pub struct RemIntLit { dest: u8, b: u8, @@ -24774,6 +26416,15 @@ pub struct RemIntLit { #[pymethods] impl RemIntLit { + pub fn to_json(&self) -> Result { + Ok(serde_json::to_string(self)?) + } + + #[staticmethod] + pub fn from_json(json: &str) -> Result { + Ok(serde_json::from_str(json)?) + } + #[new] pub fn new(dest: u8, b: u8, lit: i16) -> Result { let ins = Self { dest, b, lit }; @@ -24928,7 +26579,7 @@ impl RemIntLit { /// Either `dest` and `b` are registers indexed on 4 bits and lit is encoded in 16 bits /// or `dest` and `b` are registers indexed on 8 bits and lit is encoded in 8 bits #[pyclass] -#[derive(Debug, Clone, Copy, PartialEq, Eq)] +#[derive(Debug, Clone, Copy, PartialEq, Eq, Deserialize, Serialize)] pub struct AndIntLit { dest: u8, b: u8, @@ -24937,6 +26588,15 @@ pub struct AndIntLit { #[pymethods] impl AndIntLit { + pub fn to_json(&self) -> Result { + Ok(serde_json::to_string(self)?) + } + + #[staticmethod] + pub fn from_json(json: &str) -> Result { + Ok(serde_json::from_str(json)?) + } + #[new] pub fn new(dest: u8, b: u8, lit: i16) -> Result { let ins = Self { dest, b, lit }; @@ -25091,7 +26751,7 @@ impl AndIntLit { /// Either `dest` and `b` are registers indexed on 4 bits and lit is encoded in 16 bits /// or `dest` and `b` are registers indexed on 8 bits and lit is encoded in 8 bits #[pyclass] -#[derive(Debug, Clone, Copy, PartialEq, Eq)] +#[derive(Debug, Clone, Copy, PartialEq, Eq, Deserialize, Serialize)] pub struct OrIntLit { dest: u8, b: u8, @@ -25100,6 +26760,15 @@ pub struct OrIntLit { #[pymethods] impl OrIntLit { + pub fn to_json(&self) -> Result { + Ok(serde_json::to_string(self)?) + } + + #[staticmethod] + pub fn from_json(json: &str) -> Result { + Ok(serde_json::from_str(json)?) + } + #[new] pub fn new(dest: u8, b: u8, lit: i16) -> Result { let ins = Self { dest, b, lit }; @@ -25254,7 +26923,7 @@ impl OrIntLit { /// Either `dest` and `b` are registers indexed on 4 bits and lit is encoded in 16 bits /// or `dest` and `b` are registers indexed on 8 bits and lit is encoded in 8 bits #[pyclass] -#[derive(Debug, Clone, Copy, PartialEq, Eq)] +#[derive(Debug, Clone, Copy, PartialEq, Eq, Deserialize, Serialize)] pub struct XorIntLit { dest: u8, b: u8, @@ -25263,6 +26932,15 @@ pub struct XorIntLit { #[pymethods] impl XorIntLit { + pub fn to_json(&self) -> Result { + Ok(serde_json::to_string(self)?) + } + + #[staticmethod] + pub fn from_json(json: &str) -> Result { + Ok(serde_json::from_str(json)?) + } + #[new] pub fn new(dest: u8, b: u8, lit: i16) -> Result { let ins = Self { dest, b, lit }; @@ -25414,7 +27092,7 @@ impl XorIntLit { /// Put b << lit in dest. #[pyclass] -#[derive(Debug, Clone, Copy, PartialEq, Eq)] +#[derive(Debug, Clone, Copy, PartialEq, Eq, Deserialize, Serialize)] pub struct ShlIntLit { dest: u8, b: u8, @@ -25423,6 +27101,15 @@ pub struct ShlIntLit { #[pymethods] impl ShlIntLit { + pub fn to_json(&self) -> Result { + Ok(serde_json::to_string(self)?) + } + + #[staticmethod] + pub fn from_json(json: &str) -> Result { + Ok(serde_json::from_str(json)?) + } + #[new] pub fn new(dest: u8, b: u8, lit: i8) -> Self { Self { dest, b, lit } @@ -25516,7 +27203,7 @@ impl ShlIntLit { /// Put b >> lit (signed) in dest. #[pyclass] -#[derive(Debug, Clone, Copy, PartialEq, Eq)] +#[derive(Debug, Clone, Copy, PartialEq, Eq, Deserialize, Serialize)] pub struct ShrIntLit { dest: u8, b: u8, @@ -25525,6 +27212,15 @@ pub struct ShrIntLit { #[pymethods] impl ShrIntLit { + pub fn to_json(&self) -> Result { + Ok(serde_json::to_string(self)?) + } + + #[staticmethod] + pub fn from_json(json: &str) -> Result { + Ok(serde_json::from_str(json)?) + } + #[new] pub fn new(dest: u8, b: u8, lit: i8) -> Self { Self { dest, b, lit } @@ -25618,7 +27314,7 @@ impl ShrIntLit { /// Put b >> lit in dest. #[pyclass] -#[derive(Debug, Clone, Copy, PartialEq, Eq)] +#[derive(Debug, Clone, Copy, PartialEq, Eq, Deserialize, Serialize)] pub struct UshrIntLit { dest: u8, b: u8, @@ -25627,6 +27323,15 @@ pub struct UshrIntLit { #[pymethods] impl UshrIntLit { + pub fn to_json(&self) -> Result { + Ok(serde_json::to_string(self)?) + } + + #[staticmethod] + pub fn from_json(json: &str) -> Result { + Ok(serde_json::from_str(json)?) + } + #[new] pub fn new(dest: u8, b: u8, lit: i8) -> Self { Self { dest, b, lit } @@ -25720,7 +27425,7 @@ impl UshrIntLit { /// Call a polymorphic method. #[pyclass] -#[derive(Debug, Clone, PartialEq, Eq)] +#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize)] pub struct InvokePolymorphic { #[pyo3(get)] pub method: IdMethod, @@ -25732,6 +27437,15 @@ pub struct InvokePolymorphic { #[pymethods] impl InvokePolymorphic { + pub fn to_json(&self) -> Result { + Ok(serde_json::to_string(self)?) + } + + #[staticmethod] + pub fn from_json(json: &str) -> Result { + Ok(serde_json::from_str(json)?) + } + #[new] pub fn new(method: IdMethod, proto: IdMethodType, args: Vec) -> Result { let invoke = Self { @@ -25948,7 +27662,7 @@ impl InvokePolymorphic { /// Invoke a method from a call site. #[pyclass] -#[derive(Debug, Clone)] +#[derive(Debug, Clone, PartialEq, Deserialize, Serialize)] pub struct InvokeCustom { #[pyo3(get)] pub call_site: CallSite, @@ -25958,6 +27672,15 @@ pub struct InvokeCustom { #[pymethods] impl InvokeCustom { + pub fn to_json(&self) -> Result { + Ok(serde_json::to_string(self)?) + } + + #[staticmethod] + pub fn from_json(json: &str) -> Result { + Ok(serde_json::from_str(json)?) + } + #[new] pub fn new(call_site: CallSite, args: Vec) -> Result { let invoke = Self { call_site, args }; @@ -26153,7 +27876,7 @@ impl InvokeCustom { /// Put contents reference to the method handle in the register. #[pyclass] -#[derive(Debug, Clone, PartialEq, Eq)] +#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize)] pub struct ConstMethodHandle { #[pyo3(get)] pub handle: MethodHandle, @@ -26163,6 +27886,15 @@ pub struct ConstMethodHandle { #[pymethods] impl ConstMethodHandle { + pub fn to_json(&self) -> Result { + Ok(serde_json::to_string(self)?) + } + + #[staticmethod] + pub fn from_json(json: &str) -> Result { + Ok(serde_json::from_str(json)?) + } + #[new] pub fn new(to: u8, handle: MethodHandle) -> Self { Self { to, handle } @@ -26258,7 +27990,7 @@ impl ConstMethodHandle { /// Put contents reference to the prototype in the register. #[pyclass] -#[derive(Debug, Clone, PartialEq, Eq)] +#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize)] pub struct ConstMethodType { #[pyo3(get)] pub proto: IdMethodType, @@ -26268,6 +28000,15 @@ pub struct ConstMethodType { #[pymethods] impl ConstMethodType { + pub fn to_json(&self) -> Result { + Ok(serde_json::to_string(self)?) + } + + #[staticmethod] + pub fn from_json(json: &str) -> Result { + Ok(serde_json::from_str(json)?) + } + #[new] pub fn new(to: u8, proto: IdMethodType) -> Self { Self { to, proto } @@ -26365,7 +28106,7 @@ impl ConstMethodType { /// Try block. It does not match an dalvik instruction but is derived from the code item struct. #[pyclass] -#[derive(Debug, Clone, PartialEq, Eq)] +#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize)] pub struct Try { #[pyo3(get)] pub end_label: String, @@ -26383,6 +28124,15 @@ pub struct Try { #[pymethods] impl Try { + pub fn to_json(&self) -> Result { + Ok(serde_json::to_string(self)?) + } + + #[staticmethod] + pub fn from_json(json: &str) -> Result { + Ok(serde_json::from_str(json)?) + } + #[new] pub fn new( end_label: String, @@ -26502,7 +28252,7 @@ impl Try { /// Label marker. It does not match an dalvik instruction, but it's use as a marker for a /// jump destination. #[pyclass] -#[derive(Debug, Clone, PartialEq, Eq)] +#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize)] pub struct Label { #[pyo3(get)] pub name: String, @@ -26510,6 +28260,15 @@ pub struct Label { #[pymethods] impl Label { + pub fn to_json(&self) -> Result { + Ok(serde_json::to_string(self)?) + } + + #[staticmethod] + pub fn from_json(json: &str) -> Result { + Ok(serde_json::from_str(json)?) + } + #[new] pub fn new(name: String) -> Self { Self { name } diff --git a/androscalpel/src/lib.rs b/androscalpel/src/lib.rs index 7375fe9..9c5d4b2 100644 --- a/androscalpel/src/lib.rs +++ b/androscalpel/src/lib.rs @@ -10,6 +10,7 @@ pub mod dex_id; pub mod dex_string; pub mod dex_writer; pub mod field; +mod hashmap_vectorize; pub mod instructions; pub mod method; pub mod method_handle; diff --git a/androscalpel/src/method.rs b/androscalpel/src/method.rs index 0c91295..5e6578d 100644 --- a/androscalpel/src/method.rs +++ b/androscalpel/src/method.rs @@ -1,17 +1,19 @@ //! Representation of a method. +use serde::{Deserialize, Serialize}; use std::collections::HashSet; use pyo3::prelude::*; use crate::{ Code, DexAnnotationItem, DexString, IdField, IdMethod, IdMethodType, IdType, MethodHandle, + Result, }; use androscalpel_serializer::consts::*; /// Represent a method. #[pyclass] -#[derive(Debug, Clone)] +#[derive(Debug, Clone, PartialEq, Deserialize, Serialize)] pub struct Method { /// The structure used to reference this method. #[pyo3(get)] @@ -68,7 +70,7 @@ pub struct Method { /// Represent the visibility of a field #[pyclass] -#[derive(Debug, Clone, Copy, PartialEq, Eq)] +#[derive(Debug, Clone, Copy, PartialEq, Eq, Deserialize, Serialize)] pub enum MethodVisibility { Public, Private, @@ -78,6 +80,15 @@ pub enum MethodVisibility { #[pymethods] impl Method { + pub fn to_json(&self) -> Result { + Ok(serde_json::to_string(self)?) + } + + #[staticmethod] + pub fn from_json(json: &str) -> Result { + Ok(serde_json::from_str(json)?) + } + #[new] pub fn new(descriptor: IdMethod) -> Self { // TODO: take code option as arg and set the default flags accordingly diff --git a/androscalpel/src/method_handle.rs b/androscalpel/src/method_handle.rs index dc3e1fe..fdb4774 100644 --- a/androscalpel/src/method_handle.rs +++ b/androscalpel/src/method_handle.rs @@ -1,5 +1,6 @@ //! The structure use to reference a method invocation. +use serde::{Deserialize, Serialize}; use std::collections::HashSet; use std::hash::Hash; @@ -8,9 +9,10 @@ use pyo3::prelude::*; use crate::dex_id::*; use crate::DexString; +use crate::Result; /// The structure use to reference a method invocation. -#[derive(Debug, Clone, PartialEq, Eq, Hash)] +#[derive(Debug, Clone, PartialEq, Eq, Hash, Deserialize, Serialize)] pub enum MethodHandle { StaticPut(StaticPut), StaticGet(StaticGet), @@ -24,11 +26,20 @@ pub enum MethodHandle { } #[pyclass] -#[derive(Debug, Clone, PartialEq, Eq, Hash)] +#[derive(Debug, Clone, PartialEq, Eq, Hash, Deserialize, Serialize)] pub struct StaticPut(pub IdField); #[pymethods] impl StaticPut { + pub fn to_json(&self) -> Result { + Ok(serde_json::to_string(self)?) + } + + #[staticmethod] + pub fn from_json(json: &str) -> Result { + Ok(serde_json::from_str(json)?) + } + #[new] pub fn new(val: IdField) -> Self { Self(val) @@ -81,11 +92,20 @@ impl StaticPut { } } #[pyclass] -#[derive(Debug, Clone, PartialEq, Eq, Hash)] +#[derive(Debug, Clone, PartialEq, Eq, Hash, Deserialize, Serialize)] pub struct StaticGet(pub IdField); #[pymethods] impl StaticGet { + pub fn to_json(&self) -> Result { + Ok(serde_json::to_string(self)?) + } + + #[staticmethod] + pub fn from_json(json: &str) -> Result { + Ok(serde_json::from_str(json)?) + } + #[new] pub fn new(val: IdField) -> Self { Self(val) @@ -138,11 +158,20 @@ impl StaticGet { } } #[pyclass] -#[derive(Debug, Clone, PartialEq, Eq, Hash)] +#[derive(Debug, Clone, PartialEq, Eq, Hash, Deserialize, Serialize)] pub struct InstancePut(pub IdField); #[pymethods] impl InstancePut { + pub fn to_json(&self) -> Result { + Ok(serde_json::to_string(self)?) + } + + #[staticmethod] + pub fn from_json(json: &str) -> Result { + Ok(serde_json::from_str(json)?) + } + #[new] pub fn new(val: IdField) -> Self { Self(val) @@ -195,11 +224,20 @@ impl InstancePut { } } #[pyclass] -#[derive(Debug, Clone, PartialEq, Eq, Hash)] +#[derive(Debug, Clone, PartialEq, Eq, Hash, Deserialize, Serialize)] pub struct InstanceGet(pub IdField); #[pymethods] impl InstanceGet { + pub fn to_json(&self) -> Result { + Ok(serde_json::to_string(self)?) + } + + #[staticmethod] + pub fn from_json(json: &str) -> Result { + Ok(serde_json::from_str(json)?) + } + #[new] pub fn new(val: IdField) -> Self { Self(val) @@ -253,11 +291,20 @@ impl InstanceGet { } #[pyclass] -#[derive(Debug, Clone, PartialEq, Eq, Hash)] +#[derive(Debug, Clone, PartialEq, Eq, Hash, Deserialize, Serialize)] pub struct InvokeStatic(pub IdMethod); #[pymethods] impl InvokeStatic { + pub fn to_json(&self) -> Result { + Ok(serde_json::to_string(self)?) + } + + #[staticmethod] + pub fn from_json(json: &str) -> Result { + Ok(serde_json::from_str(json)?) + } + #[new] pub fn new(val: IdMethod) -> Self { Self(val) @@ -311,11 +358,20 @@ impl InvokeStatic { } #[pyclass] -#[derive(Debug, Clone, PartialEq, Eq, Hash)] +#[derive(Debug, Clone, PartialEq, Eq, Hash, Deserialize, Serialize)] pub struct InvokeInstance(pub IdMethod); #[pymethods] impl InvokeInstance { + pub fn to_json(&self) -> Result { + Ok(serde_json::to_string(self)?) + } + + #[staticmethod] + pub fn from_json(json: &str) -> Result { + Ok(serde_json::from_str(json)?) + } + #[new] pub fn new(val: IdMethod) -> Self { Self(val) @@ -369,11 +425,20 @@ impl InvokeInstance { } #[pyclass] -#[derive(Debug, Clone, PartialEq, Eq, Hash)] +#[derive(Debug, Clone, PartialEq, Eq, Hash, Deserialize, Serialize)] pub struct InvokeConstructor(pub IdMethod); #[pymethods] impl InvokeConstructor { + pub fn to_json(&self) -> Result { + Ok(serde_json::to_string(self)?) + } + + #[staticmethod] + pub fn from_json(json: &str) -> Result { + Ok(serde_json::from_str(json)?) + } + #[new] pub fn new(val: IdMethod) -> Self { Self(val) @@ -427,11 +492,20 @@ impl InvokeConstructor { } #[pyclass] -#[derive(Debug, Clone, PartialEq, Eq, Hash)] +#[derive(Debug, Clone, PartialEq, Eq, Hash, Deserialize, Serialize)] pub struct InvokeDirect(pub IdMethod); #[pymethods] impl InvokeDirect { + pub fn to_json(&self) -> Result { + Ok(serde_json::to_string(self)?) + } + + #[staticmethod] + pub fn from_json(json: &str) -> Result { + Ok(serde_json::from_str(json)?) + } + #[new] pub fn new(val: IdMethod) -> Self { Self(val) @@ -485,11 +559,20 @@ impl InvokeDirect { } #[pyclass] -#[derive(Debug, Clone, PartialEq, Eq, Hash)] +#[derive(Debug, Clone, PartialEq, Eq, Hash, Deserialize, Serialize)] pub struct InvokeInterface(pub IdMethod); #[pymethods] impl InvokeInterface { + pub fn to_json(&self) -> Result { + Ok(serde_json::to_string(self)?) + } + + #[staticmethod] + pub fn from_json(json: &str) -> Result { + Ok(serde_json::from_str(json)?) + } + #[new] pub fn new(val: IdMethod) -> Self { Self(val) diff --git a/androscalpel/src/scalar.rs b/androscalpel/src/scalar.rs index e7dd4da..f7d4055 100644 --- a/androscalpel/src/scalar.rs +++ b/androscalpel/src/scalar.rs @@ -1,15 +1,26 @@ //! The class identifying dex structure. +use crate::Result; +use serde::{Deserialize, Serialize}; use std::collections::HashSet; use crate::{DexString, DexValue, IdField, IdMethod, IdMethodType, IdType, MethodHandle}; use pyo3::prelude::*; #[pyclass] -#[derive(Debug, Clone, Copy, PartialEq, Eq)] +#[derive(Debug, Clone, Copy, PartialEq, Eq, Deserialize, Serialize)] pub struct DexByte(pub i8); #[pymethods] impl DexByte { + pub fn to_json(&self) -> Result { + Ok(serde_json::to_string(self)?) + } + + #[staticmethod] + pub fn from_json(json: &str) -> Result { + Ok(serde_json::from_str(json)?) + } + #[new] pub fn new(val: i8) -> Self { Self(val) @@ -29,10 +40,19 @@ impl DexByte { } #[pyclass] -#[derive(Debug, Clone, Copy, PartialEq, Eq)] +#[derive(Debug, Clone, Copy, PartialEq, Eq, Deserialize, Serialize)] pub struct DexShort(pub i16); #[pymethods] impl DexShort { + pub fn to_json(&self) -> Result { + Ok(serde_json::to_string(self)?) + } + + #[staticmethod] + pub fn from_json(json: &str) -> Result { + Ok(serde_json::from_str(json)?) + } + #[new] pub fn new(val: i16) -> Self { Self(val) @@ -52,10 +72,19 @@ impl DexShort { } #[pyclass] -#[derive(Debug, Clone, Copy, PartialEq, Eq)] +#[derive(Debug, Clone, Copy, PartialEq, Eq, Deserialize, Serialize)] pub struct DexChar(pub u16); #[pymethods] impl DexChar { + pub fn to_json(&self) -> Result { + Ok(serde_json::to_string(self)?) + } + + #[staticmethod] + pub fn from_json(json: &str) -> Result { + Ok(serde_json::from_str(json)?) + } + #[new] pub fn new(val: u16) -> Self { Self(val) @@ -75,10 +104,19 @@ impl DexChar { } #[pyclass] -#[derive(Debug, Clone, Copy, PartialEq, Eq)] +#[derive(Debug, Clone, Copy, PartialEq, Eq, Deserialize, Serialize)] pub struct DexInt(pub i32); #[pymethods] impl DexInt { + pub fn to_json(&self) -> Result { + Ok(serde_json::to_string(self)?) + } + + #[staticmethod] + pub fn from_json(json: &str) -> Result { + Ok(serde_json::from_str(json)?) + } + #[new] pub fn new(val: i32) -> Self { Self(val) @@ -98,10 +136,19 @@ impl DexInt { } #[pyclass] -#[derive(Debug, Clone, Copy, PartialEq, Eq)] +#[derive(Debug, Clone, Copy, PartialEq, Eq, Deserialize, Serialize)] pub struct DexLong(pub i64); #[pymethods] impl DexLong { + pub fn to_json(&self) -> Result { + Ok(serde_json::to_string(self)?) + } + + #[staticmethod] + pub fn from_json(json: &str) -> Result { + Ok(serde_json::from_str(json)?) + } + #[new] pub fn new(val: i64) -> Self { Self(val) @@ -121,10 +168,19 @@ impl DexLong { } #[pyclass] -#[derive(Debug, Clone, Copy)] +#[derive(Debug, Clone, Copy, PartialEq, Deserialize, Serialize)] pub struct DexFloat(pub f32); #[pymethods] impl DexFloat { + pub fn to_json(&self) -> Result { + Ok(serde_json::to_string(self)?) + } + + #[staticmethod] + pub fn from_json(json: &str) -> Result { + Ok(serde_json::from_str(json)?) + } + #[new] pub fn new(val: f32) -> Self { Self(val) @@ -144,10 +200,19 @@ impl DexFloat { } #[pyclass] -#[derive(Debug, Clone, Copy)] +#[derive(Debug, Clone, Copy, PartialEq, Deserialize, Serialize)] pub struct DexDouble(pub f64); #[pymethods] impl DexDouble { + pub fn to_json(&self) -> Result { + Ok(serde_json::to_string(self)?) + } + + #[staticmethod] + pub fn from_json(json: &str) -> Result { + Ok(serde_json::from_str(json)?) + } + #[new] pub fn new(val: f64) -> Self { Self(val) @@ -172,6 +237,15 @@ impl DexDouble { pub struct DexString(pub u32); #[pymethods] impl DexString { + pub fn to_json(&self) -> Result { + Ok(serde_json::to_string(self)?) + } + + #[staticmethod] + pub fn from_json(json: &str) -> Result { + Ok(serde_json::from_str(json)?) + } + #[new] pub fn new(val: u32) -> Self { Self(val) @@ -192,10 +266,19 @@ impl DexString { */ #[pyclass] -#[derive(Debug, Clone, Copy, PartialEq, Eq)] +#[derive(Debug, Clone, Copy, PartialEq, Eq, Deserialize, Serialize)] pub struct DexNull; #[pymethods] impl DexNull { + pub fn to_json(&self) -> Result { + Ok(serde_json::to_string(self)?) + } + + #[staticmethod] + pub fn from_json(json: &str) -> Result { + Ok(serde_json::from_str(json)?) + } + #[new] pub fn _new() -> Self { Self @@ -211,10 +294,19 @@ impl DexNull { } #[pyclass] -#[derive(Debug, Clone, Copy, PartialEq, Eq)] +#[derive(Debug, Clone, Copy, PartialEq, Eq, Deserialize, Serialize)] pub struct DexBoolean(pub bool); #[pymethods] impl DexBoolean { + pub fn to_json(&self) -> Result { + Ok(serde_json::to_string(self)?) + } + + #[staticmethod] + pub fn from_json(json: &str) -> Result { + Ok(serde_json::from_str(json)?) + } + #[new] pub fn new(val: bool) -> Self { Self(val) @@ -234,10 +326,19 @@ impl DexBoolean { } #[pyclass] -#[derive(Debug, Clone)] +#[derive(Debug, Clone, PartialEq, Deserialize, Serialize)] pub struct DexArray(pub Vec); #[pymethods] impl DexArray { + pub fn to_json(&self) -> Result { + Ok(serde_json::to_string(self)?) + } + + #[staticmethod] + pub fn from_json(json: &str) -> Result { + Ok(serde_json::from_str(json)?) + } + #[new] pub fn _new(arr: Vec) -> Self { Self(arr) diff --git a/androscalpel/src/value.rs b/androscalpel/src/value.rs index c8fe998..b5af3ef 100644 --- a/androscalpel/src/value.rs +++ b/androscalpel/src/value.rs @@ -1,5 +1,6 @@ //! The class identifying dex structure. +use serde::{Deserialize, Serialize}; use std::collections::HashSet; use pyo3::exceptions::PyTypeError; @@ -7,7 +8,7 @@ use pyo3::prelude::*; use crate::{dex_id::*, scalar::*, DexAnnotation, DexString, MethodHandle}; -#[derive(Debug, Clone)] +#[derive(Debug, Clone, PartialEq, Deserialize, Serialize)] pub enum DexValue { Byte(DexByte), Short(DexShort), diff --git a/test.py b/test.py index 553135f..47384f7 100644 --- a/test.py +++ b/test.py @@ -27,49 +27,49 @@ clazz = apk.classes[clazz_id] method = clazz.virtual_methods[method_id] code = method.code -logging.getLogger().setLevel(logging.ERROR) - -print(f"Code of {method_id}") -for i in code.insns: - print(i) - -new_insns = [] -for i in code.insns: - if isinstance(i, asc.ins.ConstString): - if i.lit == "Hello": - i = asc.ins.ConstString(i.reg, DexString("Degemer Mat")) - elif i.lit == "Bye": - i = asc.ins.ConstString(i.reg, DexString("Kenavo")) - new_insns.append(i) - -# This need improving! -code = asc.Code(code.registers_size, code.ins_size, code.outs_size, new_insns) -apk.set_method_code(method_id, code) -# apk.set_method_code(method.descriptor, code) - -clazz = apk.classes[clazz_id] -method = clazz.virtual_methods[method_id] -code = method.code - -print(f"Code of {method_id}") -for i in code.insns: - print(i) - -dex_raw = apk.gen_raw_dex() -assert len(dex_raw) == 1 -with open(DEX_NAME, "wb") as file: - file.write(dex_raw[0]) - - -with open(DEX_NAME, "rb") as file: - dex = file.read() -new_apk = asc.Apk() -new_apk.add_dex_file(dex) - -clazz = new_apk.classes[clazz_id] -method = clazz.virtual_methods[method_id] -code = method.code - -print(f"Code of {method_id} in new apk") -for i in code.insns: - print(i) +# logging.getLogger().setLevel(logging.ERROR) +# +# print(f"Code of {method_id}") +# for i in code.insns: +# print(i) +# +# new_insns = [] +# for i in code.insns: +# if isinstance(i, asc.ins.ConstString): +# if i.lit == "Hello": +# i = asc.ins.ConstString(i.reg, DexString("Degemer Mat")) +# elif i.lit == "Bye": +# i = asc.ins.ConstString(i.reg, DexString("Kenavo")) +# new_insns.append(i) +# +## This need improving! +# code = asc.Code(code.registers_size, code.ins_size, code.outs_size, new_insns) +# apk.set_method_code(method_id, code) +## apk.set_method_code(method.descriptor, code) +# +# clazz = apk.classes[clazz_id] +# method = clazz.virtual_methods[method_id] +# code = method.code +# +# print(f"Code of {method_id}") +# for i in code.insns: +# print(i) +# +# dex_raw = apk.gen_raw_dex() +# assert len(dex_raw) == 1 +# with open(DEX_NAME, "wb") as file: +# file.write(dex_raw[0]) +# +# +# with open(DEX_NAME, "rb") as file: +# dex = file.read() +# new_apk = asc.Apk() +# new_apk.add_dex_file(dex) +# +# clazz = new_apk.classes[clazz_id] +# method = clazz.virtual_methods[method_id] +# code = method.code +# +# print(f"Code of {method_id} in new apk") +# for i in code.insns: +# print(i)