diff options
| author | Michael Williamson <mike@zwobble.org> | 2026-08-10 10:19:49 +0100 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2026-08-10 10:19:49 +0100 |
| commit | 5113f2157c5aa257ad7ebf555cb6a551701d169a (patch) | |
| tree | 8ddaee09f6c43b0529b2203f9e662a028fb5fcc0 /examples/15-transient-0 | |
| parent | 5d41166750e0f05da436bf30c7a642749f7a71c5 (diff) | |
Add generic struct example without any outputs
Diffstat (limited to 'examples/15-transient-0')
23 files changed, 0 insertions, 2471 deletions
diff --git a/examples/15-transient-0/hobgoblin.json5 b/examples/15-transient-0/hobgoblin.json5 deleted file mode 100644 index e632b0a..0000000 --- a/examples/15-transient-0/hobgoblin.json5 +++ /dev/null @@ -1,27 +0,0 @@ -{ - outputs: { - langs: { - java: { - packageName: "org.zwobble.example.types", - }, - }, - generators: [ - { - generator: "java-types", - path: "output/java/src/gen/java", - }, - { - generator: "java-transient-0", - path: "output/java/src/main/java", - }, - { - generator: "rust-types", - path: "output/rust/src/gen", - }, - { - generator: "rust-transient-0", - path: "output/rust/src/gen", - } - ], - } -} diff --git a/examples/15-transient-0/output/java/.gitignore b/examples/15-transient-0/output/java/.gitignore deleted file mode 100644 index 2fcf0b8..0000000 --- a/examples/15-transient-0/output/java/.gitignore +++ /dev/null @@ -1,3 +0,0 @@ -/src/gen/ -/target/ -/transient-0/ diff --git a/examples/15-transient-0/output/java/pom.xml b/examples/15-transient-0/output/java/pom.xml deleted file mode 120000 index 445fa65..0000000 --- a/examples/15-transient-0/output/java/pom.xml +++ /dev/null @@ -1 +0,0 @@ -../../../templates/java-junit/pom.xml
\ No newline at end of file diff --git a/examples/15-transient-0/output/java/src/main/java/org/zwobble/example/types/data/GenericNative.java b/examples/15-transient-0/output/java/src/main/java/org/zwobble/example/types/data/GenericNative.java deleted file mode 100644 index cfd16d5..0000000 --- a/examples/15-transient-0/output/java/src/main/java/org/zwobble/example/types/data/GenericNative.java +++ /dev/null @@ -1,3 +0,0 @@ -package org.zwobble.example.types.data; - -public record GenericNative<A, B>(A a, B b) {} diff --git a/examples/15-transient-0/output/java/src/main/java/org/zwobble/example/types/data/HobgoblinNativeData.java b/examples/15-transient-0/output/java/src/main/java/org/zwobble/example/types/data/HobgoblinNativeData.java deleted file mode 100644 index 32796b5..0000000 --- a/examples/15-transient-0/output/java/src/main/java/org/zwobble/example/types/data/HobgoblinNativeData.java +++ /dev/null @@ -1,13 +0,0 @@ -package org.zwobble.example.types.data; - -public class HobgoblinNativeData { - private HobgoblinNativeData() {} - - public static Native arbitraryNative() { - return new Native(0, 0); - } - - public static <A, B> GenericNative<A, B> arbitraryGenericNative() { - throw new RuntimeException("TODO"); - } -} diff --git a/examples/15-transient-0/output/java/src/main/java/org/zwobble/example/types/data/Native.java b/examples/15-transient-0/output/java/src/main/java/org/zwobble/example/types/data/Native.java deleted file mode 100644 index 366dd74..0000000 --- a/examples/15-transient-0/output/java/src/main/java/org/zwobble/example/types/data/Native.java +++ /dev/null @@ -1,3 +0,0 @@ -package org.zwobble.example.types.data; - -public record Native(int a, int b) {} diff --git a/examples/15-transient-0/output/java/src/main/java/org/zwobble/example/types/data/transient0/HobgoblinTransient0Data.java b/examples/15-transient-0/output/java/src/main/java/org/zwobble/example/types/data/transient0/HobgoblinTransient0Data.java deleted file mode 100644 index 1eea54c..0000000 --- a/examples/15-transient-0/output/java/src/main/java/org/zwobble/example/types/data/transient0/HobgoblinTransient0Data.java +++ /dev/null @@ -1,581 +0,0 @@ -// Generated by hobgoblin. - -package org.zwobble.example.types.data.transient0; - -// Custom area start: org.zwobble.example.types.data.transient0.HobgoblinTransient0Data imports -import java.io.InputStream; -import java.io.IOException; -import java.io.OutputStream; -import java.util.List; -import java.util.Map; -import org.zwobble.example.types.data.GenericNative; -import org.zwobble.example.types.data.Native; -import org.zwobble.example.types.transient0.Decoder; -import org.zwobble.example.types.transient0.Encoder; -import org.zwobble.example.types.transient0.HobgoblinTransient0Builtins; -import org.zwobble.example.types.transient0.HobgoblinTransient0TaggedSharedValue; -// Custom area end: org.zwobble.example.types.data.transient0.HobgoblinTransient0Data imports - -public final class HobgoblinTransient0Data { - public static void encodeStructSingleton(org.zwobble.example.types.data.StructSingleton value, java.io.OutputStream outputStream, java.util.Map<org.zwobble.example.types.transient0.HobgoblinTransient0TaggedSharedValue, java.lang.Long> sharedValues) throws java.io.IOException { - } - - public static org.zwobble.example.types.data.StructSingleton decodeStructSingleton(java.io.InputStream inputStream, java.util.List<java.lang.Object> sharedValues) throws java.io.IOException { - return org.zwobble.example.types.data.StructSingleton.INSTANCE; - } - - public static void encodeStructWithBool(org.zwobble.example.types.data.StructWithBool value, java.io.OutputStream outputStream, java.util.Map<org.zwobble.example.types.transient0.HobgoblinTransient0TaggedSharedValue, java.lang.Long> sharedValues) throws java.io.IOException { - org.zwobble.example.types.transient0.HobgoblinTransient0Builtins.encodeBool(value.a(), outputStream, sharedValues); - org.zwobble.example.types.transient0.HobgoblinTransient0Builtins.encodeBool(value.b(), outputStream, sharedValues); - } - - public static org.zwobble.example.types.data.StructWithBool decodeStructWithBool(java.io.InputStream inputStream, java.util.List<java.lang.Object> sharedValues) throws java.io.IOException { - var a = org.zwobble.example.types.transient0.HobgoblinTransient0Builtins.decodeBool(inputStream, sharedValues); - var b = org.zwobble.example.types.transient0.HobgoblinTransient0Builtins.decodeBool(inputStream, sharedValues); - return new org.zwobble.example.types.data.StructWithBool(a, b); - } - - public static void encodeStructWithInt8(org.zwobble.example.types.data.StructWithInt8 value, java.io.OutputStream outputStream, java.util.Map<org.zwobble.example.types.transient0.HobgoblinTransient0TaggedSharedValue, java.lang.Long> sharedValues) throws java.io.IOException { - org.zwobble.example.types.transient0.HobgoblinTransient0Builtins.encodeInt8(value.a(), outputStream, sharedValues); - org.zwobble.example.types.transient0.HobgoblinTransient0Builtins.encodeInt8(value.b(), outputStream, sharedValues); - } - - public static org.zwobble.example.types.data.StructWithInt8 decodeStructWithInt8(java.io.InputStream inputStream, java.util.List<java.lang.Object> sharedValues) throws java.io.IOException { - var a = org.zwobble.example.types.transient0.HobgoblinTransient0Builtins.decodeInt8(inputStream, sharedValues); - var b = org.zwobble.example.types.transient0.HobgoblinTransient0Builtins.decodeInt8(inputStream, sharedValues); - return new org.zwobble.example.types.data.StructWithInt8(a, b); - } - - public static void encodeStructWithInt32(org.zwobble.example.types.data.StructWithInt32 value, java.io.OutputStream outputStream, java.util.Map<org.zwobble.example.types.transient0.HobgoblinTransient0TaggedSharedValue, java.lang.Long> sharedValues) throws java.io.IOException { - org.zwobble.example.types.transient0.HobgoblinTransient0Builtins.encodeInt32(value.a(), outputStream, sharedValues); - org.zwobble.example.types.transient0.HobgoblinTransient0Builtins.encodeInt32(value.b(), outputStream, sharedValues); - } - - public static org.zwobble.example.types.data.StructWithInt32 decodeStructWithInt32(java.io.InputStream inputStream, java.util.List<java.lang.Object> sharedValues) throws java.io.IOException { - var a = org.zwobble.example.types.transient0.HobgoblinTransient0Builtins.decodeInt32(inputStream, sharedValues); - var b = org.zwobble.example.types.transient0.HobgoblinTransient0Builtins.decodeInt32(inputStream, sharedValues); - return new org.zwobble.example.types.data.StructWithInt32(a, b); - } - - public static void encodeStructWithInt64(org.zwobble.example.types.data.StructWithInt64 value, java.io.OutputStream outputStream, java.util.Map<org.zwobble.example.types.transient0.HobgoblinTransient0TaggedSharedValue, java.lang.Long> sharedValues) throws java.io.IOException { - org.zwobble.example.types.transient0.HobgoblinTransient0Builtins.encodeInt64(value.a(), outputStream, sharedValues); - org.zwobble.example.types.transient0.HobgoblinTransient0Builtins.encodeInt64(value.b(), outputStream, sharedValues); - } - - public static org.zwobble.example.types.data.StructWithInt64 decodeStructWithInt64(java.io.InputStream inputStream, java.util.List<java.lang.Object> sharedValues) throws java.io.IOException { - var a = org.zwobble.example.types.transient0.HobgoblinTransient0Builtins.decodeInt64(inputStream, sharedValues); - var b = org.zwobble.example.types.transient0.HobgoblinTransient0Builtins.decodeInt64(inputStream, sharedValues); - return new org.zwobble.example.types.data.StructWithInt64(a, b); - } - - public static void encodeStructWithString(org.zwobble.example.types.data.StructWithString value, java.io.OutputStream outputStream, java.util.Map<org.zwobble.example.types.transient0.HobgoblinTransient0TaggedSharedValue, java.lang.Long> sharedValues) throws java.io.IOException { - org.zwobble.example.types.transient0.HobgoblinTransient0Builtins.encodeString(value.a(), outputStream, sharedValues); - org.zwobble.example.types.transient0.HobgoblinTransient0Builtins.encodeString(value.b(), outputStream, sharedValues); - } - - public static org.zwobble.example.types.data.StructWithString decodeStructWithString(java.io.InputStream inputStream, java.util.List<java.lang.Object> sharedValues) throws java.io.IOException { - var a = org.zwobble.example.types.transient0.HobgoblinTransient0Builtins.decodeString(inputStream, sharedValues); - var b = org.zwobble.example.types.transient0.HobgoblinTransient0Builtins.decodeString(inputStream, sharedValues); - return new org.zwobble.example.types.data.StructWithString(a, b); - } - - public static void encodeStructWithStruct(org.zwobble.example.types.data.StructWithStruct value, java.io.OutputStream outputStream, java.util.Map<org.zwobble.example.types.transient0.HobgoblinTransient0TaggedSharedValue, java.lang.Long> sharedValues) throws java.io.IOException { - org.zwobble.example.types.data.transient0.HobgoblinTransient0Data.encodeStructWithInt32(value.inner(), outputStream, sharedValues); - org.zwobble.example.types.transient0.HobgoblinTransient0Builtins.encodeInt32(value.c(), outputStream, sharedValues); - } - - public static org.zwobble.example.types.data.StructWithStruct decodeStructWithStruct(java.io.InputStream inputStream, java.util.List<java.lang.Object> sharedValues) throws java.io.IOException { - var inner = org.zwobble.example.types.data.transient0.HobgoblinTransient0Data.decodeStructWithInt32(inputStream, sharedValues); - var c = org.zwobble.example.types.transient0.HobgoblinTransient0Builtins.decodeInt32(inputStream, sharedValues); - return new org.zwobble.example.types.data.StructWithStruct(inner, c); - } - - public static void encodeStructWithList(org.zwobble.example.types.data.StructWithList value, java.io.OutputStream outputStream, java.util.Map<org.zwobble.example.types.transient0.HobgoblinTransient0TaggedSharedValue, java.lang.Long> sharedValues) throws java.io.IOException { - org.zwobble.example.types.transient0.HobgoblinTransient0Builtins.encodeInt64((long) value.a().size(), outputStream, sharedValues); - for (var element : value.a()) { - org.zwobble.example.types.transient0.HobgoblinTransient0Builtins.encodeInt64(element, outputStream, sharedValues); - } - org.zwobble.example.types.transient0.HobgoblinTransient0Builtins.encodeInt64((long) value.b().size(), outputStream, sharedValues); - for (var element : value.b()) { - org.zwobble.example.types.data.transient0.HobgoblinTransient0Data.encodeStructWithInt32(element, outputStream, sharedValues); - } - } - - public static org.zwobble.example.types.data.StructWithList decodeStructWithList(java.io.InputStream inputStream, java.util.List<java.lang.Object> sharedValues) throws java.io.IOException { - var a$size = org.zwobble.example.types.transient0.HobgoblinTransient0Builtins.decodeInt64(inputStream, sharedValues); - if (a$size > java.lang.Integer.MAX_VALUE) { - throw new java.io.IOException("Lists longer than Integer.MAX_VALUE are not supported"); - } - var a = new java.util.ArrayList<java.lang.Long>((int) a$size); - for (long a$index = 0; a$index < a$size; a$index++) { - var a$element = org.zwobble.example.types.transient0.HobgoblinTransient0Builtins.decodeInt64(inputStream, sharedValues); - a.add(a$element); - } - var b$size = org.zwobble.example.types.transient0.HobgoblinTransient0Builtins.decodeInt64(inputStream, sharedValues); - if (b$size > java.lang.Integer.MAX_VALUE) { - throw new java.io.IOException("Lists longer than Integer.MAX_VALUE are not supported"); - } - var b = new java.util.ArrayList<org.zwobble.example.types.data.StructWithInt32>((int) b$size); - for (long b$index = 0; b$index < b$size; b$index++) { - var b$element = org.zwobble.example.types.data.transient0.HobgoblinTransient0Data.decodeStructWithInt32(inputStream, sharedValues); - b.add(b$element); - } - return new org.zwobble.example.types.data.StructWithList(a, b); - } - - public static void encodeStructWithOption(org.zwobble.example.types.data.StructWithOption value, java.io.OutputStream outputStream, java.util.Map<org.zwobble.example.types.transient0.HobgoblinTransient0TaggedSharedValue, java.lang.Long> sharedValues) throws java.io.IOException { - org.zwobble.example.types.transient0.HobgoblinTransient0Builtins.encodeBool(value.a().isPresent(), outputStream, sharedValues); - if (value.a().isPresent()) { - org.zwobble.example.types.transient0.HobgoblinTransient0Builtins.encodeInt64(value.a().get(), outputStream, sharedValues); - } - org.zwobble.example.types.transient0.HobgoblinTransient0Builtins.encodeBool(value.b().isPresent(), outputStream, sharedValues); - if (value.b().isPresent()) { - org.zwobble.example.types.data.transient0.HobgoblinTransient0Data.encodeStructWithInt32(value.b().get(), outputStream, sharedValues); - } - } - - public static org.zwobble.example.types.data.StructWithOption decodeStructWithOption(java.io.InputStream inputStream, java.util.List<java.lang.Object> sharedValues) throws java.io.IOException { - var a$isPresent = org.zwobble.example.types.transient0.HobgoblinTransient0Builtins.decodeBool(inputStream, sharedValues); - java.util.Optional<java.lang.Long> a; - if (a$isPresent) { - var a$element = org.zwobble.example.types.transient0.HobgoblinTransient0Builtins.decodeInt64(inputStream, sharedValues); - a = java.util.Optional.of(a$element); - } else { - a = java.util.Optional.empty(); - } - var b$isPresent = org.zwobble.example.types.transient0.HobgoblinTransient0Builtins.decodeBool(inputStream, sharedValues); - java.util.Optional<org.zwobble.example.types.data.StructWithInt32> b; - if (b$isPresent) { - var b$element = org.zwobble.example.types.data.transient0.HobgoblinTransient0Data.decodeStructWithInt32(inputStream, sharedValues); - b = java.util.Optional.of(b$element); - } else { - b = java.util.Optional.empty(); - } - return new org.zwobble.example.types.data.StructWithOption(a, b); - } - - public static void encodeEnumWithVariants(org.zwobble.example.types.data.EnumWithVariants value, java.io.OutputStream outputStream, java.util.Map<org.zwobble.example.types.transient0.HobgoblinTransient0TaggedSharedValue, java.lang.Long> sharedValues) throws java.io.IOException { - org.zwobble.example.types.transient0.HobgoblinTransient0Builtins.encodeInt32(value.ordinal(), outputStream, sharedValues); - } - - private static final org.zwobble.example.types.data.EnumWithVariants[] EnumWithVariants$values = org.zwobble.example.types.data.EnumWithVariants.values(); - - public static org.zwobble.example.types.data.EnumWithVariants decodeEnumWithVariants(java.io.InputStream inputStream, java.util.List<java.lang.Object> sharedValues) throws java.io.IOException { - var ordinal = org.zwobble.example.types.transient0.HobgoblinTransient0Builtins.decodeInt32(inputStream, sharedValues); - return EnumWithVariants$values[ordinal]; - } - - public static void encodeStructWithEnum(org.zwobble.example.types.data.StructWithEnum value, java.io.OutputStream outputStream, java.util.Map<org.zwobble.example.types.transient0.HobgoblinTransient0TaggedSharedValue, java.lang.Long> sharedValues) throws java.io.IOException { - org.zwobble.example.types.data.transient0.HobgoblinTransient0Data.encodeEnumWithVariants(value.inner(), outputStream, sharedValues); - org.zwobble.example.types.transient0.HobgoblinTransient0Builtins.encodeInt32(value.c(), outputStream, sharedValues); - } - - public static org.zwobble.example.types.data.StructWithEnum decodeStructWithEnum(java.io.InputStream inputStream, java.util.List<java.lang.Object> sharedValues) throws java.io.IOException { - var inner = org.zwobble.example.types.data.transient0.HobgoblinTransient0Data.decodeEnumWithVariants(inputStream, sharedValues); - var c = org.zwobble.example.types.transient0.HobgoblinTransient0Builtins.decodeInt32(inputStream, sharedValues); - return new org.zwobble.example.types.data.StructWithEnum(inner, c); - } - - public static void encodeSumWithVariants(org.zwobble.example.types.data.SumWithVariants value, java.io.OutputStream outputStream, java.util.Map<org.zwobble.example.types.transient0.HobgoblinTransient0TaggedSharedValue, java.lang.Long> sharedValues) throws java.io.IOException { - switch (value) { - case org.zwobble.example.types.data.VariantOne value$0 -> { - org.zwobble.example.types.transient0.HobgoblinTransient0Builtins.encodeInt32(0, outputStream, sharedValues); - org.zwobble.example.types.data.transient0.HobgoblinTransient0Data.encodeVariantOne(value$0, outputStream, sharedValues); - } - case org.zwobble.example.types.data.VariantTwo value$1 -> { - org.zwobble.example.types.transient0.HobgoblinTransient0Builtins.encodeInt32(1, outputStream, sharedValues); - org.zwobble.example.types.data.transient0.HobgoblinTransient0Data.encodeVariantTwo(value$1, outputStream, sharedValues); - } - } - } - - public static org.zwobble.example.types.data.SumWithVariants decodeSumWithVariants(java.io.InputStream inputStream, java.util.List<java.lang.Object> sharedValues) throws java.io.IOException { - var variantTag = org.zwobble.example.types.transient0.HobgoblinTransient0Builtins.decodeInt32(inputStream, sharedValues); - switch (variantTag) { - case 0 -> { - var value$0 = org.zwobble.example.types.data.transient0.HobgoblinTransient0Data.decodeVariantOne(inputStream, sharedValues); - return value$0; - } - case 1 -> { - var value$1 = org.zwobble.example.types.data.transient0.HobgoblinTransient0Data.decodeVariantTwo(inputStream, sharedValues); - return value$1; - } - default -> { - throw new java.lang.RuntimeException("unexpected data.SumWithVariants variant tag: " + variantTag); - } - } - } - - public static void encodeVariantOne(org.zwobble.example.types.data.VariantOne value, java.io.OutputStream outputStream, java.util.Map<org.zwobble.example.types.transient0.HobgoblinTransient0TaggedSharedValue, java.lang.Long> sharedValues) throws java.io.IOException { - org.zwobble.example.types.transient0.HobgoblinTransient0Builtins.encodeInt32(value.a(), outputStream, sharedValues); - } - - public static org.zwobble.example.types.data.VariantOne decodeVariantOne(java.io.InputStream inputStream, java.util.List<java.lang.Object> sharedValues) throws java.io.IOException { - var a = org.zwobble.example.types.transient0.HobgoblinTransient0Builtins.decodeInt32(inputStream, sharedValues); - return new org.zwobble.example.types.data.VariantOne(a); - } - - public static void encodeVariantTwo(org.zwobble.example.types.data.VariantTwo value, java.io.OutputStream outputStream, java.util.Map<org.zwobble.example.types.transient0.HobgoblinTransient0TaggedSharedValue, java.lang.Long> sharedValues) throws java.io.IOException { - org.zwobble.example.types.transient0.HobgoblinTransient0Builtins.encodeInt64(value.a(), outputStream, sharedValues); - } - - public static org.zwobble.example.types.data.VariantTwo decodeVariantTwo(java.io.InputStream inputStream, java.util.List<java.lang.Object> sharedValues) throws java.io.IOException { - var a = org.zwobble.example.types.transient0.HobgoblinTransient0Builtins.decodeInt64(inputStream, sharedValues); - return new org.zwobble.example.types.data.VariantTwo(a); - } - - public static void encodeSumWithBoxedVariants(org.zwobble.example.types.data.SumWithBoxedVariants value, java.io.OutputStream outputStream, java.util.Map<org.zwobble.example.types.transient0.HobgoblinTransient0TaggedSharedValue, java.lang.Long> sharedValues) throws java.io.IOException { - switch (value) { - case org.zwobble.example.types.data.VariantOne value$0 -> { - org.zwobble.example.types.transient0.HobgoblinTransient0Builtins.encodeInt32(0, outputStream, sharedValues); - org.zwobble.example.types.data.transient0.HobgoblinTransient0Data.encodeVariantOne(value$0, outputStream, sharedValues); - } - case org.zwobble.example.types.data.VariantTwo value$1 -> { - org.zwobble.example.types.transient0.HobgoblinTransient0Builtins.encodeInt32(1, outputStream, sharedValues); - org.zwobble.example.types.data.transient0.HobgoblinTransient0Data.encodeVariantTwo(value$1, outputStream, sharedValues); - } - } - } - - public static org.zwobble.example.types.data.SumWithBoxedVariants decodeSumWithBoxedVariants(java.io.InputStream inputStream, java.util.List<java.lang.Object> sharedValues) throws java.io.IOException { - var variantTag = org.zwobble.example.types.transient0.HobgoblinTransient0Builtins.decodeInt32(inputStream, sharedValues); - switch (variantTag) { - case 0 -> { - var value$0 = org.zwobble.example.types.data.transient0.HobgoblinTransient0Data.decodeVariantOne(inputStream, sharedValues); - return value$0; - } - case 1 -> { - var value$1 = org.zwobble.example.types.data.transient0.HobgoblinTransient0Data.decodeVariantTwo(inputStream, sharedValues); - return value$1; - } - default -> { - throw new java.lang.RuntimeException("unexpected data.SumWithBoxedVariants variant tag: " + variantTag); - } - } - } - - public static void encodeStructWithSum(org.zwobble.example.types.data.StructWithSum value, java.io.OutputStream outputStream, java.util.Map<org.zwobble.example.types.transient0.HobgoblinTransient0TaggedSharedValue, java.lang.Long> sharedValues) throws java.io.IOException { - org.zwobble.example.types.data.transient0.HobgoblinTransient0Data.encodeSumWithVariants(value.inner(), outputStream, sharedValues); - org.zwobble.example.types.transient0.HobgoblinTransient0Builtins.encodeInt32(value.b(), outputStream, sharedValues); - } - - public static org.zwobble.example.types.data.StructWithSum decodeStructWithSum(java.io.InputStream inputStream, java.util.List<java.lang.Object> sharedValues) throws java.io.IOException { - var inner = org.zwobble.example.types.data.transient0.HobgoblinTransient0Data.decodeSumWithVariants(inputStream, sharedValues); - var b = org.zwobble.example.types.transient0.HobgoblinTransient0Builtins.decodeInt32(inputStream, sharedValues); - return new org.zwobble.example.types.data.StructWithSum(inner, b); - } - - public static void encodeStructWithNative(org.zwobble.example.types.data.StructWithNative value, java.io.OutputStream outputStream, java.util.Map<org.zwobble.example.types.transient0.HobgoblinTransient0TaggedSharedValue, java.lang.Long> sharedValues) throws java.io.IOException { - org.zwobble.example.types.data.transient0.HobgoblinTransient0Data.encodeNative(value.a(), outputStream, sharedValues); - } - - public static org.zwobble.example.types.data.StructWithNative decodeStructWithNative(java.io.InputStream inputStream, java.util.List<java.lang.Object> sharedValues) throws java.io.IOException { - var a = org.zwobble.example.types.data.transient0.HobgoblinTransient0Data.decodeNative(inputStream, sharedValues); - return new org.zwobble.example.types.data.StructWithNative(a); - } - - public static void encodeStructWithGenericNative(org.zwobble.example.types.data.StructWithGenericNative value, java.io.OutputStream outputStream, java.util.Map<org.zwobble.example.types.transient0.HobgoblinTransient0TaggedSharedValue, java.lang.Long> sharedValues) throws java.io.IOException { - org.zwobble.example.types.data.transient0.HobgoblinTransient0Data.encodeGenericNative(value.a(), outputStream, sharedValues, org.zwobble.example.types.transient0.HobgoblinTransient0Builtins::encodeInt32, org.zwobble.example.types.transient0.HobgoblinTransient0Builtins::encodeString); - org.zwobble.example.types.data.transient0.HobgoblinTransient0Data.encodeGenericNative(value.b(), outputStream, sharedValues, org.zwobble.example.types.data.transient0.HobgoblinTransient0Data::encode$constructedType$0, org.zwobble.example.types.data.transient0.HobgoblinTransient0Data::encode$constructedType$1); - } - - public static org.zwobble.example.types.data.StructWithGenericNative decodeStructWithGenericNative(java.io.InputStream inputStream, java.util.List<java.lang.Object> sharedValues) throws java.io.IOException { - var a = org.zwobble.example.types.data.transient0.HobgoblinTransient0Data.decodeGenericNative(inputStream, sharedValues, org.zwobble.example.types.transient0.HobgoblinTransient0Builtins::decodeInt32, org.zwobble.example.types.transient0.HobgoblinTransient0Builtins::decodeString); - var b = org.zwobble.example.types.data.transient0.HobgoblinTransient0Data.decodeGenericNative(inputStream, sharedValues, org.zwobble.example.types.data.transient0.HobgoblinTransient0Data::decode$constructedType$0, org.zwobble.example.types.data.transient0.HobgoblinTransient0Data::decode$constructedType$1); - return new org.zwobble.example.types.data.StructWithGenericNative(a, b); - } - - public static void encodeStructWithBox(org.zwobble.example.types.data.StructWithBox value, java.io.OutputStream outputStream, java.util.Map<org.zwobble.example.types.transient0.HobgoblinTransient0TaggedSharedValue, java.lang.Long> sharedValues) throws java.io.IOException { - org.zwobble.example.types.data.transient0.HobgoblinTransient0Data.encodeStructWithInt32(value.inner(), outputStream, sharedValues); - } - - public static org.zwobble.example.types.data.StructWithBox decodeStructWithBox(java.io.InputStream inputStream, java.util.List<java.lang.Object> sharedValues) throws java.io.IOException { - var inner = org.zwobble.example.types.data.transient0.HobgoblinTransient0Data.decodeStructWithInt32(inputStream, sharedValues); - return new org.zwobble.example.types.data.StructWithBox(inner); - } - - public static void encodeStructWithListOfShared(org.zwobble.example.types.data.StructWithListOfShared value, java.io.OutputStream outputStream, java.util.Map<org.zwobble.example.types.transient0.HobgoblinTransient0TaggedSharedValue, java.lang.Long> sharedValues) throws java.io.IOException { - org.zwobble.example.types.transient0.HobgoblinTransient0Builtins.encodeInt64((long) value.inner().size(), outputStream, sharedValues); - for (var element : value.inner()) { - { - var existingId = sharedValues.get(new org.zwobble.example.types.transient0.HobgoblinTransient0TaggedSharedValue(0, element)); - if (existingId != null) { - org.zwobble.example.types.transient0.HobgoblinTransient0Builtins.encodeInt64(existingId, outputStream, sharedValues); - } else { - org.zwobble.example.types.transient0.HobgoblinTransient0Builtins.encodeInt64(sharedValues.size(), outputStream, sharedValues); - sharedValues.put(new org.zwobble.example.types.transient0.HobgoblinTransient0TaggedSharedValue(0, element), (long) sharedValues.size()); - org.zwobble.example.types.data.transient0.HobgoblinTransient0Data.encodeStructWithInt32(element, outputStream, sharedValues); - } - } - } - } - - public static org.zwobble.example.types.data.StructWithListOfShared decodeStructWithListOfShared(java.io.InputStream inputStream, java.util.List<java.lang.Object> sharedValues) throws java.io.IOException { - var inner$size = org.zwobble.example.types.transient0.HobgoblinTransient0Builtins.decodeInt64(inputStream, sharedValues); - if (inner$size > java.lang.Integer.MAX_VALUE) { - throw new java.io.IOException("Lists longer than Integer.MAX_VALUE are not supported"); - } - var inner = new java.util.ArrayList<org.zwobble.example.types.data.StructWithInt32>((int) inner$size); - for (long inner$index = 0; inner$index < inner$size; inner$index++) { - var inner$element$id = org.zwobble.example.types.transient0.HobgoblinTransient0Builtins.decodeInt64(inputStream, sharedValues); - if (inner$element$id > java.lang.Integer.MAX_VALUE) { - throw new java.io.IOException("Shared value IDs greater than Integer.MAX_VALUE are not supported"); - } - org.zwobble.example.types.data.StructWithInt32 inner$element; - if (inner$element$id < sharedValues.size()) { - inner$element = switch (sharedValues.get((int) inner$element$id)) { - case org.zwobble.example.types.data.StructWithInt32 inner$element$decodedValue -> { - yield inner$element$decodedValue; - } - default -> { - throw new java.io.IOException("Shared value was of the wrong type"); - } - }; - } else { - var inner$element$decodedValue = org.zwobble.example.types.data.transient0.HobgoblinTransient0Data.decodeStructWithInt32(inputStream, sharedValues); - sharedValues.add(inner$element$decodedValue); - inner$element = inner$element$decodedValue; - } - inner.add(inner$element); - } - return new org.zwobble.example.types.data.StructWithListOfShared(inner); - } - - public static void encodeStructWithDifferentSharedTypes(org.zwobble.example.types.data.StructWithDifferentSharedTypes value, java.io.OutputStream outputStream, java.util.Map<org.zwobble.example.types.transient0.HobgoblinTransient0TaggedSharedValue, java.lang.Long> sharedValues) throws java.io.IOException { - { - var existingId = sharedValues.get(new org.zwobble.example.types.transient0.HobgoblinTransient0TaggedSharedValue(0, value.a())); - if (existingId != null) { - org.zwobble.example.types.transient0.HobgoblinTransient0Builtins.encodeInt64(existingId, outputStream, sharedValues); - } else { - org.zwobble.example.types.transient0.HobgoblinTransient0Builtins.encodeInt64(sharedValues.size(), outputStream, sharedValues); - sharedValues.put(new org.zwobble.example.types.transient0.HobgoblinTransient0TaggedSharedValue(0, value.a()), (long) sharedValues.size()); - org.zwobble.example.types.data.transient0.HobgoblinTransient0Data.encodeStructWithInt32(value.a(), outputStream, sharedValues); - } - } - { - var existingId = sharedValues.get(new org.zwobble.example.types.transient0.HobgoblinTransient0TaggedSharedValue(1, value.b())); - if (existingId != null) { - org.zwobble.example.types.transient0.HobgoblinTransient0Builtins.encodeInt64(existingId, outputStream, sharedValues); - } else { - org.zwobble.example.types.transient0.HobgoblinTransient0Builtins.encodeInt64(sharedValues.size(), outputStream, sharedValues); - sharedValues.put(new org.zwobble.example.types.transient0.HobgoblinTransient0TaggedSharedValue(1, value.b()), (long) sharedValues.size()); - org.zwobble.example.types.data.transient0.HobgoblinTransient0Data.encodeStructWithInt64(value.b(), outputStream, sharedValues); - } - } - { - var existingId = sharedValues.get(new org.zwobble.example.types.transient0.HobgoblinTransient0TaggedSharedValue(0, value.c())); - if (existingId != null) { - org.zwobble.example.types.transient0.HobgoblinTransient0Builtins.encodeInt64(existingId, outputStream, sharedValues); - } else { - org.zwobble.example.types.transient0.HobgoblinTransient0Builtins.encodeInt64(sharedValues.size(), outputStream, sharedValues); - sharedValues.put(new org.zwobble.example.types.transient0.HobgoblinTransient0TaggedSharedValue(0, value.c()), (long) sharedValues.size()); - org.zwobble.example.types.data.transient0.HobgoblinTransient0Data.encodeStructWithInt32(value.c(), outputStream, sharedValues); - } - } - } - - public static org.zwobble.example.types.data.StructWithDifferentSharedTypes decodeStructWithDifferentSharedTypes(java.io.InputStream inputStream, java.util.List<java.lang.Object> sharedValues) throws java.io.IOException { - var a$id = org.zwobble.example.types.transient0.HobgoblinTransient0Builtins.decodeInt64(inputStream, sharedValues); - if (a$id > java.lang.Integer.MAX_VALUE) { - throw new java.io.IOException("Shared value IDs greater than Integer.MAX_VALUE are not supported"); - } - org.zwobble.example.types.data.StructWithInt32 a; - if (a$id < sharedValues.size()) { - a = switch (sharedValues.get((int) a$id)) { - case org.zwobble.example.types.data.StructWithInt32 a$decodedValue -> { - yield a$decodedValue; - } - default -> { - throw new java.io.IOException("Shared value was of the wrong type"); - } - }; - } else { - var a$decodedValue = org.zwobble.example.types.data.transient0.HobgoblinTransient0Data.decodeStructWithInt32(inputStream, sharedValues); - sharedValues.add(a$decodedValue); - a = a$decodedValue; - } - var b$id = org.zwobble.example.types.transient0.HobgoblinTransient0Builtins.decodeInt64(inputStream, sharedValues); - if (b$id > java.lang.Integer.MAX_VALUE) { - throw new java.io.IOException("Shared value IDs greater than Integer.MAX_VALUE are not supported"); - } - org.zwobble.example.types.data.StructWithInt64 b; - if (b$id < sharedValues.size()) { - b = switch (sharedValues.get((int) b$id)) { - case org.zwobble.example.types.data.StructWithInt64 b$decodedValue -> { - yield b$decodedValue; - } - default -> { - throw new java.io.IOException("Shared value was of the wrong type"); - } - }; - } else { - var b$decodedValue = org.zwobble.example.types.data.transient0.HobgoblinTransient0Data.decodeStructWithInt64(inputStream, sharedValues); - sharedValues.add(b$decodedValue); - b = b$decodedValue; - } - var c$id = org.zwobble.example.types.transient0.HobgoblinTransient0Builtins.decodeInt64(inputStream, sharedValues); - if (c$id > java.lang.Integer.MAX_VALUE) { - throw new java.io.IOException("Shared value IDs greater than Integer.MAX_VALUE are not supported"); - } - org.zwobble.example.types.data.StructWithInt32 c; - if (c$id < sharedValues.size()) { - c = switch (sharedValues.get((int) c$id)) { - case org.zwobble.example.types.data.StructWithInt32 c$decodedValue -> { - yield c$decodedValue; - } - default -> { - throw new java.io.IOException("Shared value was of the wrong type"); - } - }; - } else { - var c$decodedValue = org.zwobble.example.types.data.transient0.HobgoblinTransient0Data.decodeStructWithInt32(inputStream, sharedValues); - sharedValues.add(c$decodedValue); - c = c$decodedValue; - } - return new org.zwobble.example.types.data.StructWithDifferentSharedTypes(a, b, c); - } - - public static void encodeStructWithSharedSumAndVariant(org.zwobble.example.types.data.StructWithSharedSumAndVariant value, java.io.OutputStream outputStream, java.util.Map<org.zwobble.example.types.transient0.HobgoblinTransient0TaggedSharedValue, java.lang.Long> sharedValues) throws java.io.IOException { - { - var existingId = sharedValues.get(new org.zwobble.example.types.transient0.HobgoblinTransient0TaggedSharedValue(2, value.a())); - if (existingId != null) { - org.zwobble.example.types.transient0.HobgoblinTransient0Builtins.encodeInt64(existingId, outputStream, sharedValues); - } else { - org.zwobble.example.types.transient0.HobgoblinTransient0Builtins.encodeInt64(sharedValues.size(), outputStream, sharedValues); - sharedValues.put(new org.zwobble.example.types.transient0.HobgoblinTransient0TaggedSharedValue(2, value.a()), (long) sharedValues.size()); - org.zwobble.example.types.data.transient0.HobgoblinTransient0Data.encodeSumWithVariants(value.a(), outputStream, sharedValues); - } - } - { - var existingId = sharedValues.get(new org.zwobble.example.types.transient0.HobgoblinTransient0TaggedSharedValue(3, value.b())); - if (existingId != null) { - org.zwobble.example.types.transient0.HobgoblinTransient0Builtins.encodeInt64(existingId, outputStream, sharedValues); - } else { - org.zwobble.example.types.transient0.HobgoblinTransient0Builtins.encodeInt64(sharedValues.size(), outputStream, sharedValues); - sharedValues.put(new org.zwobble.example.types.transient0.HobgoblinTransient0TaggedSharedValue(3, value.b()), (long) sharedValues.size()); - org.zwobble.example.types.data.transient0.HobgoblinTransient0Data.encodeVariantOne(value.b(), outputStream, sharedValues); - } - } - } - - public static org.zwobble.example.types.data.StructWithSharedSumAndVariant decodeStructWithSharedSumAndVariant(java.io.InputStream inputStream, java.util.List<java.lang.Object> sharedValues) throws java.io.IOException { - var a$id = org.zwobble.example.types.transient0.HobgoblinTransient0Builtins.decodeInt64(inputStream, sharedValues); - if (a$id > java.lang.Integer.MAX_VALUE) { - throw new java.io.IOException("Shared value IDs greater than Integer.MAX_VALUE are not supported"); - } - org.zwobble.example.types.data.SumWithVariants a; - if (a$id < sharedValues.size()) { - a = switch (sharedValues.get((int) a$id)) { - case org.zwobble.example.types.data.SumWithVariants a$decodedValue -> { - yield a$decodedValue; - } - default -> { - throw new java.io.IOException("Shared value was of the wrong type"); - } - }; - } else { - var a$decodedValue = org.zwobble.example.types.data.transient0.HobgoblinTransient0Data.decodeSumWithVariants(inputStream, sharedValues); - sharedValues.add(a$decodedValue); - a = a$decodedValue; - } - var b$id = org.zwobble.example.types.transient0.HobgoblinTransient0Builtins.decodeInt64(inputStream, sharedValues); - if (b$id > java.lang.Integer.MAX_VALUE) { - throw new java.io.IOException("Shared value IDs greater than Integer.MAX_VALUE are not supported"); - } - org.zwobble.example.types.data.VariantOne b; - if (b$id < sharedValues.size()) { - b = switch (sharedValues.get((int) b$id)) { - case org.zwobble.example.types.data.VariantOne b$decodedValue -> { - yield b$decodedValue; - } - default -> { - throw new java.io.IOException("Shared value was of the wrong type"); - } - }; - } else { - var b$decodedValue = org.zwobble.example.types.data.transient0.HobgoblinTransient0Data.decodeVariantOne(inputStream, sharedValues); - sharedValues.add(b$decodedValue); - b = b$decodedValue; - } - return new org.zwobble.example.types.data.StructWithSharedSumAndVariant(a, b); - } - - private static void encode$constructedType$0(java.util.Optional<String> value, java.io.OutputStream outputStream, java.util.Map<org.zwobble.example.types.transient0.HobgoblinTransient0TaggedSharedValue, java.lang.Long> sharedValues) throws java.io.IOException { - org.zwobble.example.types.transient0.HobgoblinTransient0Builtins.encodeBool(value.isPresent(), outputStream, sharedValues); - if (value.isPresent()) { - org.zwobble.example.types.transient0.HobgoblinTransient0Builtins.encodeString(value.get(), outputStream, sharedValues); - } - } - - private static java.util.Optional<String> decode$constructedType$0(java.io.InputStream inputStream, java.util.List<java.lang.Object> sharedValues) throws java.io.IOException { - var value$isPresent = org.zwobble.example.types.transient0.HobgoblinTransient0Builtins.decodeBool(inputStream, sharedValues); - java.util.Optional<String> value; - if (value$isPresent) { - var value$element = org.zwobble.example.types.transient0.HobgoblinTransient0Builtins.decodeString(inputStream, sharedValues); - value = java.util.Optional.of(value$element); - } else { - value = java.util.Optional.empty(); - } - return value; - } - - private static void encode$constructedType$1(org.zwobble.example.types.data.GenericNative<java.util.Optional<String>, org.zwobble.example.types.data.GenericNative<String, String>> value, java.io.OutputStream outputStream, java.util.Map<org.zwobble.example.types.transient0.HobgoblinTransient0TaggedSharedValue, java.lang.Long> sharedValues) throws java.io.IOException { - org.zwobble.example.types.data.transient0.HobgoblinTransient0Data.encodeGenericNative(value, outputStream, sharedValues, org.zwobble.example.types.data.transient0.HobgoblinTransient0Data::encode$constructedType$0, org.zwobble.example.types.data.transient0.HobgoblinTransient0Data::encode$constructedType$2); - } - - private static org.zwobble.example.types.data.GenericNative<java.util.Optional<String>, org.zwobble.example.types.data.GenericNative<String, String>> decode$constructedType$1(java.io.InputStream inputStream, java.util.List<java.lang.Object> sharedValues) throws java.io.IOException { - var value = org.zwobble.example.types.data.transient0.HobgoblinTransient0Data.decodeGenericNative(inputStream, sharedValues, org.zwobble.example.types.data.transient0.HobgoblinTransient0Data::decode$constructedType$0, org.zwobble.example.types.data.transient0.HobgoblinTransient0Data::decode$constructedType$2); - return value; - } - - private static void encode$constructedType$2(org.zwobble.example.types.data.GenericNative<String, String> value, java.io.OutputStream outputStream, java.util.Map<org.zwobble.example.types.transient0.HobgoblinTransient0TaggedSharedValue, java.lang.Long> sharedValues) throws java.io.IOException { - org.zwobble.example.types.data.transient0.HobgoblinTransient0Data.encodeGenericNative(value, outputStream, sharedValues, org.zwobble.example.types.transient0.HobgoblinTransient0Builtins::encodeString, org.zwobble.example.types.transient0.HobgoblinTransient0Builtins::encodeString); - } - - private static org.zwobble.example.types.data.GenericNative<String, String> decode$constructedType$2(java.io.InputStream inputStream, java.util.List<java.lang.Object> sharedValues) throws java.io.IOException { - var value = org.zwobble.example.types.data.transient0.HobgoblinTransient0Data.decodeGenericNative(inputStream, sharedValues, org.zwobble.example.types.transient0.HobgoblinTransient0Builtins::decodeString, org.zwobble.example.types.transient0.HobgoblinTransient0Builtins::decodeString); - return value; - } - - // Custom area start: org.zwobble.example.types.data.transient0.HobgoblinTransient0Data body - public static void encodeNative( - Native value, - OutputStream outputStream, - Map<HobgoblinTransient0TaggedSharedValue, Long> sharedValues - ) throws IOException { - HobgoblinTransient0Builtins.encodeInt32(value.a(), outputStream, sharedValues); - HobgoblinTransient0Builtins.encodeInt32(value.b(), outputStream, sharedValues); - } - - public static Native decodeNative( - InputStream inputStream, - List<Object> sharedValues - ) throws IOException { - var a = HobgoblinTransient0Builtins.decodeInt32(inputStream, sharedValues); - var b = HobgoblinTransient0Builtins.decodeInt32(inputStream, sharedValues); - return new Native(a, b); - } - - public static <A, B> void encodeGenericNative( - GenericNative<A, B> value, - OutputStream outputStream, - Map<HobgoblinTransient0TaggedSharedValue, Long> sharedValues, - Encoder<A> encoderA, - Encoder<B> encoderB - ) throws IOException { - encoderA.encode(value.a(), outputStream, sharedValues); - encoderB.encode(value.b(), outputStream, sharedValues); - } - - public static <A, B> GenericNative<A, B> decodeGenericNative( - InputStream inputStream, - List<Object> sharedValues, - Decoder<A> decoderA, - Decoder<B> decoderB - ) throws IOException { - var a = decoderA.decode(inputStream, sharedValues); - var b = decoderB.decode(inputStream, sharedValues); - return new GenericNative(a, b); - } - // Custom area end: org.zwobble.example.types.data.transient0.HobgoblinTransient0Data body -} diff --git a/examples/15-transient-0/output/java/src/main/java/org/zwobble/example/types/transient0/Decoder.java b/examples/15-transient-0/output/java/src/main/java/org/zwobble/example/types/transient0/Decoder.java deleted file mode 100644 index ad1a6d0..0000000 --- a/examples/15-transient-0/output/java/src/main/java/org/zwobble/example/types/transient0/Decoder.java +++ /dev/null @@ -1,13 +0,0 @@ -// Generated by hobgoblin. - -package org.zwobble.example.types.transient0; - -// Custom area start: org.zwobble.example.types.transient0.Decoder imports -// Custom area end: org.zwobble.example.types.transient0.Decoder imports - -public interface Decoder<T> { - public T decode(java.io.InputStream inputStream, java.util.List<java.lang.Object> sharedValues) throws java.io.IOException; - - // Custom area start: org.zwobble.example.types.transient0.Decoder body - // Custom area end: org.zwobble.example.types.transient0.Decoder body -} diff --git a/examples/15-transient-0/output/java/src/main/java/org/zwobble/example/types/transient0/Encoder.java b/examples/15-transient-0/output/java/src/main/java/org/zwobble/example/types/transient0/Encoder.java deleted file mode 100644 index 2ba43a6..0000000 --- a/examples/15-transient-0/output/java/src/main/java/org/zwobble/example/types/transient0/Encoder.java +++ /dev/null @@ -1,13 +0,0 @@ -// Generated by hobgoblin. - -package org.zwobble.example.types.transient0; - -// Custom area start: org.zwobble.example.types.transient0.Encoder imports -// Custom area end: org.zwobble.example.types.transient0.Encoder imports - -public interface Encoder<T> { - public void encode(T value, java.io.OutputStream outputStream, java.util.Map<org.zwobble.example.types.transient0.HobgoblinTransient0TaggedSharedValue, java.lang.Long> sharedValues) throws java.io.IOException; - - // Custom area start: org.zwobble.example.types.transient0.Encoder body - // Custom area end: org.zwobble.example.types.transient0.Encoder body -} diff --git a/examples/15-transient-0/output/java/src/main/java/org/zwobble/example/types/transient0/HobgoblinTransient0Builtins.java b/examples/15-transient-0/output/java/src/main/java/org/zwobble/example/types/transient0/HobgoblinTransient0Builtins.java deleted file mode 100644 index 293aee7..0000000 --- a/examples/15-transient-0/output/java/src/main/java/org/zwobble/example/types/transient0/HobgoblinTransient0Builtins.java +++ /dev/null @@ -1,82 +0,0 @@ -// Generated by hobgoblin. - -package org.zwobble.example.types.transient0; - -// Custom area start: org.zwobble.example.types.transient0.HobgoblinTransient0Builtins imports -// Custom area end: org.zwobble.example.types.transient0.HobgoblinTransient0Builtins imports - -public final class HobgoblinTransient0Builtins { - public static void encodeBool(boolean value, java.io.OutputStream outputStream, java.util.Map<org.zwobble.example.types.transient0.HobgoblinTransient0TaggedSharedValue, java.lang.Long> sharedValues) throws java.io.IOException { - outputStream.write(value ? 1 : 0); - } - - public static boolean decodeBool(java.io.InputStream inputStream, java.util.List<java.lang.Object> sharedValues) throws java.io.IOException { - return inputStream.read() != 0; - } - - public static void encodeInt8(byte value, java.io.OutputStream outputStream, java.util.Map<org.zwobble.example.types.transient0.HobgoblinTransient0TaggedSharedValue, java.lang.Long> sharedValues) throws java.io.IOException { - outputStream.write(value); - } - - public static byte decodeInt8(java.io.InputStream inputStream, java.util.List<java.lang.Object> sharedValues) throws java.io.IOException { - return (byte) inputStream.read(); - } - - public static void encodeInt32(int value, java.io.OutputStream outputStream, java.util.Map<org.zwobble.example.types.transient0.HobgoblinTransient0TaggedSharedValue, java.lang.Long> sharedValues) throws java.io.IOException { - outputStream.write(value >>> 0 & 255); - outputStream.write(value >>> 8 & 255); - outputStream.write(value >>> 16 & 255); - outputStream.write(value >>> 24 & 255); - } - - public static int decodeInt32(java.io.InputStream inputStream, java.util.List<java.lang.Object> sharedValues) throws java.io.IOException { - int value = 0; - value = value | inputStream.read() << 0; - value = value | inputStream.read() << 8; - value = value | inputStream.read() << 16; - value = value | inputStream.read() << 24; - return value; - } - - public static void encodeInt64(long value, java.io.OutputStream outputStream, java.util.Map<org.zwobble.example.types.transient0.HobgoblinTransient0TaggedSharedValue, java.lang.Long> sharedValues) throws java.io.IOException { - outputStream.write((int) (value >>> 0 & 255)); - outputStream.write((int) (value >>> 8 & 255)); - outputStream.write((int) (value >>> 16 & 255)); - outputStream.write((int) (value >>> 24 & 255)); - outputStream.write((int) (value >>> 32 & 255)); - outputStream.write((int) (value >>> 40 & 255)); - outputStream.write((int) (value >>> 48 & 255)); - outputStream.write((int) (value >>> 56 & 255)); - } - - public static long decodeInt64(java.io.InputStream inputStream, java.util.List<java.lang.Object> sharedValues) throws java.io.IOException { - long value = 0; - value = value | inputStream.read() << 0; - value = value | inputStream.read() << 8; - value = value | inputStream.read() << 16; - value = value | inputStream.read() << 24; - value = value | inputStream.read() << 32; - value = value | inputStream.read() << 40; - value = value | inputStream.read() << 48; - value = value | inputStream.read() << 56; - return value; - } - - public static void encodeString(String value, java.io.OutputStream outputStream, java.util.Map<org.zwobble.example.types.transient0.HobgoblinTransient0TaggedSharedValue, java.lang.Long> sharedValues) throws java.io.IOException { - var bytes = value.getBytes(java.nio.charset.StandardCharsets.UTF_8); - org.zwobble.example.types.transient0.HobgoblinTransient0Builtins.encodeInt64((long) bytes.length, outputStream, sharedValues); - outputStream.write(bytes); - } - - public static String decodeString(java.io.InputStream inputStream, java.util.List<java.lang.Object> sharedValues) throws java.io.IOException { - var bytesLength = org.zwobble.example.types.transient0.HobgoblinTransient0Builtins.decodeInt64(inputStream, sharedValues); - if (bytesLength > java.lang.Integer.MAX_VALUE) { - throw new java.io.IOException("Strings longer than Integer.MAX_VALUE are not supported"); - } - var bytes = inputStream.readNBytes((int) bytesLength); - return new String(bytes, java.nio.charset.StandardCharsets.UTF_8); - } - - // Custom area start: org.zwobble.example.types.transient0.HobgoblinTransient0Builtins body - // Custom area end: org.zwobble.example.types.transient0.HobgoblinTransient0Builtins body -} diff --git a/examples/15-transient-0/output/java/src/main/java/org/zwobble/example/types/transient0/HobgoblinTransient0TaggedSharedValue.java b/examples/15-transient-0/output/java/src/main/java/org/zwobble/example/types/transient0/HobgoblinTransient0TaggedSharedValue.java deleted file mode 100644 index 6c5b520..0000000 --- a/examples/15-transient-0/output/java/src/main/java/org/zwobble/example/types/transient0/HobgoblinTransient0TaggedSharedValue.java +++ /dev/null @@ -1,22 +0,0 @@ -// Generated by hobgoblin. - -package org.zwobble.example.types.transient0; - -// Custom area start: org.zwobble.example.types.transient0.HobgoblinTransient0TaggedSharedValue imports -// Custom area end: org.zwobble.example.types.transient0.HobgoblinTransient0TaggedSharedValue imports - -public record HobgoblinTransient0TaggedSharedValue( - long typeId, - java.lang.Object value -) { - public boolean equals(java.lang.Object other) { - return other instanceof org.zwobble.example.types.transient0.HobgoblinTransient0TaggedSharedValue otherSharedValue && this.typeId == otherSharedValue.typeId && this.value == otherSharedValue.value; - } - - public int hashCode() { - return 37 * (37 * 17 + java.lang.Long.hashCode(this.typeId)) + java.lang.System.identityHashCode(this.value); - } - - // Custom area start: org.zwobble.example.types.transient0.HobgoblinTransient0TaggedSharedValue body - // Custom area end: org.zwobble.example.types.transient0.HobgoblinTransient0TaggedSharedValue body -} diff --git a/examples/15-transient-0/output/java/src/test/java/org/zwobble/example/Transient0Tests.java b/examples/15-transient-0/output/java/src/test/java/org/zwobble/example/Transient0Tests.java deleted file mode 100644 index ba43aed..0000000 --- a/examples/15-transient-0/output/java/src/test/java/org/zwobble/example/Transient0Tests.java +++ /dev/null @@ -1,392 +0,0 @@ -package org.zwobble.example; - -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; -import java.nio.file.Files; -import java.nio.file.Path; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Optional; -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.GenericNative; -import org.zwobble.example.types.data.Native; -import org.zwobble.example.types.data.StructSingleton; -import org.zwobble.example.types.data.StructWithBool; -import org.zwobble.example.types.data.StructWithBox; -import org.zwobble.example.types.data.StructWithDifferentSharedTypes; -import org.zwobble.example.types.data.StructWithEnum; -import org.zwobble.example.types.data.StructWithGenericNative; -import org.zwobble.example.types.data.StructWithInt8; -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.StructWithListOfShared; -import org.zwobble.example.types.data.StructWithNative; -import org.zwobble.example.types.data.StructWithOption; -import org.zwobble.example.types.data.StructWithSharedSumAndVariant; -import org.zwobble.example.types.data.StructWithString; -import org.zwobble.example.types.data.StructWithStruct; -import org.zwobble.example.types.data.StructWithSum; -import org.zwobble.example.types.data.VariantOne; -import org.zwobble.example.types.data.VariantTwo; -import org.zwobble.example.types.data.transient0.HobgoblinTransient0Data; -import org.zwobble.example.types.transient0.HobgoblinTransient0TaggedSharedValue; - -public class Transient0Tests { - @Test - public void structSingleton() throws IOException { - var value = StructSingleton.INSTANCE; - - assertRoundTripEncoding( - "StructSingleton", - value, - HobgoblinTransient0Data::encodeStructSingleton, - HobgoblinTransient0Data::decodeStructSingleton - ); - } - - @Test - public void structWithBool() throws IOException { - var value = new StructWithBool(true, false); - - assertRoundTripEncoding( - "StructWithBool", - value, - HobgoblinTransient0Data::encodeStructWithBool, - HobgoblinTransient0Data::decodeStructWithBool - ); - } - - @Test - public void structWithInt8() throws IOException { - var value = new StructWithInt8((byte)10, (byte)25); - - assertRoundTripEncoding( - "StructWithInt8", - value, - HobgoblinTransient0Data::encodeStructWithInt8, - HobgoblinTransient0Data::decodeStructWithInt8 - ); - } - - @Test - public void structWithInt32() throws IOException { - var value = new StructWithInt32(10, 25); - - assertRoundTripEncoding( - "StructWithInt32", - value, - HobgoblinTransient0Data::encodeStructWithInt32, - HobgoblinTransient0Data::decodeStructWithInt32 - ); - } - - @Test - public void structWithInt64() throws IOException { - var value = new StructWithInt64(10, 25); - - assertRoundTripEncoding( - "StructWithInt64", - value, - HobgoblinTransient0Data::encodeStructWithInt64, - HobgoblinTransient0Data::decodeStructWithInt64 - ); - } - - @Test - public void structWithString() throws IOException { - var value = new StructWithString("abc", "def"); - - assertRoundTripEncoding( - "StructWithString", - value, - HobgoblinTransient0Data::encodeStructWithString, - HobgoblinTransient0Data::decodeStructWithString - ); - } - - @Test - public void structWithStruct() throws IOException { - var value = new StructWithStruct(new StructWithInt32(10, 25), 42); - - assertRoundTripEncoding( - "StructWithStruct", - value, - HobgoblinTransient0Data::encodeStructWithStruct, - HobgoblinTransient0Data::decodeStructWithStruct - ); - } - - @Test - public void structWithList() throws IOException { - var value = new StructWithList( - List.of(10L, 25L), - List.of( - new StructWithInt32(42, 47), - new StructWithInt32(52, 57), - new StructWithInt32(62, 67) - ) - ); - - assertRoundTripEncoding( - "StructWithList", - value, - HobgoblinTransient0Data::encodeStructWithList, - HobgoblinTransient0Data::decodeStructWithList - ); - } - - @Test - public void structWithOptionNone() throws IOException { - var value = new StructWithOption( - Optional.empty(), - Optional.empty() - ); - - assertRoundTripEncoding( - "StructWithOption_None", - value, - HobgoblinTransient0Data::encodeStructWithOption, - HobgoblinTransient0Data::decodeStructWithOption - ); - } - - @Test - public void structWithOptionSome() throws IOException { - var value = new StructWithOption( - Optional.of(10L), - Optional.of(new StructWithInt32(42, 47)) - ); - - assertRoundTripEncoding( - "StructWithOption_Some", - value, - HobgoblinTransient0Data::encodeStructWithOption, - HobgoblinTransient0Data::decodeStructWithOption - ); - } - - @Test - public void enumWithVariants() throws IOException { - assertRoundTripEncoding( - "EnumWithVariants_zero", - EnumWithVariants.ZERO, - HobgoblinTransient0Data::encodeEnumWithVariants, - HobgoblinTransient0Data::decodeEnumWithVariants - ); - - assertRoundTripEncoding( - "EnumWithVariants_one", - EnumWithVariants.ONE, - HobgoblinTransient0Data::encodeEnumWithVariants, - HobgoblinTransient0Data::decodeEnumWithVariants - ); - - assertRoundTripEncoding( - "EnumWithVariants_two", - EnumWithVariants.TWO, - HobgoblinTransient0Data::encodeEnumWithVariants, - HobgoblinTransient0Data::decodeEnumWithVariants - ); - } - - @Test - public void structWithEnum() throws IOException { - var value = new StructWithEnum( - EnumWithVariants.ONE, - 42 - ); - - assertRoundTripEncoding( - "StructWithEnum", - value, - HobgoblinTransient0Data::encodeStructWithEnum, - HobgoblinTransient0Data::decodeStructWithEnum - ); - } - - @Test - public void sumWithVariants() throws IOException { - assertRoundTripEncoding( - "SumWithVariants_VariantOne", - new VariantOne(10), - HobgoblinTransient0Data::encodeSumWithVariants, - HobgoblinTransient0Data::decodeSumWithVariants - ); - - assertRoundTripEncoding( - "SumWithVariants_VariantTwo", - new VariantTwo(25), - HobgoblinTransient0Data::encodeSumWithVariants, - HobgoblinTransient0Data::decodeSumWithVariants - ); - } - - @Test - public void sumWithBoxedVariants() throws IOException { - assertRoundTripEncoding( - "SumWithBoxedVariants_VariantOne", - new VariantOne(10), - HobgoblinTransient0Data::encodeSumWithBoxedVariants, - HobgoblinTransient0Data::decodeSumWithBoxedVariants - ); - - assertRoundTripEncoding( - "SumWithBoxedVariants_VariantTwo", - new VariantTwo(25), - HobgoblinTransient0Data::encodeSumWithBoxedVariants, - HobgoblinTransient0Data::decodeSumWithBoxedVariants - ); - } - - @Test - public void structWithSum() throws IOException { - var value = new StructWithSum( - new VariantTwo(25), - 42 - ); - - assertRoundTripEncoding( - "StructWithSum", - value, - HobgoblinTransient0Data::encodeStructWithSum, - HobgoblinTransient0Data::decodeStructWithSum - ); - } - - @Test - public void structWithNative() throws IOException { - var value = new StructWithNative( - new Native(10, 25) - ); - - assertRoundTripEncoding( - "StructWithNative", - value, - HobgoblinTransient0Data::encodeStructWithNative, - HobgoblinTransient0Data::decodeStructWithNative - ); - } - - @Test - public void structWithGenericNative() throws IOException { - var value = new StructWithGenericNative( - new GenericNative(10, "x1"), - new GenericNative( - Optional.of("x2"), - new GenericNative( - Optional.of("x3"), - new GenericNative("x4", "x5") - ) - ) - ); - - assertRoundTripEncoding( - "StructWithGenericNative", - value, - HobgoblinTransient0Data::encodeStructWithGenericNative, - HobgoblinTransient0Data::decodeStructWithGenericNative - ); - } - - @Test - public void structWithBox() throws IOException { - var value = new StructWithBox( - new StructWithInt32(10, 25) - ); - - assertRoundTripEncoding( - "StructWithBox", - value, - HobgoblinTransient0Data::encodeStructWithBox, - HobgoblinTransient0Data::decodeStructWithBox - ); - } - - @Test - public void structWithListOfShared() throws IOException { - var a = new StructWithInt32(10, 25); - var b = new StructWithInt32(42, 47); - - var value = new StructWithListOfShared(List.of(a, a, b, a, b)); - - var decodedValue = assertRoundTripEncoding( - "StructWithListOfShared", - value, - HobgoblinTransient0Data::encodeStructWithListOfShared, - HobgoblinTransient0Data::decodeStructWithListOfShared - ); - Assertions.assertSame(decodedValue.inner().get(0), decodedValue.inner().get(1)); - Assertions.assertSame(decodedValue.inner().get(0), decodedValue.inner().get(3)); - Assertions.assertSame(decodedValue.inner().get(2), decodedValue.inner().get(4)); - } - - @Test - public void structWithDifferentSharedTypes() throws IOException { - var a = new StructWithInt32(10, 25); - var b = new StructWithInt64(42, 47); - var c = new StructWithInt32(52, 57); - - var value = new StructWithDifferentSharedTypes(a, b, c); - - assertRoundTripEncoding( - "StructWithDifferentSharedTypes", - value, - HobgoblinTransient0Data::encodeStructWithDifferentSharedTypes, - HobgoblinTransient0Data::decodeStructWithDifferentSharedTypes - ); - } - - @Test - public void structWithSharedSumAndVariant() throws IOException { - var a = new VariantOne(10); - - var value = new StructWithSharedSumAndVariant(a, a); - - assertRoundTripEncoding( - "StructWithSharedSumAndVariant", - value, - HobgoblinTransient0Data::encodeStructWithSharedSumAndVariant, - HobgoblinTransient0Data::decodeStructWithSharedSumAndVariant - ); - } - - private <T> T assertRoundTripEncoding( - String name, - T value, - Encoder<T> encoder, - Decoder<T> decoder - ) throws IOException { - var outputStream = new ByteArrayOutputStream(); - encoder.encode(value, outputStream, new HashMap<>()); - var bytes = outputStream.toByteArray(); - - var outputDir = System.getenv("HOBGOBLIN_OUTPUT_DIR"); - var transient0OutputDir = Path.of(outputDir).resolve("transient-0"); - Files.createDirectories(transient0OutputDir); - var transient0OutputPath = transient0OutputDir.resolve(name); - Files.write(transient0OutputPath, bytes); - - var inputStream = new ByteArrayInputStream(bytes); - var decodedValue = decoder.decode(inputStream, new ArrayList<>()); - - Assertions.assertEquals(value, decodedValue); - - return decodedValue; - } - - private interface Encoder<T> { - void encode(T value, OutputStream outputStream, Map<HobgoblinTransient0TaggedSharedValue, Long> sharedValues) throws IOException; - } - - private interface Decoder<T> { - T decode(InputStream inputStream, List<Object> sharedValues) throws IOException; - } -} diff --git a/examples/15-transient-0/output/rust/.gitignore b/examples/15-transient-0/output/rust/.gitignore deleted file mode 100644 index fc03479..0000000 --- a/examples/15-transient-0/output/rust/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -/target -/transient-0/ diff --git a/examples/15-transient-0/output/rust/Cargo.lock b/examples/15-transient-0/output/rust/Cargo.lock deleted file mode 100644 index 9dc6e3e..0000000 --- a/examples/15-transient-0/output/rust/Cargo.lock +++ /dev/null @@ -1,7 +0,0 @@ -# This file is automatically @generated by Cargo. -# It is not intended for manual editing. -version = 4 - -[[package]] -name = "example" -version = "0.1.0" diff --git a/examples/15-transient-0/output/rust/Cargo.toml b/examples/15-transient-0/output/rust/Cargo.toml deleted file mode 100644 index 5d4c622..0000000 --- a/examples/15-transient-0/output/rust/Cargo.toml +++ /dev/null @@ -1,6 +0,0 @@ -[package] -name = "example" -version = "0.1.0" -edition = "2024" - -[dependencies] diff --git a/examples/15-transient-0/output/rust/rust-toolchain.toml b/examples/15-transient-0/output/rust/rust-toolchain.toml deleted file mode 100644 index 4fedb95..0000000 --- a/examples/15-transient-0/output/rust/rust-toolchain.toml +++ /dev/null @@ -1,2 +0,0 @@ -[toolchain] -channel = "1.96" diff --git a/examples/15-transient-0/output/rust/src/data.rs b/examples/15-transient-0/output/rust/src/data.rs deleted file mode 100644 index 2b890c2..0000000 --- a/examples/15-transient-0/output/rust/src/data.rs +++ /dev/null @@ -1,66 +0,0 @@ -include!("./gen/data.rs"); - -#[derive(Clone, Debug, Hash, PartialEq)] -pub struct Native { - pub a: i32, - pub b: i32, -} - -#[derive(Clone, Debug, Hash, PartialEq)] -pub struct GenericNative<A, B> { - pub a: A, - pub b: B, -} - - -pub mod transient_0 { - use ::std::any::Any; - use ::std::sync::Arc; - use ::std::vec::Vec; - use crate::transient_0::{Decode, Encode}; - use super::{GenericNative, Native}; - - include!("./gen/data/transient_0.rs"); - - pub fn encode_native( - value: &Native, - writer: &mut impl std::io::Write, - shared_values: &mut ::std::collections::HashMap::<usize, i64>, - ) -> std::io::Result<()> { - crate::transient_0::encode_int_32(&value.a, writer, shared_values)?; - crate::transient_0::encode_int_32(&value.b, writer, shared_values)?; - Ok(()) - } - - pub fn decode_native( - reader: &mut impl std::io::Read, - shared_values: &mut Vec<Arc::<dyn Any + Sync + Send>>, - ) -> std::io::Result<Native> { - let a = crate::transient_0::decode_int_32(reader, shared_values)?; - let b = crate::transient_0::decode_int_32(reader, shared_values)?; - Ok(Native { a, b }) - } - - pub fn encode_generic_native<TWrite: std::io::Write, A, B>( - value: &GenericNative<A, B>, - writer: &mut TWrite, - shared_values: &mut ::std::collections::HashMap::<usize, i64>, - encode_a: Encode<A, TWrite>, - encode_b: Encode<B, TWrite>, - ) -> std::io::Result<()> { - encode_a(&value.a, writer, shared_values)?; - encode_b(&value.b, writer, shared_values)?; - Ok(()) - } - - pub fn decode_generic_native<TRead: std::io::Read, A, B>( - reader: &mut TRead, - shared_values: &mut Vec<Arc::<dyn Any + Sync + Send>>, - decode_a: Decode<TRead, A>, - decode_b: Decode<TRead, B>, - ) -> std::io::Result<GenericNative<A, B>> { - let a = decode_a(reader, shared_values)?; - let b = decode_b(reader, shared_values)?; - Ok(GenericNative { a, b }) - } -} diff --git a/examples/15-transient-0/output/rust/src/gen/data.rs b/examples/15-transient-0/output/rust/src/gen/data.rs deleted file mode 100644 index 6f1d5b5..0000000 --- a/examples/15-transient-0/output/rust/src/gen/data.rs +++ /dev/null @@ -1,151 +0,0 @@ -// Generated by hobgoblin. - -#[derive(Clone, Debug, Hash, PartialEq)] -pub struct StructSingleton; - -#[derive(Clone, Debug, Hash, PartialEq)] -pub struct StructWithBool { - pub a: ::core::primitive::bool, - pub b: ::core::primitive::bool, -} - -#[derive(Clone, Debug, Hash, PartialEq)] -pub struct StructWithInt8 { - pub a: ::core::primitive::i8, - pub b: ::core::primitive::i8, -} - -#[derive(Clone, Debug, Hash, PartialEq)] -pub struct StructWithInt32 { - pub a: ::core::primitive::i32, - pub b: ::core::primitive::i32, -} - -#[derive(Clone, Debug, Hash, PartialEq)] -pub struct StructWithInt64 { - pub a: ::core::primitive::i64, - pub b: ::core::primitive::i64, -} - -#[derive(Clone, Debug, Hash, PartialEq)] -pub struct StructWithString { - pub a: ::std::string::String, - pub b: ::std::string::String, -} - -#[derive(Clone, Debug, Hash, PartialEq)] -pub struct StructWithStruct { - pub inner: crate::data::StructWithInt32, - pub c: ::core::primitive::i32, -} - -#[derive(Clone, Debug, Hash, PartialEq)] -pub struct StructWithList { - pub a: ::std::vec::Vec::<::core::primitive::i64>, - pub b: ::std::vec::Vec::<crate::data::StructWithInt32>, -} - -#[derive(Clone, Debug, Hash, PartialEq)] -pub struct StructWithOption { - pub a: ::std::option::Option::<::core::primitive::i64>, - pub b: ::std::option::Option::<crate::data::StructWithInt32>, -} - -#[derive(Clone, Copy, Debug, Hash, PartialEq)] -pub enum EnumWithVariants { - Zero, - One, - Two, -} - -#[derive(Clone, Debug, Hash, PartialEq)] -pub struct StructWithEnum { - pub inner: crate::data::EnumWithVariants, - pub c: ::core::primitive::i32, -} - -#[derive(Clone, Debug, Hash, PartialEq)] -pub enum SumWithVariants { - VariantOne(crate::data::VariantOne), - VariantTwo(crate::data::VariantTwo), -} - -impl ::std::convert::From::<crate::data::VariantOne> for crate::data::SumWithVariants { - fn from(value: crate::data::VariantOne) -> Self { - Self::VariantOne(value) - } -} - -impl ::std::convert::From::<crate::data::VariantTwo> for crate::data::SumWithVariants { - fn from(value: crate::data::VariantTwo) -> Self { - Self::VariantTwo(value) - } -} - -#[derive(Clone, Debug, Hash, PartialEq)] -pub struct VariantOne { - pub a: ::core::primitive::i32, -} - -#[derive(Clone, Debug, Hash, PartialEq)] -pub struct VariantTwo { - pub a: ::core::primitive::i64, -} - -#[derive(Clone, Debug, Hash, PartialEq)] -pub enum SumWithBoxedVariants { - VariantOne(::std::boxed::Box::<crate::data::VariantOne>), - VariantTwo(::std::boxed::Box::<crate::data::VariantTwo>), -} - -impl ::std::convert::From::<crate::data::VariantOne> for crate::data::SumWithBoxedVariants { - fn from(value: crate::data::VariantOne) -> Self { - Self::VariantOne(::std::boxed::Box::new(value)) - } -} - -impl ::std::convert::From::<crate::data::VariantTwo> for crate::data::SumWithBoxedVariants { - fn from(value: crate::data::VariantTwo) -> Self { - Self::VariantTwo(::std::boxed::Box::new(value)) - } -} - -#[derive(Clone, Debug, Hash, PartialEq)] -pub struct StructWithSum { - pub inner: crate::data::SumWithVariants, - pub b: ::core::primitive::i32, -} - -#[derive(Clone, Debug, Hash, PartialEq)] -pub struct StructWithNative { - pub a: crate::data::Native, -} - -#[derive(Clone, Debug, Hash, PartialEq)] -pub struct StructWithGenericNative { - pub a: crate::data::GenericNative::<::core::primitive::i32, ::std::string::String>, - pub b: crate::data::GenericNative::<::std::option::Option::<::std::string::String>, crate::data::GenericNative::<::std::option::Option::<::std::string::String>, crate::data::GenericNative::<::std::string::String, ::std::string::String>>>, -} - -#[derive(Clone, Debug, Hash, PartialEq)] -pub struct StructWithBox { - pub inner: ::std::boxed::Box::<crate::data::StructWithInt32>, -} - -#[derive(Clone, Debug, Hash, PartialEq)] -pub struct StructWithListOfShared { - pub inner: ::std::vec::Vec::<::std::sync::Arc::<crate::data::StructWithInt32>>, -} - -#[derive(Clone, Debug, Hash, PartialEq)] -pub struct StructWithDifferentSharedTypes { - pub a: ::std::sync::Arc::<crate::data::StructWithInt32>, - pub b: ::std::sync::Arc::<crate::data::StructWithInt64>, - pub c: ::std::sync::Arc::<crate::data::StructWithInt32>, -} - -#[derive(Clone, Debug, Hash, PartialEq)] -pub struct StructWithSharedSumAndVariant { - pub a: ::std::sync::Arc::<crate::data::SumWithVariants>, - pub b: ::std::sync::Arc::<crate::data::VariantOne>, -} diff --git a/examples/15-transient-0/output/rust/src/gen/data/transient_0.rs b/examples/15-transient-0/output/rust/src/gen/data/transient_0.rs deleted file mode 100644 index b72964c..0000000 --- a/examples/15-transient-0/output/rust/src/gen/data/transient_0.rs +++ /dev/null @@ -1,531 +0,0 @@ -// Generated by hobgoblin. - -pub fn encode_struct_singleton(value: &crate::data::StructSingleton, writer: &mut impl std::io::Write, shared_values: &mut ::std::collections::HashMap::<::core::primitive::usize, ::core::primitive::i64>) -> ::std::io::Result::<()> { - ::std::io::Result::Ok(()) -} - -pub fn decode_struct_singleton(reader: &mut impl std::io::Read, shared_values: &mut ::std::vec::Vec::<::std::sync::Arc::<dyn ::std::any::Any + ::std::marker::Sync + ::std::marker::Send>>) -> ::std::io::Result::<crate::data::StructSingleton> { - ::std::io::Result::Ok(crate::data::StructSingleton) -} - -pub fn encode_struct_with_bool(value: &crate::data::StructWithBool, writer: &mut impl std::io::Write, shared_values: &mut ::std::collections::HashMap::<::core::primitive::usize, ::core::primitive::i64>) -> ::std::io::Result::<()> { - crate::transient_0::encode_bool(&value.a, writer, shared_values)?; - crate::transient_0::encode_bool(&value.b, writer, shared_values)?; - ::std::io::Result::Ok(()) -} - -pub fn decode_struct_with_bool(reader: &mut impl std::io::Read, shared_values: &mut ::std::vec::Vec::<::std::sync::Arc::<dyn ::std::any::Any + ::std::marker::Sync + ::std::marker::Send>>) -> ::std::io::Result::<crate::data::StructWithBool> { - let a = crate::transient_0::decode_bool(reader, shared_values)?; - let b = crate::transient_0::decode_bool(reader, shared_values)?; - ::std::io::Result::Ok(crate::data::StructWithBool { a: a, b: b }) -} - -pub fn encode_struct_with_int_8(value: &crate::data::StructWithInt8, writer: &mut impl std::io::Write, shared_values: &mut ::std::collections::HashMap::<::core::primitive::usize, ::core::primitive::i64>) -> ::std::io::Result::<()> { - crate::transient_0::encode_int_8(&value.a, writer, shared_values)?; - crate::transient_0::encode_int_8(&value.b, writer, shared_values)?; - ::std::io::Result::Ok(()) -} - -pub fn decode_struct_with_int_8(reader: &mut impl std::io::Read, shared_values: &mut ::std::vec::Vec::<::std::sync::Arc::<dyn ::std::any::Any + ::std::marker::Sync + ::std::marker::Send>>) -> ::std::io::Result::<crate::data::StructWithInt8> { - let a = crate::transient_0::decode_int_8(reader, shared_values)?; - let b = crate::transient_0::decode_int_8(reader, shared_values)?; - ::std::io::Result::Ok(crate::data::StructWithInt8 { a: a, b: b }) -} - -pub fn encode_struct_with_int_32(value: &crate::data::StructWithInt32, writer: &mut impl std::io::Write, shared_values: &mut ::std::collections::HashMap::<::core::primitive::usize, ::core::primitive::i64>) -> ::std::io::Result::<()> { - crate::transient_0::encode_int_32(&value.a, writer, shared_values)?; - crate::transient_0::encode_int_32(&value.b, writer, shared_values)?; - ::std::io::Result::Ok(()) -} - -pub fn decode_struct_with_int_32(reader: &mut impl std::io::Read, shared_values: &mut ::std::vec::Vec::<::std::sync::Arc::<dyn ::std::any::Any + ::std::marker::Sync + ::std::marker::Send>>) -> ::std::io::Result::<crate::data::StructWithInt32> { - let a = crate::transient_0::decode_int_32(reader, shared_values)?; - let b = crate::transient_0::decode_int_32(reader, shared_values)?; - ::std::io::Result::Ok(crate::data::StructWithInt32 { a: a, b: b }) -} - -pub fn encode_struct_with_int_64(value: &crate::data::StructWithInt64, writer: &mut impl std::io::Write, shared_values: &mut ::std::collections::HashMap::<::core::primitive::usize, ::core::primitive::i64>) -> ::std::io::Result::<()> { - crate::transient_0::encode_int_64(&value.a, writer, shared_values)?; - crate::transient_0::encode_int_64(&value.b, writer, shared_values)?; - ::std::io::Result::Ok(()) -} - -pub fn decode_struct_with_int_64(reader: &mut impl std::io::Read, shared_values: &mut ::std::vec::Vec::<::std::sync::Arc::<dyn ::std::any::Any + ::std::marker::Sync + ::std::marker::Send>>) -> ::std::io::Result::<crate::data::StructWithInt64> { - let a = crate::transient_0::decode_int_64(reader, shared_values)?; - let b = crate::transient_0::decode_int_64(reader, shared_values)?; - ::std::io::Result::Ok(crate::data::StructWithInt64 { a: a, b: b }) -} - -pub fn encode_struct_with_string(value: &crate::data::StructWithString, writer: &mut impl std::io::Write, shared_values: &mut ::std::collections::HashMap::<::core::primitive::usize, ::core::primitive::i64>) -> ::std::io::Result::<()> { - crate::transient_0::encode_string(&value.a, writer, shared_values)?; - crate::transient_0::encode_string(&value.b, writer, shared_values)?; - ::std::io::Result::Ok(()) -} - -pub fn decode_struct_with_string(reader: &mut impl std::io::Read, shared_values: &mut ::std::vec::Vec::<::std::sync::Arc::<dyn ::std::any::Any + ::std::marker::Sync + ::std::marker::Send>>) -> ::std::io::Result::<crate::data::StructWithString> { - let a = crate::transient_0::decode_string(reader, shared_values)?; - let b = crate::transient_0::decode_string(reader, shared_values)?; - ::std::io::Result::Ok(crate::data::StructWithString { a: a, b: b }) -} - -pub fn encode_struct_with_struct(value: &crate::data::StructWithStruct, writer: &mut impl std::io::Write, shared_values: &mut ::std::collections::HashMap::<::core::primitive::usize, ::core::primitive::i64>) -> ::std::io::Result::<()> { - crate::data::transient_0::encode_struct_with_int_32(&value.inner, writer, shared_values)?; - crate::transient_0::encode_int_32(&value.c, writer, shared_values)?; - ::std::io::Result::Ok(()) -} - -pub fn decode_struct_with_struct(reader: &mut impl std::io::Read, shared_values: &mut ::std::vec::Vec::<::std::sync::Arc::<dyn ::std::any::Any + ::std::marker::Sync + ::std::marker::Send>>) -> ::std::io::Result::<crate::data::StructWithStruct> { - let inner = crate::data::transient_0::decode_struct_with_int_32(reader, shared_values)?; - let c = crate::transient_0::decode_int_32(reader, shared_values)?; - ::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, shared_values: &mut ::std::collections::HashMap::<::core::primitive::usize, ::core::primitive::i64>) -> ::std::io::Result::<()> { - { - crate::transient_0::encode_int_64(&(((&value.a).len()).try_into()).map_err(|error| ::std::io::Error::new(::std::io::ErrorKind::InvalidData, error))?, writer, shared_values)?; - for element in &value.a { - crate::transient_0::encode_int_64(element, writer, shared_values)?; - }; - }; - { - crate::transient_0::encode_int_64(&(((&value.b).len()).try_into()).map_err(|error| ::std::io::Error::new(::std::io::ErrorKind::InvalidData, error))?, writer, shared_values)?; - for element in &value.b { - crate::data::transient_0::encode_struct_with_int_32(element, writer, shared_values)?; - }; - }; - ::std::io::Result::Ok(()) -} - -pub fn decode_struct_with_list(reader: &mut impl std::io::Read, shared_values: &mut ::std::vec::Vec::<::std::sync::Arc::<dyn ::std::any::Any + ::std::marker::Sync + ::std::marker::Send>>) -> ::std::io::Result::<crate::data::StructWithList> { - let a = { - let len = crate::transient_0::decode_int_64(reader, shared_values)?; - 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::transient_0::decode_int_64(reader, shared_values)?); - }; - elements - }; - let b = { - let len = crate::transient_0::decode_int_64(reader, shared_values)?; - 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_struct_with_int_32(reader, shared_values)?); - }; - elements - }; - ::std::io::Result::Ok(crate::data::StructWithList { a: a, b: b }) -} - -pub fn encode_struct_with_option(value: &crate::data::StructWithOption, writer: &mut impl std::io::Write, shared_values: &mut ::std::collections::HashMap::<::core::primitive::usize, ::core::primitive::i64>) -> ::std::io::Result::<()> { - match &value.a { - ::std::option::Option::Some(value) => { - crate::transient_0::encode_bool(&true, writer, shared_values)?; - crate::transient_0::encode_int_64(&value, writer, shared_values)?; - }, - ::std::option::Option::None => { - crate::transient_0::encode_bool(&false, writer, shared_values)?; - }, - }; - match &value.b { - ::std::option::Option::Some(value) => { - crate::transient_0::encode_bool(&true, writer, shared_values)?; - crate::data::transient_0::encode_struct_with_int_32(&value, writer, shared_values)?; - }, - ::std::option::Option::None => { - crate::transient_0::encode_bool(&false, writer, shared_values)?; - }, - }; - ::std::io::Result::Ok(()) -} - -pub fn decode_struct_with_option(reader: &mut impl std::io::Read, shared_values: &mut ::std::vec::Vec::<::std::sync::Arc::<dyn ::std::any::Any + ::std::marker::Sync + ::std::marker::Send>>) -> ::std::io::Result::<crate::data::StructWithOption> { - let a = { - let is_some = crate::transient_0::decode_bool(reader, shared_values)?; - if is_some { - ::std::option::Option::Some(crate::transient_0::decode_int_64(reader, shared_values)?) - } else { - ::std::option::Option::None - } - }; - let b = { - let is_some = crate::transient_0::decode_bool(reader, shared_values)?; - if is_some { - ::std::option::Option::Some(crate::data::transient_0::decode_struct_with_int_32(reader, shared_values)?) - } else { - ::std::option::Option::None - } - }; - ::std::io::Result::Ok(crate::data::StructWithOption { a: a, b: b }) -} - -pub fn encode_enum_with_variants(value: &crate::data::EnumWithVariants, writer: &mut impl std::io::Write, shared_values: &mut ::std::collections::HashMap::<::core::primitive::usize, ::core::primitive::i64>) -> ::std::io::Result::<()> { - crate::transient_0::encode_int_32(&match value { - crate::data::EnumWithVariants::Zero => 0, - crate::data::EnumWithVariants::One => 1, - crate::data::EnumWithVariants::Two => 2, - }, writer, shared_values)?; - ::std::io::Result::Ok(()) -} - -pub fn decode_enum_with_variants(reader: &mut impl std::io::Read, shared_values: &mut ::std::vec::Vec::<::std::sync::Arc::<dyn ::std::any::Any + ::std::marker::Sync + ::std::marker::Send>>) -> ::std::io::Result::<crate::data::EnumWithVariants> { - ::std::io::Result::Ok(match &crate::transient_0::decode_int_32(reader, shared_values)? { - 0 => crate::data::EnumWithVariants::Zero, - 1 => crate::data::EnumWithVariants::One, - 2 => crate::data::EnumWithVariants::Two, - _ => ::std::result::Result::Err(::std::io::Error::new(::std::io::ErrorKind::InvalidData, "unrecognised variant tag for data.EnumWithVariants"))?, - }) -} - -pub fn encode_struct_with_enum(value: &crate::data::StructWithEnum, writer: &mut impl std::io::Write, shared_values: &mut ::std::collections::HashMap::<::core::primitive::usize, ::core::primitive::i64>) -> ::std::io::Result::<()> { - crate::data::transient_0::encode_enum_with_variants(&value.inner, writer, shared_values)?; - crate::transient_0::encode_int_32(&value.c, writer, shared_values)?; - ::std::io::Result::Ok(()) -} - -pub fn decode_struct_with_enum(reader: &mut impl std::io::Read, shared_values: &mut ::std::vec::Vec::<::std::sync::Arc::<dyn ::std::any::Any + ::std::marker::Sync + ::std::marker::Send>>) -> ::std::io::Result::<crate::data::StructWithEnum> { - let inner = crate::data::transient_0::decode_enum_with_variants(reader, shared_values)?; - let c = crate::transient_0::decode_int_32(reader, shared_values)?; - ::std::io::Result::Ok(crate::data::StructWithEnum { inner: inner, c: c }) -} - -pub fn encode_sum_with_variants(value: &crate::data::SumWithVariants, writer: &mut impl std::io::Write, shared_values: &mut ::std::collections::HashMap::<::core::primitive::usize, ::core::primitive::i64>) -> ::std::io::Result::<()> { - match value { - crate::data::SumWithVariants::VariantOne(value) => { - crate::transient_0::encode_int_32(&0, writer, shared_values)?; - crate::data::transient_0::encode_variant_one(value, writer, shared_values)?; - }, - crate::data::SumWithVariants::VariantTwo(value) => { - crate::transient_0::encode_int_32(&1, writer, shared_values)?; - crate::data::transient_0::encode_variant_two(value, writer, shared_values)?; - }, - }; - ::std::io::Result::Ok(()) -} - -pub fn decode_sum_with_variants(reader: &mut impl std::io::Read, shared_values: &mut ::std::vec::Vec::<::std::sync::Arc::<dyn ::std::any::Any + ::std::marker::Sync + ::std::marker::Send>>) -> ::std::io::Result::<crate::data::SumWithVariants> { - ::std::io::Result::Ok(match &crate::transient_0::decode_int_32(reader, shared_values)? { - 0 => crate::data::SumWithVariants::VariantOne(crate::data::transient_0::decode_variant_one(reader, shared_values)?), - 1 => crate::data::SumWithVariants::VariantTwo(crate::data::transient_0::decode_variant_two(reader, shared_values)?), - _ => ::std::result::Result::Err(::std::io::Error::new(::std::io::ErrorKind::InvalidData, "unrecognised variant tag for data.SumWithVariants"))?, - }) -} - -pub fn encode_variant_one(value: &crate::data::VariantOne, writer: &mut impl std::io::Write, shared_values: &mut ::std::collections::HashMap::<::core::primitive::usize, ::core::primitive::i64>) -> ::std::io::Result::<()> { - crate::transient_0::encode_int_32(&value.a, writer, shared_values)?; - ::std::io::Result::Ok(()) -} - -pub fn decode_variant_one(reader: &mut impl std::io::Read, shared_values: &mut ::std::vec::Vec::<::std::sync::Arc::<dyn ::std::any::Any + ::std::marker::Sync + ::std::marker::Send>>) -> ::std::io::Result::<crate::data::VariantOne> { - let a = crate::transient_0::decode_int_32(reader, shared_values)?; - ::std::io::Result::Ok(crate::data::VariantOne { a: a }) -} - -pub fn encode_variant_two(value: &crate::data::VariantTwo, writer: &mut impl std::io::Write, shared_values: &mut ::std::collections::HashMap::<::core::primitive::usize, ::core::primitive::i64>) -> ::std::io::Result::<()> { - crate::transient_0::encode_int_64(&value.a, writer, shared_values)?; - ::std::io::Result::Ok(()) -} - -pub fn decode_variant_two(reader: &mut impl std::io::Read, shared_values: &mut ::std::vec::Vec::<::std::sync::Arc::<dyn ::std::any::Any + ::std::marker::Sync + ::std::marker::Send>>) -> ::std::io::Result::<crate::data::VariantTwo> { - let a = crate::transient_0::decode_int_64(reader, shared_values)?; - ::std::io::Result::Ok(crate::data::VariantTwo { a: a }) -} - -pub fn encode_sum_with_boxed_variants(value: &crate::data::SumWithBoxedVariants, writer: &mut impl std::io::Write, shared_values: &mut ::std::collections::HashMap::<::core::primitive::usize, ::core::primitive::i64>) -> ::std::io::Result::<()> { - match value { - crate::data::SumWithBoxedVariants::VariantOne(value) => { - crate::transient_0::encode_int_32(&0, writer, shared_values)?; - crate::data::transient_0::encode_variant_one(value.as_ref(), writer, shared_values)?; - }, - crate::data::SumWithBoxedVariants::VariantTwo(value) => { - crate::transient_0::encode_int_32(&1, writer, shared_values)?; - crate::data::transient_0::encode_variant_two(value.as_ref(), writer, shared_values)?; - }, - }; - ::std::io::Result::Ok(()) -} - -pub fn decode_sum_with_boxed_variants(reader: &mut impl std::io::Read, shared_values: &mut ::std::vec::Vec::<::std::sync::Arc::<dyn ::std::any::Any + ::std::marker::Sync + ::std::marker::Send>>) -> ::std::io::Result::<crate::data::SumWithBoxedVariants> { - ::std::io::Result::Ok(match &crate::transient_0::decode_int_32(reader, shared_values)? { - 0 => crate::data::SumWithBoxedVariants::VariantOne(::std::boxed::Box::new(crate::data::transient_0::decode_variant_one(reader, shared_values)?)), - 1 => crate::data::SumWithBoxedVariants::VariantTwo(::std::boxed::Box::new(crate::data::transient_0::decode_variant_two(reader, shared_values)?)), - _ => ::std::result::Result::Err(::std::io::Error::new(::std::io::ErrorKind::InvalidData, "unrecognised variant tag for data.SumWithBoxedVariants"))?, - }) -} - -pub fn encode_struct_with_sum(value: &crate::data::StructWithSum, writer: &mut impl std::io::Write, shared_values: &mut ::std::collections::HashMap::<::core::primitive::usize, ::core::primitive::i64>) -> ::std::io::Result::<()> { - crate::data::transient_0::encode_sum_with_variants(&value.inner, writer, shared_values)?; - crate::transient_0::encode_int_32(&value.b, writer, shared_values)?; - ::std::io::Result::Ok(()) -} - -pub fn decode_struct_with_sum(reader: &mut impl std::io::Read, shared_values: &mut ::std::vec::Vec::<::std::sync::Arc::<dyn ::std::any::Any + ::std::marker::Sync + ::std::marker::Send>>) -> ::std::io::Result::<crate::data::StructWithSum> { - let inner = crate::data::transient_0::decode_sum_with_variants(reader, shared_values)?; - let b = crate::transient_0::decode_int_32(reader, shared_values)?; - ::std::io::Result::Ok(crate::data::StructWithSum { inner: inner, b: b }) -} - -pub fn encode_struct_with_native(value: &crate::data::StructWithNative, writer: &mut impl std::io::Write, shared_values: &mut ::std::collections::HashMap::<::core::primitive::usize, ::core::primitive::i64>) -> ::std::io::Result::<()> { - crate::data::transient_0::encode_native(&value.a, writer, shared_values)?; - ::std::io::Result::Ok(()) -} - -pub fn decode_struct_with_native(reader: &mut impl std::io::Read, shared_values: &mut ::std::vec::Vec::<::std::sync::Arc::<dyn ::std::any::Any + ::std::marker::Sync + ::std::marker::Send>>) -> ::std::io::Result::<crate::data::StructWithNative> { - let a = crate::data::transient_0::decode_native(reader, shared_values)?; - ::std::io::Result::Ok(crate::data::StructWithNative { a: a }) -} - -pub fn encode_struct_with_generic_native(value: &crate::data::StructWithGenericNative, writer: &mut impl std::io::Write, shared_values: &mut ::std::collections::HashMap::<::core::primitive::usize, ::core::primitive::i64>) -> ::std::io::Result::<()> { - crate::data::transient_0::encode_generic_native(&value.a, writer, shared_values, |value, writer, shared_values| { - crate::transient_0::encode_int_32(value, writer, shared_values)?; - ::std::io::Result::Ok(()) - }, |value, writer, shared_values| { - crate::transient_0::encode_string(value, writer, shared_values)?; - ::std::io::Result::Ok(()) - })?; - crate::data::transient_0::encode_generic_native(&value.b, writer, shared_values, |value, writer, shared_values| { - match value { - ::std::option::Option::Some(value) => { - crate::transient_0::encode_bool(&true, writer, shared_values)?; - crate::transient_0::encode_string(&value, writer, shared_values)?; - }, - ::std::option::Option::None => { - crate::transient_0::encode_bool(&false, writer, shared_values)?; - }, - }; - ::std::io::Result::Ok(()) - }, |value, writer, shared_values| { - crate::data::transient_0::encode_generic_native(value, writer, shared_values, |value, writer, shared_values| { - match value { - ::std::option::Option::Some(value) => { - crate::transient_0::encode_bool(&true, writer, shared_values)?; - crate::transient_0::encode_string(&value, writer, shared_values)?; - }, - ::std::option::Option::None => { - crate::transient_0::encode_bool(&false, writer, shared_values)?; - }, - }; - ::std::io::Result::Ok(()) - }, |value, writer, shared_values| { - crate::data::transient_0::encode_generic_native(value, writer, shared_values, |value, writer, shared_values| { - crate::transient_0::encode_string(value, writer, shared_values)?; - ::std::io::Result::Ok(()) - }, |value, writer, shared_values| { - crate::transient_0::encode_string(value, writer, shared_values)?; - ::std::io::Result::Ok(()) - })?; - ::std::io::Result::Ok(()) - })?; - ::std::io::Result::Ok(()) - })?; - ::std::io::Result::Ok(()) -} - -pub fn decode_struct_with_generic_native(reader: &mut impl std::io::Read, shared_values: &mut ::std::vec::Vec::<::std::sync::Arc::<dyn ::std::any::Any + ::std::marker::Sync + ::std::marker::Send>>) -> ::std::io::Result::<crate::data::StructWithGenericNative> { - let a = crate::data::transient_0::decode_generic_native(reader, shared_values, |reader, shared_values| ::std::io::Result::Ok(crate::transient_0::decode_int_32(reader, shared_values)?), |reader, shared_values| ::std::io::Result::Ok(crate::transient_0::decode_string(reader, shared_values)?))?; - let b = crate::data::transient_0::decode_generic_native(reader, shared_values, |reader, shared_values| ::std::io::Result::Ok({ - let is_some = crate::transient_0::decode_bool(reader, shared_values)?; - if is_some { - ::std::option::Option::Some(crate::transient_0::decode_string(reader, shared_values)?) - } else { - ::std::option::Option::None - } - }), |reader, shared_values| ::std::io::Result::Ok(crate::data::transient_0::decode_generic_native(reader, shared_values, |reader, shared_values| ::std::io::Result::Ok({ - let is_some = crate::transient_0::decode_bool(reader, shared_values)?; - if is_some { - ::std::option::Option::Some(crate::transient_0::decode_string(reader, shared_values)?) - } else { - ::std::option::Option::None - } - }), |reader, shared_values| ::std::io::Result::Ok(crate::data::transient_0::decode_generic_native(reader, shared_values, |reader, shared_values| ::std::io::Result::Ok(crate::transient_0::decode_string(reader, shared_values)?), |reader, shared_values| ::std::io::Result::Ok(crate::transient_0::decode_string(reader, shared_values)?))?))?))?; - ::std::io::Result::Ok(crate::data::StructWithGenericNative { a: a, b: b }) -} - -pub fn encode_struct_with_box(value: &crate::data::StructWithBox, writer: &mut impl std::io::Write, shared_values: &mut ::std::collections::HashMap::<::core::primitive::usize, ::core::primitive::i64>) -> ::std::io::Result::<()> { - crate::data::transient_0::encode_struct_with_int_32((&value.inner).as_ref(), writer, shared_values)?; - ::std::io::Result::Ok(()) -} - -pub fn decode_struct_with_box(reader: &mut impl std::io::Read, shared_values: &mut ::std::vec::Vec::<::std::sync::Arc::<dyn ::std::any::Any + ::std::marker::Sync + ::std::marker::Send>>) -> ::std::io::Result::<crate::data::StructWithBox> { - let inner = ::std::boxed::Box::new(crate::data::transient_0::decode_struct_with_int_32(reader, shared_values)?); - ::std::io::Result::Ok(crate::data::StructWithBox { inner: inner }) -} - -pub fn encode_struct_with_list_of_shared(value: &crate::data::StructWithListOfShared, writer: &mut impl std::io::Write, shared_values: &mut ::std::collections::HashMap::<::core::primitive::usize, ::core::primitive::i64>) -> ::std::io::Result::<()> { - { - crate::transient_0::encode_int_64(&(((&value.inner).len()).try_into()).map_err(|error| ::std::io::Error::new(::std::io::ErrorKind::InvalidData, error))?, writer, shared_values)?; - for element in &value.inner { - { - let ptr = ::std::sync::Arc::as_ptr(&element) as ::core::primitive::usize; - match (shared_values.get(&ptr)).copied() { - ::std::option::Option::Some(id) => { - crate::transient_0::encode_int_64(&id, writer, shared_values)?; - }, - ::std::option::Option::None => { - let id = ((shared_values.len()).try_into()).map_err(|error| ::std::io::Error::new(::std::io::ErrorKind::InvalidData, error))?; - crate::transient_0::encode_int_64(&id, writer, shared_values)?; - shared_values.insert(ptr, id); - crate::data::transient_0::encode_struct_with_int_32(element.as_ref(), writer, shared_values)?; - }, - }; - }; - }; - }; - ::std::io::Result::Ok(()) -} - -pub fn decode_struct_with_list_of_shared(reader: &mut impl std::io::Read, shared_values: &mut ::std::vec::Vec::<::std::sync::Arc::<dyn ::std::any::Any + ::std::marker::Sync + ::std::marker::Send>>) -> ::std::io::Result::<crate::data::StructWithListOfShared> { - let inner = { - let len = crate::transient_0::decode_int_64(reader, shared_values)?; - 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({ - let id = crate::transient_0::decode_int_64(reader, shared_values)?; - if id < ((shared_values.len()).try_into()).map_err(|error| ::std::io::Error::new(::std::io::ErrorKind::InvalidData, error))? { - ((::std::sync::Arc::clone(&shared_values[(::core::primitive::usize::try_from(id)).map_err(|error| ::std::io::Error::new(::std::io::ErrorKind::InvalidData, error))?])).downcast()).map_err(|error| ::std::io::Error::new(::std::io::ErrorKind::InvalidData, "referenced value has wrong type"))? - } else { - let decoded_value = ::std::sync::Arc::new(crate::data::transient_0::decode_struct_with_int_32(reader, shared_values)?); - shared_values.push(::std::sync::Arc::clone(&decoded_value) as ::std::sync::Arc::<dyn ::std::any::Any + ::std::marker::Sync + ::std::marker::Send>); - decoded_value - } - }); - }; - elements - }; - ::std::io::Result::Ok(crate::data::StructWithListOfShared { inner: inner }) -} - -pub fn encode_struct_with_different_shared_types(value: &crate::data::StructWithDifferentSharedTypes, writer: &mut impl std::io::Write, shared_values: &mut ::std::collections::HashMap::<::core::primitive::usize, ::core::primitive::i64>) -> ::std::io::Result::<()> { - { - let ptr = ::std::sync::Arc::as_ptr(&&value.a) as ::core::primitive::usize; - match (shared_values.get(&ptr)).copied() { - ::std::option::Option::Some(id) => { - crate::transient_0::encode_int_64(&id, writer, shared_values)?; - }, - ::std::option::Option::None => { - let id = ((shared_values.len()).try_into()).map_err(|error| ::std::io::Error::new(::std::io::ErrorKind::InvalidData, error))?; - crate::transient_0::encode_int_64(&id, writer, shared_values)?; - shared_values.insert(ptr, id); - crate::data::transient_0::encode_struct_with_int_32((&value.a).as_ref(), writer, shared_values)?; - }, - }; - }; - { - let ptr = ::std::sync::Arc::as_ptr(&&value.b) as ::core::primitive::usize; - match (shared_values.get(&ptr)).copied() { - ::std::option::Option::Some(id) => { - crate::transient_0::encode_int_64(&id, writer, shared_values)?; - }, - ::std::option::Option::None => { - let id = ((shared_values.len()).try_into()).map_err(|error| ::std::io::Error::new(::std::io::ErrorKind::InvalidData, error))?; - crate::transient_0::encode_int_64(&id, writer, shared_values)?; - shared_values.insert(ptr, id); - crate::data::transient_0::encode_struct_with_int_64((&value.b).as_ref(), writer, shared_values)?; - }, - }; - }; - { - let ptr = ::std::sync::Arc::as_ptr(&&value.c) as ::core::primitive::usize; - match (shared_values.get(&ptr)).copied() { - ::std::option::Option::Some(id) => { - crate::transient_0::encode_int_64(&id, writer, shared_values)?; - }, - ::std::option::Option::None => { - let id = ((shared_values.len()).try_into()).map_err(|error| ::std::io::Error::new(::std::io::ErrorKind::InvalidData, error))?; - crate::transient_0::encode_int_64(&id, writer, shared_values)?; - shared_values.insert(ptr, id); - crate::data::transient_0::encode_struct_with_int_32((&value.c).as_ref(), writer, shared_values)?; - }, - }; - }; - ::std::io::Result::Ok(()) -} - -pub fn decode_struct_with_different_shared_types(reader: &mut impl std::io::Read, shared_values: &mut ::std::vec::Vec::<::std::sync::Arc::<dyn ::std::any::Any + ::std::marker::Sync + ::std::marker::Send>>) -> ::std::io::Result::<crate::data::StructWithDifferentSharedTypes> { - let a = { - let id = crate::transient_0::decode_int_64(reader, shared_values)?; - if id < ((shared_values.len()).try_into()).map_err(|error| ::std::io::Error::new(::std::io::ErrorKind::InvalidData, error))? { - ((::std::sync::Arc::clone(&shared_values[(::core::primitive::usize::try_from(id)).map_err(|error| ::std::io::Error::new(::std::io::ErrorKind::InvalidData, error))?])).downcast()).map_err(|error| ::std::io::Error::new(::std::io::ErrorKind::InvalidData, "referenced value has wrong type"))? - } else { - let decoded_value = ::std::sync::Arc::new(crate::data::transient_0::decode_struct_with_int_32(reader, shared_values)?); - shared_values.push(::std::sync::Arc::clone(&decoded_value) as ::std::sync::Arc::<dyn ::std::any::Any + ::std::marker::Sync + ::std::marker::Send>); - decoded_value - } - }; - let b = { - let id = crate::transient_0::decode_int_64(reader, shared_values)?; - if id < ((shared_values.len()).try_into()).map_err(|error| ::std::io::Error::new(::std::io::ErrorKind::InvalidData, error))? { - ((::std::sync::Arc::clone(&shared_values[(::core::primitive::usize::try_from(id)).map_err(|error| ::std::io::Error::new(::std::io::ErrorKind::InvalidData, error))?])).downcast()).map_err(|error| ::std::io::Error::new(::std::io::ErrorKind::InvalidData, "referenced value has wrong type"))? - } else { - let decoded_value = ::std::sync::Arc::new(crate::data::transient_0::decode_struct_with_int_64(reader, shared_values)?); - shared_values.push(::std::sync::Arc::clone(&decoded_value) as ::std::sync::Arc::<dyn ::std::any::Any + ::std::marker::Sync + ::std::marker::Send>); - decoded_value - } - }; - let c = { - let id = crate::transient_0::decode_int_64(reader, shared_values)?; - if id < ((shared_values.len()).try_into()).map_err(|error| ::std::io::Error::new(::std::io::ErrorKind::InvalidData, error))? { - ((::std::sync::Arc::clone(&shared_values[(::core::primitive::usize::try_from(id)).map_err(|error| ::std::io::Error::new(::std::io::ErrorKind::InvalidData, error))?])).downcast()).map_err(|error| ::std::io::Error::new(::std::io::ErrorKind::InvalidData, "referenced value has wrong type"))? - } else { - let decoded_value = ::std::sync::Arc::new(crate::data::transient_0::decode_struct_with_int_32(reader, shared_values)?); - shared_values.push(::std::sync::Arc::clone(&decoded_value) as ::std::sync::Arc::<dyn ::std::any::Any + ::std::marker::Sync + ::std::marker::Send>); - decoded_value - } - }; - ::std::io::Result::Ok(crate::data::StructWithDifferentSharedTypes { a: a, b: b, c: c }) -} - -pub fn encode_struct_with_shared_sum_and_variant(value: &crate::data::StructWithSharedSumAndVariant, writer: &mut impl std::io::Write, shared_values: &mut ::std::collections::HashMap::<::core::primitive::usize, ::core::primitive::i64>) -> ::std::io::Result::<()> { - { - let ptr = ::std::sync::Arc::as_ptr(&&value.a) as ::core::primitive::usize; - match (shared_values.get(&ptr)).copied() { - ::std::option::Option::Some(id) => { - crate::transient_0::encode_int_64(&id, writer, shared_values)?; - }, - ::std::option::Option::None => { - let id = ((shared_values.len()).try_into()).map_err(|error| ::std::io::Error::new(::std::io::ErrorKind::InvalidData, error))?; - crate::transient_0::encode_int_64(&id, writer, shared_values)?; - shared_values.insert(ptr, id); - crate::data::transient_0::encode_sum_with_variants((&value.a).as_ref(), writer, shared_values)?; - }, - }; - }; - { - let ptr = ::std::sync::Arc::as_ptr(&&value.b) as ::core::primitive::usize; - match (shared_values.get(&ptr)).copied() { - ::std::option::Option::Some(id) => { - crate::transient_0::encode_int_64(&id, writer, shared_values)?; - }, - ::std::option::Option::None => { - let id = ((shared_values.len()).try_into()).map_err(|error| ::std::io::Error::new(::std::io::ErrorKind::InvalidData, error))?; - crate::transient_0::encode_int_64(&id, writer, shared_values)?; - shared_values.insert(ptr, id); - crate::data::transient_0::encode_variant_one((&value.b).as_ref(), writer, shared_values)?; - }, - }; - }; - ::std::io::Result::Ok(()) -} - -pub fn decode_struct_with_shared_sum_and_variant(reader: &mut impl std::io::Read, shared_values: &mut ::std::vec::Vec::<::std::sync::Arc::<dyn ::std::any::Any + ::std::marker::Sync + ::std::marker::Send>>) -> ::std::io::Result::<crate::data::StructWithSharedSumAndVariant> { - let a = { - let id = crate::transient_0::decode_int_64(reader, shared_values)?; - if id < ((shared_values.len()).try_into()).map_err(|error| ::std::io::Error::new(::std::io::ErrorKind::InvalidData, error))? { - ((::std::sync::Arc::clone(&shared_values[(::core::primitive::usize::try_from(id)).map_err(|error| ::std::io::Error::new(::std::io::ErrorKind::InvalidData, error))?])).downcast()).map_err(|error| ::std::io::Error::new(::std::io::ErrorKind::InvalidData, "referenced value has wrong type"))? - } else { - let decoded_value = ::std::sync::Arc::new(crate::data::transient_0::decode_sum_with_variants(reader, shared_values)?); - shared_values.push(::std::sync::Arc::clone(&decoded_value) as ::std::sync::Arc::<dyn ::std::any::Any + ::std::marker::Sync + ::std::marker::Send>); - decoded_value - } - }; - let b = { - let id = crate::transient_0::decode_int_64(reader, shared_values)?; - if id < ((shared_values.len()).try_into()).map_err(|error| ::std::io::Error::new(::std::io::ErrorKind::InvalidData, error))? { - ((::std::sync::Arc::clone(&shared_values[(::core::primitive::usize::try_from(id)).map_err(|error| ::std::io::Error::new(::std::io::ErrorKind::InvalidData, error))?])).downcast()).map_err(|error| ::std::io::Error::new(::std::io::ErrorKind::InvalidData, "referenced value has wrong type"))? - } else { - let decoded_value = ::std::sync::Arc::new(crate::data::transient_0::decode_variant_one(reader, shared_values)?); - shared_values.push(::std::sync::Arc::clone(&decoded_value) as ::std::sync::Arc::<dyn ::std::any::Any + ::std::marker::Sync + ::std::marker::Send>); - decoded_value - } - }; - ::std::io::Result::Ok(crate::data::StructWithSharedSumAndVariant { a: a, b: b }) -} diff --git a/examples/15-transient-0/output/rust/src/gen/transient_0.rs b/examples/15-transient-0/output/rust/src/gen/transient_0.rs deleted file mode 100644 index b65ab95..0000000 --- a/examples/15-transient-0/output/rust/src/gen/transient_0.rs +++ /dev/null @@ -1,88 +0,0 @@ -// Generated by hobgoblin. - -pub type Encode<T, TWrite: ::std::io::Write> = fn(&T, &mut TWrite, &mut ::std::collections::HashMap::<::core::primitive::usize, ::core::primitive::i64>) -> ::std::io::Result::<()>; - -pub type Decode<TRead: ::std::io::Read, T> = fn(&mut TRead, &mut ::std::vec::Vec::<::std::sync::Arc::<dyn ::std::any::Any + ::std::marker::Sync + ::std::marker::Send>>) -> ::std::io::Result::<T>; - -pub fn encode_bool(value: &::core::primitive::bool, writer: &mut impl std::io::Write, shared_values: &mut ::std::collections::HashMap::<::core::primitive::usize, ::core::primitive::i64>) -> ::std::io::Result::<()> { - if *value { - writer.write_all(&1u8.to_le_bytes())?; - } else { - writer.write_all(&0u8.to_le_bytes())?; - }; - ::std::io::Result::Ok(()) -} - -pub fn decode_bool(reader: &mut impl std::io::Read, shared_values: &mut ::std::vec::Vec::<::std::sync::Arc::<dyn ::std::any::Any + ::std::marker::Sync + ::std::marker::Send>>) -> ::std::io::Result::<::core::primitive::bool> { - let int_value = { - let bytes = { - let mut bytes = [0; 1]; - reader.read_exact(&mut bytes)?; - bytes - }; - u8::from_le_bytes(bytes) - }; - ::std::io::Result::Ok(if int_value == 0 { - false - } else { - true - }) -} - -pub fn encode_int_8(value: &::core::primitive::i8, writer: &mut impl std::io::Write, shared_values: &mut ::std::collections::HashMap::<::core::primitive::usize, ::core::primitive::i64>) -> ::std::io::Result::<()> { - writer.write_all(&value.to_le_bytes())?; - ::std::io::Result::Ok(()) -} - -pub fn decode_int_8(reader: &mut impl std::io::Read, shared_values: &mut ::std::vec::Vec::<::std::sync::Arc::<dyn ::std::any::Any + ::std::marker::Sync + ::std::marker::Send>>) -> ::std::io::Result::<::core::primitive::i8> { - let bytes = { - let mut bytes = [0; 1]; - reader.read_exact(&mut bytes)?; - bytes - }; - ::std::io::Result::Ok(::core::primitive::i8::from_le_bytes(bytes)) -} - -pub fn encode_int_32(value: &::core::primitive::i32, writer: &mut impl std::io::Write, shared_values: &mut ::std::collections::HashMap::<::core::primitive::usize, ::core::primitive::i64>) -> ::std::io::Result::<()> { - writer.write_all(&value.to_le_bytes())?; - ::std::io::Result::Ok(()) -} - -pub fn decode_int_32(reader: &mut impl std::io::Read, shared_values: &mut ::std::vec::Vec::<::std::sync::Arc::<dyn ::std::any::Any + ::std::marker::Sync + ::std::marker::Send>>) -> ::std::io::Result::<::core::primitive::i32> { - let bytes = { - let mut bytes = [0; 4]; - reader.read_exact(&mut bytes)?; - bytes - }; - ::std::io::Result::Ok(::core::primitive::i32::from_le_bytes(bytes)) -} - -pub fn encode_int_64(value: &::core::primitive::i64, writer: &mut impl std::io::Write, shared_values: &mut ::std::collections::HashMap::<::core::primitive::usize, ::core::primitive::i64>) -> ::std::io::Result::<()> { - writer.write_all(&value.to_le_bytes())?; - ::std::io::Result::Ok(()) -} - -pub fn decode_int_64(reader: &mut impl std::io::Read, shared_values: &mut ::std::vec::Vec::<::std::sync::Arc::<dyn ::std::any::Any + ::std::marker::Sync + ::std::marker::Send>>) -> ::std::io::Result::<::core::primitive::i64> { - let bytes = { - let mut bytes = [0; 8]; - reader.read_exact(&mut bytes)?; - bytes - }; - ::std::io::Result::Ok(::core::primitive::i64::from_le_bytes(bytes)) -} - -pub fn encode_string(value: &::std::string::String, writer: &mut impl std::io::Write, shared_values: &mut ::std::collections::HashMap::<::core::primitive::usize, ::core::primitive::i64>) -> ::std::io::Result::<()> { - crate::transient_0::encode_int_64(&((value.len()).try_into()).map_err(|error| ::std::io::Error::new(::std::io::ErrorKind::InvalidData, error))?, writer, shared_values)?; - writer.write_all(value.as_bytes())?; - ::std::io::Result::Ok(()) -} - -pub fn decode_string(reader: &mut impl std::io::Read, shared_values: &mut ::std::vec::Vec::<::std::sync::Arc::<dyn ::std::any::Any + ::std::marker::Sync + ::std::marker::Send>>) -> ::std::io::Result::<::std::string::String> { - let len = crate::transient_0::decode_int_64(reader, shared_values)?; - let bytes = { - let mut bytes = vec![0u8; (len.try_into()).map_err(|error| ::std::io::Error::new(::std::io::ErrorKind::InvalidData, error))?]; - reader.read_exact(&mut bytes)?; - bytes - }; - ::std::io::Result::Ok((::std::string::String::from_utf8(bytes)).map_err(|error| ::std::io::Error::new(::std::io::ErrorKind::InvalidData, error))?) -} diff --git a/examples/15-transient-0/output/rust/src/lib.rs b/examples/15-transient-0/output/rust/src/lib.rs deleted file mode 100644 index a51afff..0000000 --- a/examples/15-transient-0/output/rust/src/lib.rs +++ /dev/null @@ -1,353 +0,0 @@ -pub mod data; -pub mod transient_0; - -#[cfg(test)] -mod test { - use std::any::Any; - use std::io::Cursor; - use std::path::PathBuf; - use std::sync::Arc; - use std::collections::HashMap; - use super::data::{EnumWithVariants, GenericNative, Native, StructSingleton, StructWithBool, StructWithBox, StructWithDifferentSharedTypes, StructWithEnum, StructWithGenericNative, StructWithInt8, StructWithInt32, StructWithInt64, StructWithList, StructWithListOfShared, StructWithNative, StructWithOption, StructWithSharedSumAndVariant, StructWithString, StructWithStruct, StructWithSum, SumWithBoxedVariants, SumWithVariants, VariantOne, VariantTwo }; - - #[test] - fn struct_singleton() { - let value = StructSingleton; - - assert_round_trip_encoding( - "StructSingleton", - value, - super::data::transient_0::encode_struct_singleton, - super::data::transient_0::decode_struct_singleton, - ); - } - - #[test] - fn struct_with_bool() { - let value = StructWithBool { a: true, b: false }; - - assert_round_trip_encoding( - "StructWithBool", - value, - super::data::transient_0::encode_struct_with_bool, - super::data::transient_0::decode_struct_with_bool, - ); - } - - #[test] - fn struct_with_int_8() { - let value = StructWithInt8 { a: 10, b: 25 }; - - assert_round_trip_encoding( - "StructWithInt8", - value, - super::data::transient_0::encode_struct_with_int_8, - super::data::transient_0::decode_struct_with_int_8, - ); - } - - #[test] - fn struct_with_int_32() { - let value = StructWithInt32 { a: 10, b: 25 }; - - assert_round_trip_encoding( - "StructWithInt32", - value, - super::data::transient_0::encode_struct_with_int_32, - super::data::transient_0::decode_struct_with_int_32, - ); - } - - #[test] - fn struct_with_int_64() { - let value = StructWithInt64 { a: 10, b: 25 }; - - assert_round_trip_encoding( - "StructWithInt64", - value, - super::data::transient_0::encode_struct_with_int_64, - super::data::transient_0::decode_struct_with_int_64, - ); - } - - #[test] - fn struct_with_string() { - let value = StructWithString { a: "abc".to_string(), b: "def".to_string() }; - - assert_round_trip_encoding( - "StructWithString", - value, - super::data::transient_0::encode_struct_with_string, - super::data::transient_0::decode_struct_with_string, - ); - } - - #[test] - fn struct_with_struct() { - let value = StructWithStruct { inner: StructWithInt32 { a: 10, b: 25 }, c: 42 }; - - assert_round_trip_encoding( - "StructWithStruct", - value, - super::data::transient_0::encode_struct_with_struct, - super::data::transient_0::decode_struct_with_struct, - ); - } - - #[test] - fn struct_with_list() { - let value = StructWithList { - a: vec![10, 25], - b: vec![ - StructWithInt32 { a: 42, b: 47 }, - StructWithInt32 { a: 52, b: 57 }, - StructWithInt32 { a: 62, b: 67 }, - ], - }; - - assert_round_trip_encoding( - "StructWithList", - value, - super::data::transient_0::encode_struct_with_list, - super::data::transient_0::decode_struct_with_list, - ); - } - - #[test] - fn struct_with_option_none() { - let value = StructWithOption { - a: None, - b: None, - }; - - assert_round_trip_encoding( - "StructWithOption_None", - value, - super::data::transient_0::encode_struct_with_option, - super::data::transient_0::decode_struct_with_option, - ); - } - - #[test] - fn struct_with_option_some() { - let value = StructWithOption { - a: Some(10), - b: Some(StructWithInt32 { a: 42, b: 47 }), - }; - - assert_round_trip_encoding( - "StructWithOption_Some", - value, - super::data::transient_0::encode_struct_with_option, - super::data::transient_0::decode_struct_with_option, - ); - } - - #[test] - fn enum_with_variants() { - assert_round_trip_encoding( - "EnumWithVariants_zero", - EnumWithVariants::Zero, - super::data::transient_0::encode_enum_with_variants, - super::data::transient_0::decode_enum_with_variants, - ); - - assert_round_trip_encoding( - "EnumWithVariants_one", - EnumWithVariants::One, - super::data::transient_0::encode_enum_with_variants, - super::data::transient_0::decode_enum_with_variants, - ); - - assert_round_trip_encoding( - "EnumWithVariants_two", - EnumWithVariants::Two, - super::data::transient_0::encode_enum_with_variants, - super::data::transient_0::decode_enum_with_variants, - ); - } - - #[test] - fn struct_with_enum() { - let value = StructWithEnum { inner: EnumWithVariants::One, c: 42 }; - - assert_round_trip_encoding( - "StructWithEnum", - value, - super::data::transient_0::encode_struct_with_enum, - super::data::transient_0::decode_struct_with_enum, - ); - } - - #[test] - fn sum_with_variants() { - assert_round_trip_encoding( - "SumWithVariants_VariantOne", - SumWithVariants::VariantOne(VariantOne { a: 10 }), - super::data::transient_0::encode_sum_with_variants, - super::data::transient_0::decode_sum_with_variants, - ); - - assert_round_trip_encoding( - "SumWithVariants_VariantTwo", - SumWithVariants::VariantTwo(VariantTwo { a: 25 }), - super::data::transient_0::encode_sum_with_variants, - super::data::transient_0::decode_sum_with_variants, - ); - } - - #[test] - fn sum_with_boxed_variants() { - assert_round_trip_encoding( - "SumWithBoxedVariants_VariantOne", - SumWithBoxedVariants::VariantOne(Box::new(VariantOne { a: 10 })), - super::data::transient_0::encode_sum_with_boxed_variants, - super::data::transient_0::decode_sum_with_boxed_variants, - ); - - assert_round_trip_encoding( - "SumWithBoxedVariants_VariantTwo", - SumWithBoxedVariants::VariantTwo(Box::new(VariantTwo { a: 25 })), - super::data::transient_0::encode_sum_with_boxed_variants, - super::data::transient_0::decode_sum_with_boxed_variants, - ); - } - - #[test] - fn struct_with_sum() { - let value = StructWithSum { - inner: SumWithVariants::VariantTwo(VariantTwo { a: 25 }), - b: 42, - }; - - assert_round_trip_encoding( - "StructWithSum", - value, - super::data::transient_0::encode_struct_with_sum, - super::data::transient_0::decode_struct_with_sum, - ); - } - - #[test] - fn struct_with_native() { - let value = StructWithNative { - a: Native { a: 10, b: 25 }, - }; - - assert_round_trip_encoding( - "StructWithNative", - value, - super::data::transient_0::encode_struct_with_native, - super::data::transient_0::decode_struct_with_native, - ); - } - - #[test] - fn struct_with_generic_native() { - let value = StructWithGenericNative { - a: GenericNative { a: 10, b: "x1".to_string() }, - b: GenericNative { - a: Some("x2".to_string()), - b: GenericNative { - a: Some("x3".to_string()), - b: GenericNative { a: "x4".to_string(), b: "x5".to_string() }, - }, - }, - }; - - assert_round_trip_encoding( - "StructWithGenericNative", - value, - super::data::transient_0::encode_struct_with_generic_native, - super::data::transient_0::decode_struct_with_generic_native, - ); - } - - #[test] - fn struct_with_box() { - let value = StructWithBox { - inner: Box::new(StructWithInt32 { a: 10, b: 25 }), - }; - - assert_round_trip_encoding( - "StructWithBox", - value, - super::data::transient_0::encode_struct_with_box, - super::data::transient_0::decode_struct_with_box, - ); - } - - #[test] - fn struct_with_list_of_shared() { - let a = Arc::new(StructWithInt32 { a: 10, b: 25 }); - let b = Arc::new(StructWithInt32 { a: 42, b: 47 }); - - let value = StructWithListOfShared { - inner: vec![Arc::clone(&a), Arc::clone(&a), Arc::clone(&b), a, b], - }; - - let decoded_value = assert_round_trip_encoding( - "StructWithListOfShared", - value, - super::data::transient_0::encode_struct_with_list_of_shared, - super::data::transient_0::decode_struct_with_list_of_shared, - ); - assert!(Arc::ptr_eq(&decoded_value.inner[0], &decoded_value.inner[1])); - assert!(Arc::ptr_eq(&decoded_value.inner[0], &decoded_value.inner[3])); - assert!(Arc::ptr_eq(&decoded_value.inner[2], &decoded_value.inner[4])); - } - - #[test] - fn struct_with_different_shared_types() { - let a = Arc::new(StructWithInt32 { a: 10, b: 25 }); - let b = Arc::new(StructWithInt64 { a: 42, b: 47 }); - let c = Arc::new(StructWithInt32 { a: 52, b: 57 }); - - let value = StructWithDifferentSharedTypes { a, b, c }; - - assert_round_trip_encoding( - "StructWithDifferentSharedTypes", - value, - super::data::transient_0::encode_struct_with_different_shared_types, - super::data::transient_0::decode_struct_with_different_shared_types, - ); - } - - #[test] - fn struct_with_shared_sum_and_variant() { - let a = Arc::new(SumWithVariants::VariantOne(VariantOne { a: 10 })); - let b = Arc::new(VariantOne { a: 10 }); - - let value = StructWithSharedSumAndVariant { a, b }; - - assert_round_trip_encoding( - "StructWithSharedSumAndVariant", - value, - super::data::transient_0::encode_struct_with_shared_sum_and_variant, - super::data::transient_0::decode_struct_with_shared_sum_and_variant, - ); - } - - fn assert_round_trip_encoding<T: std::cmp::PartialEq + std::fmt::Debug>( - name: &str, - value: T, - encode: impl Fn(&T, &mut Cursor<Vec<u8>>, &mut HashMap<usize, i64>) -> std::io::Result<()>, - decode: impl Fn(&mut Cursor<Vec<u8>>, &mut Vec<Arc<dyn Any + Sync + Send>>) -> std::io::Result<T>, - ) -> T { - let mut bytes = Cursor::new(Vec::new()); - encode(&value, &mut bytes, &mut HashMap::new()).unwrap(); - - let output_dir = std::env::var("HOBGOBLIN_OUTPUT_DIR").unwrap(); - let transient_0_output_dir = PathBuf::from(output_dir).join("transient-0"); - std::fs::create_dir_all(&transient_0_output_dir).unwrap(); - let transient_0_output_path = transient_0_output_dir.join(name); - std::fs::write(transient_0_output_path, bytes.get_ref()).unwrap(); - - bytes.set_position(0); - let decoded_value = decode(&mut bytes, &mut Vec::new()).unwrap(); - - assert_eq!(value, decoded_value); - - decoded_value - } -} diff --git a/examples/15-transient-0/output/rust/src/transient_0.rs b/examples/15-transient-0/output/rust/src/transient_0.rs deleted file mode 100644 index 8b2b800..0000000 --- a/examples/15-transient-0/output/rust/src/transient_0.rs +++ /dev/null @@ -1 +0,0 @@ -include!("./gen/transient_0.rs"); diff --git a/examples/15-transient-0/src/data.hob b/examples/15-transient-0/src/data.hob deleted file mode 100644 index df96916..0000000 --- a/examples/15-transient-0/src/data.hob +++ /dev/null @@ -1,111 +0,0 @@ -struct StructSingleton { - singleton; -} - -struct StructWithBool { - field a: Bool; - field b: Bool; -} - -struct StructWithInt8 { - field a: Int8; - field b: Int8; -} - -struct StructWithInt32 { - field a: Int32; - field b: Int32; -} - -struct StructWithInt64 { - field a: Int64; - field b: Int64; -} - -struct StructWithString { - field a: String; - field b: String; -} - -struct StructWithStruct { - field inner: StructWithInt32; - field c: Int32; -} - -struct StructWithList { - field a: List[Int64]; - field b: List[StructWithInt32]; -} - -struct StructWithOption { - field a: Option[Int64]; - field b: Option[StructWithInt32]; -} - -enum EnumWithVariants { - variant zero; - variant one; - variant two; -} - -struct StructWithEnum { - field inner: EnumWithVariants; - field c: Int32; -} - -sum SumWithVariants { - variant VariantOne; - variant VariantTwo; -} - -struct VariantOne { - field a: Int32; -} - -struct VariantTwo { - field a: Int64; -} - -sum SumWithBoxedVariants { - variant Box[VariantOne]; - variant Box[VariantTwo]; -} - -struct StructWithSum { - field inner: SumWithVariants; - field b: Int32; -} - -native Native { -} - -struct StructWithNative { - field a: Native; -} - -native GenericNative[A, B] { -} - -struct StructWithGenericNative { - field a: GenericNative[Int32, String]; - field b: GenericNative[Option[String], GenericNative[Option[String], GenericNative[String, String]]]; -} - -struct StructWithBox { - field inner: Box[StructWithInt32]; -} - -struct StructWithListOfShared { - field inner: List[Shared[StructWithInt32]]; -} - -struct StructWithDifferentSharedTypes { - field a: Shared[StructWithInt32]; - field b: Shared[StructWithInt64]; - field c: Shared[StructWithInt32]; -} - -struct StructWithSharedSumAndVariant { - field a: Shared[SumWithVariants]; - field b: Shared[VariantOne]; -} |
