Skip to content

Commit

Permalink
read
Browse files Browse the repository at this point in the history
  • Loading branch information
leighmcculloch committed Oct 18, 2023
1 parent a009f43 commit 8b3b384
Show file tree
Hide file tree
Showing 9 changed files with 54 additions and 54 deletions.
4 changes: 2 additions & 2 deletions lib/xdrgen/generators/rust.rb
Original file line number Diff line number Diff line change
Expand Up @@ -240,9 +240,9 @@ def render_enum_of_all_types(out, types)
#[cfg(feature = "serde_json")]
#[allow(clippy::too_many_lines)]
pub fn from_json(v: TypeVariant, s: &str) -> Result<Self> {
pub fn read_json(v: TypeVariant, r: impl Read) -> Result<Self> {
match v {
#{types.map { |t| "TypeVariant::#{t} => Ok(Self::#{t}(Box::new(serde_json::from_str(s)?)))," }.join("\n")}
#{types.map { |t| "TypeVariant::#{t} => Ok(Self::#{t}(Box::new(serde_json::from_reader(r)?)))," }.join("\n")}
}
}
Expand Down
4 changes: 2 additions & 2 deletions spec/output/generator_spec_rust/block_comments.x/MyXDR.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2521,9 +2521,9 @@ impl Type {

#[cfg(feature = "serde_json")]
#[allow(clippy::too_many_lines)]
pub fn from_json(v: TypeVariant, s: &str) -> Result<Self> {
pub fn read_json(v: TypeVariant, r: impl Read) -> Result<Self> {
match v {
TypeVariant::AccountFlags => Ok(Self::AccountFlags(Box::new(serde_json::from_str(s)?))),
TypeVariant::AccountFlags => Ok(Self::AccountFlags(Box::new(serde_json::from_reader(r)?))),
}
}

Expand Down
6 changes: 3 additions & 3 deletions spec/output/generator_spec_rust/const.x/MyXDR.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2456,10 +2456,10 @@ TypeVariant::TestArray2 => Box::new(ReadXdrIter::<_, TestArray2>::new(dec, r.dep

#[cfg(feature = "serde_json")]
#[allow(clippy::too_many_lines)]
pub fn from_json(v: TypeVariant, s: &str) -> Result<Self> {
pub fn read_json(v: TypeVariant, r: impl Read) -> Result<Self> {
match v {
TypeVariant::TestArray => Ok(Self::TestArray(Box::new(serde_json::from_str(s)?))),
TypeVariant::TestArray2 => Ok(Self::TestArray2(Box::new(serde_json::from_str(s)?))),
TypeVariant::TestArray => Ok(Self::TestArray(Box::new(serde_json::from_reader(r)?))),
TypeVariant::TestArray2 => Ok(Self::TestArray2(Box::new(serde_json::from_reader(r)?))),
}
}

Expand Down
8 changes: 4 additions & 4 deletions spec/output/generator_spec_rust/enum.x/MyXDR.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2841,11 +2841,11 @@ TypeVariant::Color2 => Box::new(ReadXdrIter::<_, Color2>::new(dec, r.depth_remai

#[cfg(feature = "serde_json")]
#[allow(clippy::too_many_lines)]
pub fn from_json(v: TypeVariant, s: &str) -> Result<Self> {
pub fn read_json(v: TypeVariant, r: impl Read) -> Result<Self> {
match v {
TypeVariant::MessageType => Ok(Self::MessageType(Box::new(serde_json::from_str(s)?))),
TypeVariant::Color => Ok(Self::Color(Box::new(serde_json::from_str(s)?))),
TypeVariant::Color2 => Ok(Self::Color2(Box::new(serde_json::from_str(s)?))),
TypeVariant::MessageType => Ok(Self::MessageType(Box::new(serde_json::from_reader(r)?))),
TypeVariant::Color => Ok(Self::Color(Box::new(serde_json::from_reader(r)?))),
TypeVariant::Color2 => Ok(Self::Color2(Box::new(serde_json::from_reader(r)?))),
}
}

Expand Down
12 changes: 6 additions & 6 deletions spec/output/generator_spec_rust/nesting.x/MyXDR.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2781,13 +2781,13 @@ TypeVariant::MyUnionTwo => Box::new(ReadXdrIter::<_, MyUnionTwo>::new(dec, r.dep

#[cfg(feature = "serde_json")]
#[allow(clippy::too_many_lines)]
pub fn from_json(v: TypeVariant, s: &str) -> Result<Self> {
pub fn read_json(v: TypeVariant, r: impl Read) -> Result<Self> {
match v {
TypeVariant::UnionKey => Ok(Self::UnionKey(Box::new(serde_json::from_str(s)?))),
TypeVariant::Foo => Ok(Self::Foo(Box::new(serde_json::from_str(s)?))),
TypeVariant::MyUnion => Ok(Self::MyUnion(Box::new(serde_json::from_str(s)?))),
TypeVariant::MyUnionOne => Ok(Self::MyUnionOne(Box::new(serde_json::from_str(s)?))),
TypeVariant::MyUnionTwo => Ok(Self::MyUnionTwo(Box::new(serde_json::from_str(s)?))),
TypeVariant::UnionKey => Ok(Self::UnionKey(Box::new(serde_json::from_reader(r)?))),
TypeVariant::Foo => Ok(Self::Foo(Box::new(serde_json::from_reader(r)?))),
TypeVariant::MyUnion => Ok(Self::MyUnion(Box::new(serde_json::from_reader(r)?))),
TypeVariant::MyUnionOne => Ok(Self::MyUnionOne(Box::new(serde_json::from_reader(r)?))),
TypeVariant::MyUnionTwo => Ok(Self::MyUnionTwo(Box::new(serde_json::from_reader(r)?))),
}
}

Expand Down
6 changes: 3 additions & 3 deletions spec/output/generator_spec_rust/optional.x/MyXDR.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2487,10 +2487,10 @@ TypeVariant::HasOptions => Box::new(ReadXdrIter::<_, HasOptions>::new(dec, r.dep

#[cfg(feature = "serde_json")]
#[allow(clippy::too_many_lines)]
pub fn from_json(v: TypeVariant, s: &str) -> Result<Self> {
pub fn read_json(v: TypeVariant, r: impl Read) -> Result<Self> {
match v {
TypeVariant::Arr => Ok(Self::Arr(Box::new(serde_json::from_str(s)?))),
TypeVariant::HasOptions => Ok(Self::HasOptions(Box::new(serde_json::from_str(s)?))),
TypeVariant::Arr => Ok(Self::Arr(Box::new(serde_json::from_reader(r)?))),
TypeVariant::HasOptions => Ok(Self::HasOptions(Box::new(serde_json::from_reader(r)?))),
}
}

Expand Down
6 changes: 3 additions & 3 deletions spec/output/generator_spec_rust/struct.x/MyXDR.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2495,10 +2495,10 @@ TypeVariant::MyStruct => Box::new(ReadXdrIter::<_, MyStruct>::new(dec, r.depth_r

#[cfg(feature = "serde_json")]
#[allow(clippy::too_many_lines)]
pub fn from_json(v: TypeVariant, s: &str) -> Result<Self> {
pub fn read_json(v: TypeVariant, r: impl Read) -> Result<Self> {
match v {
TypeVariant::Int64 => Ok(Self::Int64(Box::new(serde_json::from_str(s)?))),
TypeVariant::MyStruct => Ok(Self::MyStruct(Box::new(serde_json::from_str(s)?))),
TypeVariant::Int64 => Ok(Self::Int64(Box::new(serde_json::from_reader(r)?))),
TypeVariant::MyStruct => Ok(Self::MyStruct(Box::new(serde_json::from_reader(r)?))),
}
}

Expand Down
48 changes: 24 additions & 24 deletions spec/output/generator_spec_rust/test.x/MyXDR.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4257,31 +4257,31 @@ TypeVariant::NesterNestedUnion => Box::new(ReadXdrIter::<_, NesterNestedUnion>::

#[cfg(feature = "serde_json")]
#[allow(clippy::too_many_lines)]
pub fn from_json(v: TypeVariant, s: &str) -> Result<Self> {
pub fn read_json(v: TypeVariant, r: impl Read) -> Result<Self> {
match v {
TypeVariant::Uint512 => Ok(Self::Uint512(Box::new(serde_json::from_str(s)?))),
TypeVariant::Uint513 => Ok(Self::Uint513(Box::new(serde_json::from_str(s)?))),
TypeVariant::Uint514 => Ok(Self::Uint514(Box::new(serde_json::from_str(s)?))),
TypeVariant::Str => Ok(Self::Str(Box::new(serde_json::from_str(s)?))),
TypeVariant::Str2 => Ok(Self::Str2(Box::new(serde_json::from_str(s)?))),
TypeVariant::Hash => Ok(Self::Hash(Box::new(serde_json::from_str(s)?))),
TypeVariant::Hashes1 => Ok(Self::Hashes1(Box::new(serde_json::from_str(s)?))),
TypeVariant::Hashes2 => Ok(Self::Hashes2(Box::new(serde_json::from_str(s)?))),
TypeVariant::Hashes3 => Ok(Self::Hashes3(Box::new(serde_json::from_str(s)?))),
TypeVariant::OptHash1 => Ok(Self::OptHash1(Box::new(serde_json::from_str(s)?))),
TypeVariant::OptHash2 => Ok(Self::OptHash2(Box::new(serde_json::from_str(s)?))),
TypeVariant::Int1 => Ok(Self::Int1(Box::new(serde_json::from_str(s)?))),
TypeVariant::Int2 => Ok(Self::Int2(Box::new(serde_json::from_str(s)?))),
TypeVariant::Int3 => Ok(Self::Int3(Box::new(serde_json::from_str(s)?))),
TypeVariant::Int4 => Ok(Self::Int4(Box::new(serde_json::from_str(s)?))),
TypeVariant::MyStruct => Ok(Self::MyStruct(Box::new(serde_json::from_str(s)?))),
TypeVariant::LotsOfMyStructs => Ok(Self::LotsOfMyStructs(Box::new(serde_json::from_str(s)?))),
TypeVariant::HasStuff => Ok(Self::HasStuff(Box::new(serde_json::from_str(s)?))),
TypeVariant::Color => Ok(Self::Color(Box::new(serde_json::from_str(s)?))),
TypeVariant::Nester => Ok(Self::Nester(Box::new(serde_json::from_str(s)?))),
TypeVariant::NesterNestedEnum => Ok(Self::NesterNestedEnum(Box::new(serde_json::from_str(s)?))),
TypeVariant::NesterNestedStruct => Ok(Self::NesterNestedStruct(Box::new(serde_json::from_str(s)?))),
TypeVariant::NesterNestedUnion => Ok(Self::NesterNestedUnion(Box::new(serde_json::from_str(s)?))),
TypeVariant::Uint512 => Ok(Self::Uint512(Box::new(serde_json::from_reader(r)?))),
TypeVariant::Uint513 => Ok(Self::Uint513(Box::new(serde_json::from_reader(r)?))),
TypeVariant::Uint514 => Ok(Self::Uint514(Box::new(serde_json::from_reader(r)?))),
TypeVariant::Str => Ok(Self::Str(Box::new(serde_json::from_reader(r)?))),
TypeVariant::Str2 => Ok(Self::Str2(Box::new(serde_json::from_reader(r)?))),
TypeVariant::Hash => Ok(Self::Hash(Box::new(serde_json::from_reader(r)?))),
TypeVariant::Hashes1 => Ok(Self::Hashes1(Box::new(serde_json::from_reader(r)?))),
TypeVariant::Hashes2 => Ok(Self::Hashes2(Box::new(serde_json::from_reader(r)?))),
TypeVariant::Hashes3 => Ok(Self::Hashes3(Box::new(serde_json::from_reader(r)?))),
TypeVariant::OptHash1 => Ok(Self::OptHash1(Box::new(serde_json::from_reader(r)?))),
TypeVariant::OptHash2 => Ok(Self::OptHash2(Box::new(serde_json::from_reader(r)?))),
TypeVariant::Int1 => Ok(Self::Int1(Box::new(serde_json::from_reader(r)?))),
TypeVariant::Int2 => Ok(Self::Int2(Box::new(serde_json::from_reader(r)?))),
TypeVariant::Int3 => Ok(Self::Int3(Box::new(serde_json::from_reader(r)?))),
TypeVariant::Int4 => Ok(Self::Int4(Box::new(serde_json::from_reader(r)?))),
TypeVariant::MyStruct => Ok(Self::MyStruct(Box::new(serde_json::from_reader(r)?))),
TypeVariant::LotsOfMyStructs => Ok(Self::LotsOfMyStructs(Box::new(serde_json::from_reader(r)?))),
TypeVariant::HasStuff => Ok(Self::HasStuff(Box::new(serde_json::from_reader(r)?))),
TypeVariant::Color => Ok(Self::Color(Box::new(serde_json::from_reader(r)?))),
TypeVariant::Nester => Ok(Self::Nester(Box::new(serde_json::from_reader(r)?))),
TypeVariant::NesterNestedEnum => Ok(Self::NesterNestedEnum(Box::new(serde_json::from_reader(r)?))),
TypeVariant::NesterNestedStruct => Ok(Self::NesterNestedStruct(Box::new(serde_json::from_reader(r)?))),
TypeVariant::NesterNestedUnion => Ok(Self::NesterNestedUnion(Box::new(serde_json::from_reader(r)?))),
}
}

Expand Down
14 changes: 7 additions & 7 deletions spec/output/generator_spec_rust/union.x/MyXDR.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2864,14 +2864,14 @@ TypeVariant::IntUnion2 => Box::new(ReadXdrIter::<_, IntUnion2>::new(dec, r.depth

#[cfg(feature = "serde_json")]
#[allow(clippy::too_many_lines)]
pub fn from_json(v: TypeVariant, s: &str) -> Result<Self> {
pub fn read_json(v: TypeVariant, r: impl Read) -> Result<Self> {
match v {
TypeVariant::SError => Ok(Self::SError(Box::new(serde_json::from_str(s)?))),
TypeVariant::Multi => Ok(Self::Multi(Box::new(serde_json::from_str(s)?))),
TypeVariant::UnionKey => Ok(Self::UnionKey(Box::new(serde_json::from_str(s)?))),
TypeVariant::MyUnion => Ok(Self::MyUnion(Box::new(serde_json::from_str(s)?))),
TypeVariant::IntUnion => Ok(Self::IntUnion(Box::new(serde_json::from_str(s)?))),
TypeVariant::IntUnion2 => Ok(Self::IntUnion2(Box::new(serde_json::from_str(s)?))),
TypeVariant::SError => Ok(Self::SError(Box::new(serde_json::from_reader(r)?))),
TypeVariant::Multi => Ok(Self::Multi(Box::new(serde_json::from_reader(r)?))),
TypeVariant::UnionKey => Ok(Self::UnionKey(Box::new(serde_json::from_reader(r)?))),
TypeVariant::MyUnion => Ok(Self::MyUnion(Box::new(serde_json::from_reader(r)?))),
TypeVariant::IntUnion => Ok(Self::IntUnion(Box::new(serde_json::from_reader(r)?))),
TypeVariant::IntUnion2 => Ok(Self::IntUnion2(Box::new(serde_json::from_reader(r)?))),
}
}

Expand Down

0 comments on commit 8b3b384

Please sign in to comment.