diff options
Diffstat (limited to 'examples')
5 files changed, 34 insertions, 58 deletions
diff --git a/examples/10-transient-0/output/java/src/test/java/org/zwobble/example/Transient0Tests.java b/examples/10-transient-0/output/java/src/test/java/org/zwobble/example/Transient0Tests.java index e28e926..2ab3934 100644 --- a/examples/10-transient-0/output/java/src/test/java/org/zwobble/example/Transient0Tests.java +++ b/examples/10-transient-0/output/java/src/test/java/org/zwobble/example/Transient0Tests.java @@ -11,14 +11,13 @@ import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import org.zwobble.example.types.data.EnumWithVariants; import org.zwobble.example.types.data.HobgoblinTransient0Data; -import org.zwobble.example.types.data.InnerStruct; -import org.zwobble.example.types.data.OuterStruct; import org.zwobble.example.types.data.StructWithBool; import org.zwobble.example.types.data.StructWithInt32; import org.zwobble.example.types.data.StructWithInt64; import org.zwobble.example.types.data.StructWithList; import org.zwobble.example.types.data.StructWithOption; import org.zwobble.example.types.data.StructWithString; +import org.zwobble.example.types.data.StructWithStruct; import org.zwobble.example.types.data.VariantOne; import org.zwobble.example.types.data.VariantTwo; @@ -68,13 +67,13 @@ public class Transient0Tests { } @Test - public void nestedStruct() throws IOException { - var value = new OuterStruct(new InnerStruct(10, 25), 42); + public void structWithStruct() throws IOException { + var value = new StructWithStruct(new StructWithInt32(10, 25), 42); assertRoundTripEncoding( value, - HobgoblinTransient0Data::encodeOuterStruct, - HobgoblinTransient0Data::decodeOuterStruct + HobgoblinTransient0Data::encodeStructWithStruct, + HobgoblinTransient0Data::decodeStructWithStruct ); } @@ -83,9 +82,9 @@ public class Transient0Tests { var value = new StructWithList( List.of(10L, 25L), List.of( - new InnerStruct(42, 47), - new InnerStruct(52, 57), - new InnerStruct(62, 67) + new StructWithInt32(42, 47), + new StructWithInt32(52, 57), + new StructWithInt32(62, 67) ) ); @@ -114,7 +113,7 @@ public class Transient0Tests { public void structWithOptionSome() throws IOException { var value = new StructWithOption( Optional.of(10L), - Optional.of(new InnerStruct(42, 47)) + Optional.of(new StructWithInt32(42, 47)) ); assertRoundTripEncoding( diff --git a/examples/10-transient-0/output/rust/src/gen/data.rs b/examples/10-transient-0/output/rust/src/gen/data.rs index 814e4ca..ccabce6 100644 --- a/examples/10-transient-0/output/rust/src/gen/data.rs +++ b/examples/10-transient-0/output/rust/src/gen/data.rs @@ -25,27 +25,21 @@ pub struct StructWithString { } #[derive(Debug, PartialEq)] -pub struct OuterStruct { - pub inner: crate::data::InnerStruct, +pub struct StructWithStruct { + pub inner: crate::data::StructWithInt32, pub c: ::core::primitive::i32, } #[derive(Debug, PartialEq)] -pub struct InnerStruct { - pub a: ::core::primitive::i32, - pub b: ::core::primitive::i32, -} - -#[derive(Debug, PartialEq)] pub struct StructWithList { pub a: ::std::vec::Vec::<::core::primitive::i64>, - pub b: ::std::vec::Vec::<crate::data::InnerStruct>, + pub b: ::std::vec::Vec::<crate::data::StructWithInt32>, } #[derive(Debug, PartialEq)] pub struct StructWithOption { pub a: ::std::option::Option::<::core::primitive::i64>, - pub b: ::std::option::Option::<crate::data::InnerStruct>, + pub b: ::std::option::Option::<crate::data::StructWithInt32>, } #[derive(Debug, PartialEq)] diff --git a/examples/10-transient-0/output/rust/src/gen/data/transient_0.rs b/examples/10-transient-0/output/rust/src/gen/data/transient_0.rs index 2caeb3a..c1ded4c 100644 --- a/examples/10-transient-0/output/rust/src/gen/data/transient_0.rs +++ b/examples/10-transient-0/output/rust/src/gen/data/transient_0.rs @@ -48,28 +48,16 @@ pub fn decode_struct_with_string(reader: &mut impl std::io::Read) -> ::std::io:: std::io::Result::Ok(crate::data::StructWithString { a: a, b: b }) } -pub fn encode_outer_struct(value: &crate::data::OuterStruct, writer: &mut impl std::io::Write) -> ::std::io::Result::<()> { - crate::data::transient_0::encode_inner_struct(&value.inner, writer)?; +pub fn encode_struct_with_struct(value: &crate::data::StructWithStruct, writer: &mut impl std::io::Write) -> ::std::io::Result::<()> { + crate::data::transient_0::encode_struct_with_int_32(&value.inner, writer)?; crate::transient_0::encode_int_32(&value.c, writer)?; ::std::io::Result::Ok(()) } -pub fn decode_outer_struct(reader: &mut impl std::io::Read) -> ::std::io::Result::<crate::data::OuterStruct> { - let inner = crate::data::transient_0::decode_inner_struct(reader)?; +pub fn decode_struct_with_struct(reader: &mut impl std::io::Read) -> ::std::io::Result::<crate::data::StructWithStruct> { + let inner = crate::data::transient_0::decode_struct_with_int_32(reader)?; let c = crate::transient_0::decode_int_32(reader)?; - std::io::Result::Ok(crate::data::OuterStruct { inner: inner, c: c }) -} - -pub fn encode_inner_struct(value: &crate::data::InnerStruct, writer: &mut impl std::io::Write) -> ::std::io::Result::<()> { - crate::transient_0::encode_int_32(&value.a, writer)?; - crate::transient_0::encode_int_32(&value.b, writer)?; - ::std::io::Result::Ok(()) -} - -pub fn decode_inner_struct(reader: &mut impl std::io::Read) -> ::std::io::Result::<crate::data::InnerStruct> { - let a = crate::transient_0::decode_int_32(reader)?; - let b = crate::transient_0::decode_int_32(reader)?; - std::io::Result::Ok(crate::data::InnerStruct { a: a, b: b }) + std::io::Result::Ok(crate::data::StructWithStruct { inner: inner, c: c }) } pub fn encode_struct_with_list(value: &crate::data::StructWithList, writer: &mut impl std::io::Write) -> ::std::io::Result::<()> { @@ -82,7 +70,7 @@ pub fn encode_struct_with_list(value: &crate::data::StructWithList, writer: &mut { crate::transient_0::encode_int_64(&(((&value.b).len()).try_into()).map_err(|error| ::std::io::Error::new(::std::io::ErrorKind::InvalidData, error))?, writer)?; for element in &value.b { - crate::data::transient_0::encode_inner_struct(element, writer)?; + crate::data::transient_0::encode_struct_with_int_32(element, writer)?; }; }; ::std::io::Result::Ok(()) @@ -101,7 +89,7 @@ pub fn decode_struct_with_list(reader: &mut impl std::io::Read) -> ::std::io::Re let len = crate::transient_0::decode_int_64(reader)?; let mut elements = ::std::vec::Vec::with_capacity((len.try_into()).map_err(|error| ::std::io::Error::new(::std::io::ErrorKind::InvalidData, error))?); for _ in 0..len { - elements.push(crate::data::transient_0::decode_inner_struct(reader)?); + elements.push(crate::data::transient_0::decode_struct_with_int_32(reader)?); }; elements }; @@ -121,7 +109,7 @@ pub fn encode_struct_with_option(value: &crate::data::StructWithOption, writer: match &value.b { ::std::option::Option::Some(value) => { crate::transient_0::encode_bool(&true, writer)?; - crate::data::transient_0::encode_inner_struct(&value, writer)?; + crate::data::transient_0::encode_struct_with_int_32(&value, writer)?; }, ::std::option::Option::None => { crate::transient_0::encode_bool(&false, writer)?; @@ -142,7 +130,7 @@ pub fn decode_struct_with_option(reader: &mut impl std::io::Read) -> ::std::io:: let b = { let is_some = crate::transient_0::decode_bool(reader)?; if is_some { - ::std::option::Option::Some(crate::data::transient_0::decode_inner_struct(reader)?) + ::std::option::Option::Some(crate::data::transient_0::decode_struct_with_int_32(reader)?) } else { ::std::option::Option::None } diff --git a/examples/10-transient-0/output/rust/src/lib.rs b/examples/10-transient-0/output/rust/src/lib.rs index 3aa9751..b736203 100644 --- a/examples/10-transient-0/output/rust/src/lib.rs +++ b/examples/10-transient-0/output/rust/src/lib.rs @@ -4,7 +4,7 @@ pub mod transient_0; #[cfg(test)] mod test { use std::io::Cursor; - use super::data::{EnumWithVariants, InnerStruct, OuterStruct, StructWithBool, StructWithInt32, StructWithInt64, StructWithList, StructWithOption, StructWithString, SumWithVariants, VariantOne, VariantTwo }; + use super::data::{EnumWithVariants, StructWithBool, StructWithInt32, StructWithInt64, StructWithList, StructWithOption, StructWithString, StructWithStruct, SumWithVariants, VariantOne, VariantTwo }; #[test] fn struct_with_bool() { @@ -52,12 +52,12 @@ mod test { #[test] fn nested_struct() { - let value = OuterStruct { inner: InnerStruct { a: 10, b: 25 }, c: 42 }; + let value = StructWithStruct { inner: StructWithInt32 { a: 10, b: 25 }, c: 42 }; assert_round_trip_encoding( value, - super::data::transient_0::encode_outer_struct, - super::data::transient_0::decode_outer_struct, + super::data::transient_0::encode_struct_with_struct, + super::data::transient_0::decode_struct_with_struct, ); } @@ -66,9 +66,9 @@ mod test { let value = StructWithList { a: vec![10, 25], b: vec![ - InnerStruct { a: 42, b: 47 }, - InnerStruct { a: 52, b: 57 }, - InnerStruct { a: 62, b: 67 }, + StructWithInt32 { a: 42, b: 47 }, + StructWithInt32 { a: 52, b: 57 }, + StructWithInt32 { a: 62, b: 67 }, ], }; @@ -97,7 +97,7 @@ mod test { fn struct_with_option_some() { let value = StructWithOption { a: Some(10), - b: Some(InnerStruct { a: 42, b: 47 }), + b: Some(StructWithInt32 { a: 42, b: 47 }), }; assert_round_trip_encoding( diff --git a/examples/10-transient-0/src/data.hob b/examples/10-transient-0/src/data.hob index e1d7290..5f82992 100644 --- a/examples/10-transient-0/src/data.hob +++ b/examples/10-transient-0/src/data.hob @@ -18,24 +18,19 @@ struct StructWithString { field b: String; } -struct OuterStruct { - field inner: InnerStruct; +struct StructWithStruct { + field inner: StructWithInt32; field c: Int32; } -struct InnerStruct { - field a: Int32; - field b: Int32; -} - struct StructWithList { field a: List[Int64]; - field b: List[InnerStruct]; + field b: List[StructWithInt32]; } struct StructWithOption { field a: Option[Int64]; - field b: Option[InnerStruct]; + field b: Option[StructWithInt32]; } enum EnumWithVariants { |
