From 84a97b8f7a29369b55ae1d3d1c776592bb03924c Mon Sep 17 00:00:00 2001 From: Jun Luo <4catcode@gmail.com> Date: Fri, 6 Feb 2026 16:52:47 +0800 Subject: [PATCH] Remove Python and Java legacy generators These generators have been migrated to dedicated repositories: - Python: https://github.com/StellarCN/py-stellar-base - Java: https://github.com/lightsail-network/java-stellar-sdk --- README.md | 2 - lib/xdrgen/generators.rb | 2 - lib/xdrgen/generators/java.rb | 657 ----------------- .../generators/java/XdrDataInputStream.erb | 122 --- .../generators/java/XdrDataOutputStream.erb | 96 --- lib/xdrgen/generators/java/XdrElement.erb | 21 - lib/xdrgen/generators/java/XdrString.erb | 62 -- .../java/XdrUnsignedHyperInteger.erb | 69 -- .../generators/java/XdrUnsignedInteger.erb | 57 -- lib/xdrgen/generators/python.rb | 695 ------------------ lib/xdrgen/generators/python/base.py | 252 ------- spec/lib/xdrgen/generator_spec.rb | 2 +- .../block_comments.x/AccountFlags.java | 56 -- .../block_comments.x/Constants.java | 10 - .../block_comments.x/XdrDataInputStream.java | 122 --- .../block_comments.x/XdrDataOutputStream.java | 96 --- .../block_comments.x/XdrElement.java | 21 - .../block_comments.x/XdrString.java | 62 -- .../XdrUnsignedHyperInteger.java | 69 -- .../block_comments.x/XdrUnsignedInteger.java | 57 -- .../const.x/Constants.java | 11 - .../const.x/TestArray.java | 53 -- .../const.x/TestArray2.java | 54 -- .../const.x/XdrDataInputStream.java | 122 --- .../const.x/XdrDataOutputStream.java | 96 --- .../const.x/XdrElement.java | 21 - .../const.x/XdrString.java | 62 -- .../const.x/XdrUnsignedHyperInteger.java | 69 -- .../const.x/XdrUnsignedInteger.java | 57 -- .../generator_spec_java/enum.x/Color.java | 61 -- .../generator_spec_java/enum.x/Color2.java | 61 -- .../generator_spec_java/enum.x/Color3.java | 61 -- .../generator_spec_java/enum.x/Constants.java | 10 - .../enum.x/MessageType.java | 101 --- .../enum.x/XdrDataInputStream.java | 122 --- .../enum.x/XdrDataOutputStream.java | 96 --- .../enum.x/XdrElement.java | 21 - .../generator_spec_java/enum.x/XdrString.java | 62 -- .../enum.x/XdrUnsignedHyperInteger.java | 69 -- .../enum.x/XdrUnsignedInteger.java | 57 -- .../nesting.x/Constants.java | 10 - .../generator_spec_java/nesting.x/Foo.java | 46 -- .../nesting.x/MyUnion.java | 158 ---- .../nesting.x/UnionKey.java | 61 -- .../nesting.x/XdrDataInputStream.java | 122 --- .../nesting.x/XdrDataOutputStream.java | 96 --- .../nesting.x/XdrElement.java | 21 - .../nesting.x/XdrString.java | 62 -- .../nesting.x/XdrUnsignedHyperInteger.java | 69 -- .../nesting.x/XdrUnsignedInteger.java | 57 -- .../generator_spec_java/optional.x/Arr.java | 53 -- .../optional.x/Constants.java | 10 - .../optional.x/HasOptions.java | 81 -- .../optional.x/XdrDataInputStream.java | 122 --- .../optional.x/XdrDataOutputStream.java | 96 --- .../optional.x/XdrElement.java | 21 - .../optional.x/XdrString.java | 62 -- .../optional.x/XdrUnsignedHyperInteger.java | 69 -- .../optional.x/XdrUnsignedInteger.java | 57 -- .../struct.x/Constants.java | 10 - .../generator_spec_java/struct.x/Int64.java | 46 -- .../struct.x/MyStruct.java | 68 -- .../struct.x/XdrDataInputStream.java | 122 --- .../struct.x/XdrDataOutputStream.java | 96 --- .../struct.x/XdrElement.java | 21 - .../struct.x/XdrString.java | 62 -- .../struct.x/XdrUnsignedHyperInteger.java | 69 -- .../struct.x/XdrUnsignedInteger.java | 57 -- .../generator_spec_java/test.x/Color.java | 61 -- .../generator_spec_java/test.x/Constants.java | 12 - .../generator_spec_java/test.x/HasStuff.java | 49 -- .../generator_spec_java/test.x/Hash.java | 49 -- .../generator_spec_java/test.x/Hashes1.java | 53 -- .../generator_spec_java/test.x/Hashes2.java | 54 -- .../generator_spec_java/test.x/Hashes3.java | 54 -- .../generator_spec_java/test.x/Int1.java | 46 -- .../generator_spec_java/test.x/Int2.java | 46 -- .../generator_spec_java/test.x/Int3.java | 46 -- .../generator_spec_java/test.x/Int4.java | 46 -- .../test.x/LotsOfMyStructs.java | 57 -- .../generator_spec_java/test.x/MyStruct.java | 73 -- .../generator_spec_java/test.x/Nester.java | 208 ------ .../generator_spec_java/test.x/OptHash1.java | 54 -- .../generator_spec_java/test.x/OptHash2.java | 54 -- .../generator_spec_java/test.x/Str.java | 46 -- .../generator_spec_java/test.x/Str2.java | 46 -- .../generator_spec_java/test.x/Uint512.java | 49 -- .../generator_spec_java/test.x/Uint513.java | 50 -- .../generator_spec_java/test.x/Uint514.java | 50 -- .../test.x/XdrDataInputStream.java | 122 --- .../test.x/XdrDataOutputStream.java | 96 --- .../test.x/XdrElement.java | 21 - .../generator_spec_java/test.x/XdrString.java | 62 -- .../test.x/XdrUnsignedHyperInteger.java | 69 -- .../test.x/XdrUnsignedInteger.java | 57 -- .../union.x/Constants.java | 10 - .../generator_spec_java/union.x/Error.java | 46 -- .../generator_spec_java/union.x/IntUnion.java | 81 -- .../union.x/IntUnion2.java | 46 -- .../generator_spec_java/union.x/Multi.java | 46 -- .../generator_spec_java/union.x/MyUnion.java | 82 --- .../generator_spec_java/union.x/UnionKey.java | 58 -- .../union.x/XdrDataInputStream.java | 122 --- .../union.x/XdrDataOutputStream.java | 96 --- .../union.x/XdrElement.java | 21 - .../union.x/XdrString.java | 62 -- .../union.x/XdrUnsignedHyperInteger.java | 69 -- .../union.x/XdrUnsignedInteger.java | 57 -- .../block_comments.x/__init__.py | 5 - .../block_comments.x/account_flags.py | 47 -- .../block_comments.x/base.py | 252 ------- .../block_comments.x/constants.py | 2 - .../generator_spec_python/const.x/__init__.py | 6 - .../generator_spec_python/const.x/base.py | 252 ------- .../const.x/constants.py | 4 - .../const.x/test_array.py | 60 -- .../const.x/test_array2.py | 61 -- .../generator_spec_python/enum.x/__init__.py | 8 - .../generator_spec_python/enum.x/base.py | 252 ------- .../generator_spec_python/enum.x/color.py | 50 -- .../generator_spec_python/enum.x/color2.py | 50 -- .../generator_spec_python/enum.x/color3.py | 50 -- .../generator_spec_python/enum.x/constants.py | 2 - .../enum.x/message_type.py | 79 -- .../nesting.x/__init__.py | 9 - .../generator_spec_python/nesting.x/base.py | 252 ------- .../nesting.x/constants.py | 2 - .../generator_spec_python/nesting.x/foo.py | 53 -- .../nesting.x/my_union.py | 101 --- .../nesting.x/my_union_one.py | 62 -- .../nesting.x/my_union_two.py | 70 -- .../nesting.x/union_key.py | 50 -- .../optional.x/__init__.py | 6 - .../generator_spec_python/optional.x/arr.py | 60 -- .../generator_spec_python/optional.x/base.py | 252 ------- .../optional.x/constants.py | 2 - .../optional.x/has_options.py | 90 --- .../struct.x/__init__.py | 6 - .../generator_spec_python/struct.x/base.py | 252 ------- .../struct.x/constants.py | 2 - .../generator_spec_python/struct.x/int64.py | 53 -- .../struct.x/my_struct.py | 92 --- .../generator_spec_python/test.x/__init__.py | 27 - .../generator_spec_python/test.x/base.py | 252 ------- .../generator_spec_python/test.x/color.py | 50 -- .../generator_spec_python/test.x/constants.py | 6 - .../generator_spec_python/test.x/has_stuff.py | 64 -- .../generator_spec_python/test.x/hash.py | 53 -- .../generator_spec_python/test.x/hashes1.py | 61 -- .../generator_spec_python/test.x/hashes2.py | 62 -- .../generator_spec_python/test.x/hashes3.py | 62 -- .../generator_spec_python/test.x/int1.py | 53 -- .../generator_spec_python/test.x/int2.py | 53 -- .../generator_spec_python/test.x/int3.py | 53 -- .../generator_spec_python/test.x/int4.py | 53 -- .../test.x/lots_of_my_structs.py | 72 -- .../generator_spec_python/test.x/my_struct.py | 108 --- .../generator_spec_python/test.x/nester.py | 94 --- .../test.x/nester_nested_enum.py | 48 -- .../test.x/nester_nested_struct.py | 62 -- .../test.x/nester_nested_union.py | 74 -- .../generator_spec_python/test.x/opt_hash1.py | 58 -- .../generator_spec_python/test.x/opt_hash2.py | 58 -- .../generator_spec_python/test.x/str.py | 53 -- .../generator_spec_python/test.x/str2.py | 53 -- .../generator_spec_python/test.x/uint512.py | 53 -- .../generator_spec_python/test.x/uint513.py | 53 -- .../generator_spec_python/test.x/uint514.py | 53 -- .../generator_spec_python/union.x/__init__.py | 10 - .../generator_spec_python/union.x/base.py | 252 ------- .../union.x/constants.py | 2 - .../generator_spec_python/union.x/error.py | 53 -- .../union.x/int_union.py | 96 --- .../union.x/int_union2.py | 54 -- .../generator_spec_python/union.x/multi.py | 53 -- .../generator_spec_python/union.x/my_union.py | 98 --- .../union.x/union_key.py | 48 -- 177 files changed, 1 insertion(+), 12993 deletions(-) delete mode 100644 lib/xdrgen/generators/java.rb delete mode 100644 lib/xdrgen/generators/java/XdrDataInputStream.erb delete mode 100644 lib/xdrgen/generators/java/XdrDataOutputStream.erb delete mode 100644 lib/xdrgen/generators/java/XdrElement.erb delete mode 100644 lib/xdrgen/generators/java/XdrString.erb delete mode 100644 lib/xdrgen/generators/java/XdrUnsignedHyperInteger.erb delete mode 100644 lib/xdrgen/generators/java/XdrUnsignedInteger.erb delete mode 100644 lib/xdrgen/generators/python.rb delete mode 100644 lib/xdrgen/generators/python/base.py delete mode 100644 spec/output/generator_spec_java/block_comments.x/AccountFlags.java delete mode 100644 spec/output/generator_spec_java/block_comments.x/Constants.java delete mode 100644 spec/output/generator_spec_java/block_comments.x/XdrDataInputStream.java delete mode 100644 spec/output/generator_spec_java/block_comments.x/XdrDataOutputStream.java delete mode 100644 spec/output/generator_spec_java/block_comments.x/XdrElement.java delete mode 100644 spec/output/generator_spec_java/block_comments.x/XdrString.java delete mode 100644 spec/output/generator_spec_java/block_comments.x/XdrUnsignedHyperInteger.java delete mode 100644 spec/output/generator_spec_java/block_comments.x/XdrUnsignedInteger.java delete mode 100644 spec/output/generator_spec_java/const.x/Constants.java delete mode 100644 spec/output/generator_spec_java/const.x/TestArray.java delete mode 100644 spec/output/generator_spec_java/const.x/TestArray2.java delete mode 100644 spec/output/generator_spec_java/const.x/XdrDataInputStream.java delete mode 100644 spec/output/generator_spec_java/const.x/XdrDataOutputStream.java delete mode 100644 spec/output/generator_spec_java/const.x/XdrElement.java delete mode 100644 spec/output/generator_spec_java/const.x/XdrString.java delete mode 100644 spec/output/generator_spec_java/const.x/XdrUnsignedHyperInteger.java delete mode 100644 spec/output/generator_spec_java/const.x/XdrUnsignedInteger.java delete mode 100644 spec/output/generator_spec_java/enum.x/Color.java delete mode 100644 spec/output/generator_spec_java/enum.x/Color2.java delete mode 100644 spec/output/generator_spec_java/enum.x/Color3.java delete mode 100644 spec/output/generator_spec_java/enum.x/Constants.java delete mode 100644 spec/output/generator_spec_java/enum.x/MessageType.java delete mode 100644 spec/output/generator_spec_java/enum.x/XdrDataInputStream.java delete mode 100644 spec/output/generator_spec_java/enum.x/XdrDataOutputStream.java delete mode 100644 spec/output/generator_spec_java/enum.x/XdrElement.java delete mode 100644 spec/output/generator_spec_java/enum.x/XdrString.java delete mode 100644 spec/output/generator_spec_java/enum.x/XdrUnsignedHyperInteger.java delete mode 100644 spec/output/generator_spec_java/enum.x/XdrUnsignedInteger.java delete mode 100644 spec/output/generator_spec_java/nesting.x/Constants.java delete mode 100644 spec/output/generator_spec_java/nesting.x/Foo.java delete mode 100644 spec/output/generator_spec_java/nesting.x/MyUnion.java delete mode 100644 spec/output/generator_spec_java/nesting.x/UnionKey.java delete mode 100644 spec/output/generator_spec_java/nesting.x/XdrDataInputStream.java delete mode 100644 spec/output/generator_spec_java/nesting.x/XdrDataOutputStream.java delete mode 100644 spec/output/generator_spec_java/nesting.x/XdrElement.java delete mode 100644 spec/output/generator_spec_java/nesting.x/XdrString.java delete mode 100644 spec/output/generator_spec_java/nesting.x/XdrUnsignedHyperInteger.java delete mode 100644 spec/output/generator_spec_java/nesting.x/XdrUnsignedInteger.java delete mode 100644 spec/output/generator_spec_java/optional.x/Arr.java delete mode 100644 spec/output/generator_spec_java/optional.x/Constants.java delete mode 100644 spec/output/generator_spec_java/optional.x/HasOptions.java delete mode 100644 spec/output/generator_spec_java/optional.x/XdrDataInputStream.java delete mode 100644 spec/output/generator_spec_java/optional.x/XdrDataOutputStream.java delete mode 100644 spec/output/generator_spec_java/optional.x/XdrElement.java delete mode 100644 spec/output/generator_spec_java/optional.x/XdrString.java delete mode 100644 spec/output/generator_spec_java/optional.x/XdrUnsignedHyperInteger.java delete mode 100644 spec/output/generator_spec_java/optional.x/XdrUnsignedInteger.java delete mode 100644 spec/output/generator_spec_java/struct.x/Constants.java delete mode 100644 spec/output/generator_spec_java/struct.x/Int64.java delete mode 100644 spec/output/generator_spec_java/struct.x/MyStruct.java delete mode 100644 spec/output/generator_spec_java/struct.x/XdrDataInputStream.java delete mode 100644 spec/output/generator_spec_java/struct.x/XdrDataOutputStream.java delete mode 100644 spec/output/generator_spec_java/struct.x/XdrElement.java delete mode 100644 spec/output/generator_spec_java/struct.x/XdrString.java delete mode 100644 spec/output/generator_spec_java/struct.x/XdrUnsignedHyperInteger.java delete mode 100644 spec/output/generator_spec_java/struct.x/XdrUnsignedInteger.java delete mode 100644 spec/output/generator_spec_java/test.x/Color.java delete mode 100644 spec/output/generator_spec_java/test.x/Constants.java delete mode 100644 spec/output/generator_spec_java/test.x/HasStuff.java delete mode 100644 spec/output/generator_spec_java/test.x/Hash.java delete mode 100644 spec/output/generator_spec_java/test.x/Hashes1.java delete mode 100644 spec/output/generator_spec_java/test.x/Hashes2.java delete mode 100644 spec/output/generator_spec_java/test.x/Hashes3.java delete mode 100644 spec/output/generator_spec_java/test.x/Int1.java delete mode 100644 spec/output/generator_spec_java/test.x/Int2.java delete mode 100644 spec/output/generator_spec_java/test.x/Int3.java delete mode 100644 spec/output/generator_spec_java/test.x/Int4.java delete mode 100644 spec/output/generator_spec_java/test.x/LotsOfMyStructs.java delete mode 100644 spec/output/generator_spec_java/test.x/MyStruct.java delete mode 100644 spec/output/generator_spec_java/test.x/Nester.java delete mode 100644 spec/output/generator_spec_java/test.x/OptHash1.java delete mode 100644 spec/output/generator_spec_java/test.x/OptHash2.java delete mode 100644 spec/output/generator_spec_java/test.x/Str.java delete mode 100644 spec/output/generator_spec_java/test.x/Str2.java delete mode 100644 spec/output/generator_spec_java/test.x/Uint512.java delete mode 100644 spec/output/generator_spec_java/test.x/Uint513.java delete mode 100644 spec/output/generator_spec_java/test.x/Uint514.java delete mode 100644 spec/output/generator_spec_java/test.x/XdrDataInputStream.java delete mode 100644 spec/output/generator_spec_java/test.x/XdrDataOutputStream.java delete mode 100644 spec/output/generator_spec_java/test.x/XdrElement.java delete mode 100644 spec/output/generator_spec_java/test.x/XdrString.java delete mode 100644 spec/output/generator_spec_java/test.x/XdrUnsignedHyperInteger.java delete mode 100644 spec/output/generator_spec_java/test.x/XdrUnsignedInteger.java delete mode 100644 spec/output/generator_spec_java/union.x/Constants.java delete mode 100644 spec/output/generator_spec_java/union.x/Error.java delete mode 100644 spec/output/generator_spec_java/union.x/IntUnion.java delete mode 100644 spec/output/generator_spec_java/union.x/IntUnion2.java delete mode 100644 spec/output/generator_spec_java/union.x/Multi.java delete mode 100644 spec/output/generator_spec_java/union.x/MyUnion.java delete mode 100644 spec/output/generator_spec_java/union.x/UnionKey.java delete mode 100644 spec/output/generator_spec_java/union.x/XdrDataInputStream.java delete mode 100644 spec/output/generator_spec_java/union.x/XdrDataOutputStream.java delete mode 100644 spec/output/generator_spec_java/union.x/XdrElement.java delete mode 100644 spec/output/generator_spec_java/union.x/XdrString.java delete mode 100644 spec/output/generator_spec_java/union.x/XdrUnsignedHyperInteger.java delete mode 100644 spec/output/generator_spec_java/union.x/XdrUnsignedInteger.java delete mode 100644 spec/output/generator_spec_python/block_comments.x/__init__.py delete mode 100644 spec/output/generator_spec_python/block_comments.x/account_flags.py delete mode 100644 spec/output/generator_spec_python/block_comments.x/base.py delete mode 100644 spec/output/generator_spec_python/block_comments.x/constants.py delete mode 100644 spec/output/generator_spec_python/const.x/__init__.py delete mode 100644 spec/output/generator_spec_python/const.x/base.py delete mode 100644 spec/output/generator_spec_python/const.x/constants.py delete mode 100644 spec/output/generator_spec_python/const.x/test_array.py delete mode 100644 spec/output/generator_spec_python/const.x/test_array2.py delete mode 100644 spec/output/generator_spec_python/enum.x/__init__.py delete mode 100644 spec/output/generator_spec_python/enum.x/base.py delete mode 100644 spec/output/generator_spec_python/enum.x/color.py delete mode 100644 spec/output/generator_spec_python/enum.x/color2.py delete mode 100644 spec/output/generator_spec_python/enum.x/color3.py delete mode 100644 spec/output/generator_spec_python/enum.x/constants.py delete mode 100644 spec/output/generator_spec_python/enum.x/message_type.py delete mode 100644 spec/output/generator_spec_python/nesting.x/__init__.py delete mode 100644 spec/output/generator_spec_python/nesting.x/base.py delete mode 100644 spec/output/generator_spec_python/nesting.x/constants.py delete mode 100644 spec/output/generator_spec_python/nesting.x/foo.py delete mode 100644 spec/output/generator_spec_python/nesting.x/my_union.py delete mode 100644 spec/output/generator_spec_python/nesting.x/my_union_one.py delete mode 100644 spec/output/generator_spec_python/nesting.x/my_union_two.py delete mode 100644 spec/output/generator_spec_python/nesting.x/union_key.py delete mode 100644 spec/output/generator_spec_python/optional.x/__init__.py delete mode 100644 spec/output/generator_spec_python/optional.x/arr.py delete mode 100644 spec/output/generator_spec_python/optional.x/base.py delete mode 100644 spec/output/generator_spec_python/optional.x/constants.py delete mode 100644 spec/output/generator_spec_python/optional.x/has_options.py delete mode 100644 spec/output/generator_spec_python/struct.x/__init__.py delete mode 100644 spec/output/generator_spec_python/struct.x/base.py delete mode 100644 spec/output/generator_spec_python/struct.x/constants.py delete mode 100644 spec/output/generator_spec_python/struct.x/int64.py delete mode 100644 spec/output/generator_spec_python/struct.x/my_struct.py delete mode 100644 spec/output/generator_spec_python/test.x/__init__.py delete mode 100644 spec/output/generator_spec_python/test.x/base.py delete mode 100644 spec/output/generator_spec_python/test.x/color.py delete mode 100644 spec/output/generator_spec_python/test.x/constants.py delete mode 100644 spec/output/generator_spec_python/test.x/has_stuff.py delete mode 100644 spec/output/generator_spec_python/test.x/hash.py delete mode 100644 spec/output/generator_spec_python/test.x/hashes1.py delete mode 100644 spec/output/generator_spec_python/test.x/hashes2.py delete mode 100644 spec/output/generator_spec_python/test.x/hashes3.py delete mode 100644 spec/output/generator_spec_python/test.x/int1.py delete mode 100644 spec/output/generator_spec_python/test.x/int2.py delete mode 100644 spec/output/generator_spec_python/test.x/int3.py delete mode 100644 spec/output/generator_spec_python/test.x/int4.py delete mode 100644 spec/output/generator_spec_python/test.x/lots_of_my_structs.py delete mode 100644 spec/output/generator_spec_python/test.x/my_struct.py delete mode 100644 spec/output/generator_spec_python/test.x/nester.py delete mode 100644 spec/output/generator_spec_python/test.x/nester_nested_enum.py delete mode 100644 spec/output/generator_spec_python/test.x/nester_nested_struct.py delete mode 100644 spec/output/generator_spec_python/test.x/nester_nested_union.py delete mode 100644 spec/output/generator_spec_python/test.x/opt_hash1.py delete mode 100644 spec/output/generator_spec_python/test.x/opt_hash2.py delete mode 100644 spec/output/generator_spec_python/test.x/str.py delete mode 100644 spec/output/generator_spec_python/test.x/str2.py delete mode 100644 spec/output/generator_spec_python/test.x/uint512.py delete mode 100644 spec/output/generator_spec_python/test.x/uint513.py delete mode 100644 spec/output/generator_spec_python/test.x/uint514.py delete mode 100644 spec/output/generator_spec_python/union.x/__init__.py delete mode 100644 spec/output/generator_spec_python/union.x/base.py delete mode 100644 spec/output/generator_spec_python/union.x/constants.py delete mode 100644 spec/output/generator_spec_python/union.x/error.py delete mode 100644 spec/output/generator_spec_python/union.x/int_union.py delete mode 100644 spec/output/generator_spec_python/union.x/int_union2.py delete mode 100644 spec/output/generator_spec_python/union.x/multi.py delete mode 100644 spec/output/generator_spec_python/union.x/my_union.py delete mode 100644 spec/output/generator_spec_python/union.x/union_key.py diff --git a/README.md b/README.md index 8901ec72e..1cd3266b8 100644 --- a/README.md +++ b/README.md @@ -72,12 +72,10 @@ are not maintained, not tested, and are preserved for legacy usage. - ruby: complete support - javascript: complete support -- java: complete support - golang: currently using a fork of go-xdr, but has complete support - elixir: support is experimental as the SDK is in early development. Generated code requires [:exdr](https://github.com/revelrylabs/exdr) in your deps - C#: complete support -- Python: complete support ## Contributing new generators / languages diff --git a/lib/xdrgen/generators.rb b/lib/xdrgen/generators.rb index dacfa7f3c..53ef67c24 100644 --- a/lib/xdrgen/generators.rb +++ b/lib/xdrgen/generators.rb @@ -5,10 +5,8 @@ module Xdrgen::Generators autoload :Ruby autoload :Go autoload :Javascript - autoload :Java autoload :Elixir autoload :Csharp - autoload :Python def self.for_language(language) const_get language.to_s.classify diff --git a/lib/xdrgen/generators/java.rb b/lib/xdrgen/generators/java.rb deleted file mode 100644 index 40ecd0cec..000000000 --- a/lib/xdrgen/generators/java.rb +++ /dev/null @@ -1,657 +0,0 @@ -require 'set' - -module Xdrgen - module Generators - class Java < Xdrgen::Generators::Base - - def generate - constants_container = Set[] - render_lib - render_definitions(@top, constants_container) - render_constants constants_container - end - - def render_lib - template = IO.read(__dir__ + "/java/XdrDataInputStream.erb") - result = ERB.new(template).result binding - @output.write "XdrDataInputStream.java", result - - template = IO.read(__dir__ + "/java/XdrDataOutputStream.erb") - result = ERB.new(template).result binding - @output.write "XdrDataOutputStream.java", result - - template = IO.read(__dir__ + "/java/XdrElement.erb") - result = ERB.new(template).result binding - @output.write "XdrElement.java", result - - template = IO.read(__dir__ + "/java/XdrString.erb") - result = ERB.new(template).result binding - @output.write "XdrString.java", result - - template = IO.read(__dir__ + "/java/XdrUnsignedHyperInteger.erb") - result = ERB.new(template).result binding - @output.write "XdrUnsignedHyperInteger.java", result - - template = IO.read(__dir__ + "/java/XdrUnsignedInteger.erb") - result = ERB.new(template).result binding - @output.write "XdrUnsignedInteger.java", result - end - - def render_definitions(node, constants_container) - node.namespaces.each{|n| render_definitions n, constants_container } - node.definitions.each { |defn| render_definition(defn, constants_container) } - end - - def add_imports_for_definition(defn, imports) - imports.add("org.stellar.sdk.Base64Factory") - imports.add("java.io.ByteArrayInputStream") - imports.add("java.io.ByteArrayOutputStream") - - case defn - when AST::Definitions::Struct, AST::Definitions::Union - imports.add("lombok.Data") - imports.add("lombok.NoArgsConstructor") - imports.add("lombok.AllArgsConstructor") - imports.add("lombok.Builder") - when AST::Definitions::Typedef - imports.add("lombok.Data") - imports.add("lombok.NoArgsConstructor") - imports.add("lombok.AllArgsConstructor") - end - - if defn.respond_to? :nested_definitions - defn.nested_definitions.each{ |child_defn| add_imports_for_definition(child_defn, imports) } - end - end - - def render_definition(defn, constants_container) - imports = Set[] - add_imports_for_definition(defn, imports) - - case defn - when AST::Definitions::Struct ; - render_element defn, imports, defn do |out| - render_struct defn, out - render_nested_definitions defn, out - end - when AST::Definitions::Enum ; - render_element defn, imports, defn do |out| - render_enum defn, out - end - when AST::Definitions::Union ; - render_element defn, imports, defn do |out| - render_union defn, out - render_nested_definitions defn, out - end - when AST::Definitions::Typedef ; - render_element defn, imports, defn do |out| - render_typedef defn, out - end - when AST::Definitions::Const ; - const_name = defn.name - const_value = defn.value - constants_container.add([const_name, const_value]) - end - end - - def render_nested_definitions(defn, out, post_name="implements XdrElement") - return unless defn.respond_to? :nested_definitions - defn.nested_definitions.each{|ndefn| - render_source_comment out, ndefn - case ndefn - when AST::Definitions::Struct ; - name = name ndefn - out.puts "@Data" - out.puts "@NoArgsConstructor" - out.puts "@AllArgsConstructor" - out.puts "@Builder(toBuilder = true)" - out.puts "public static class #{name} #{post_name} {" - out.indent do - render_struct ndefn, out - render_nested_definitions ndefn , out - end - out.puts "}" - when AST::Definitions::Enum ; - name = name ndefn - out.puts "public static enum #{name} #{post_name} {" - out.indent do - render_enum ndefn, out - end - out.puts "}" - when AST::Definitions::Union ; - name = name ndefn - out.puts "@Data" - out.puts "@NoArgsConstructor" - out.puts "@AllArgsConstructor" - out.puts "@Builder(toBuilder = true)" - out.puts "public static class #{name} #{post_name} {" - out.indent do - render_union ndefn, out - render_nested_definitions ndefn, out - end - out.puts "}" - when AST::Definitions::Typedef ; - name = name ndefn - out.puts "@Data" - out.puts "@NoArgsConstructor" - out.puts "@AllArgsConstructor" - out.puts "public static class #{name} #{post_name} {" - out.indent do - render_typedef ndefn, out - end - out.puts "}" - end - } - end - - def render_element(defn, imports, element, post_name="implements XdrElement") - path = element.name.camelize + ".java" - name = name_string element.name - out = @output.open(path) - render_top_matter out - imports.each do |import| - out.puts "import #{import};" - end - out.puts "\n" - render_source_comment out, element - case defn - when AST::Definitions::Struct, AST::Definitions::Union - out.puts "@Data" - out.puts "@NoArgsConstructor" - out.puts "@AllArgsConstructor" - out.puts "@Builder(toBuilder = true)" - out.puts "public class #{name} #{post_name} {" - when AST::Definitions::Enum - out.puts "public enum #{name} #{post_name} {" - when AST::Definitions::Typedef - out.puts "@Data" - out.puts "@NoArgsConstructor" - out.puts "@AllArgsConstructor" - out.puts "public class #{name} #{post_name} {" - end - out.indent do - yield out - out.unbreak - end - out.puts "}" - end - - def render_constants(constants_container) - out = @output.open("Constants.java") - render_top_matter out - out.puts "public final class Constants {" - out.indent do - out.puts "private Constants() {}" - constants_container.each do |const_name, const_value| - out.puts "public static final int #{const_name} = #{const_value};" - end - end - out.puts "}" - end - - def render_enum(enum, out) - out.balance_after /,[\s]*/ do - enum.members.each_with_index do |em, index| - out.puts "#{em.name}(#{em.value})#{index == enum.members.size - 1 ? ';' : ','}" - end - end - out.break - out.puts <<-EOS.strip_heredoc - private final int value; - - #{name_string enum.name}(int value) { - this.value = value; - } - - public int getValue() { - return value; - } - - public static #{name_string enum.name} decode(XdrDataInputStream stream) throws IOException { - int value = stream.readInt(); - switch (value) { - EOS - out.indent 2 do - enum.members.each do |em| - out.puts "case #{em.value}: return #{em.name};" - end - end - out.puts <<-EOS.strip_heredoc - default: - throw new IllegalArgumentException("Unknown enum value: " + value); - } - } - - public void encode(XdrDataOutputStream stream) throws IOException { - stream.writeInt(value); - } - EOS - render_base64((name_string enum.name), out) - out.break - end - - def render_struct(struct, out) - struct.members.each do |m| - out.puts "private #{decl_string(m.declaration)} #{m.name};" - end - - out.puts "public void encode(XdrDataOutputStream stream) throws IOException{" - struct.members.each do |m| - out.indent do - encode_member m, out - end - end - out.puts "}" - - out.puts <<-EOS.strip_heredoc - public static #{name struct} decode(XdrDataInputStream stream) throws IOException { - #{name struct} decoded#{name struct} = new #{name struct}(); - EOS - struct.members.each do |m| - out.indent do - decode_member "decoded#{name struct}", m, out - end - end - out.indent do - out.puts "return decoded#{name struct};" - end - out.puts "}" - - render_base64((name struct), out) - out.break - end - - def render_typedef(typedef, out) - out.puts "private #{decl_string typedef.declaration} #{typedef.name};" - out.puts "public void encode(XdrDataOutputStream stream) throws IOException {" - out.indent do - encode_member typedef, out - end - out.puts "}" - out.break - - out.puts <<-EOS.strip_heredoc - public static #{name typedef} decode(XdrDataInputStream stream) throws IOException { - #{name typedef} decoded#{name typedef} = new #{name typedef}(); - EOS - out.indent do - decode_member "decoded#{name typedef}", typedef, out - out.puts "return decoded#{name typedef};" - end - out.puts "}" - out.break - render_base64(typedef.name.camelize, out) - end - - def render_union(union, out) - out.puts "private #{type_string union.discriminant.type} discriminant;" - union.arms.each do |arm| - next if arm.void? - out.puts "private #{decl_string(arm.declaration)} #{arm.name};" - end - out.break - - out.puts "public void encode(XdrDataOutputStream stream) throws IOException {" - if union.discriminant.type.is_a?(AST::Typespecs::Int) - out.puts "stream.writeInt(discriminant);" - elsif type_string(union.discriminant.type) == "Uint32" - # ugly workaround for compile error after generating source for AuthenticatedMessage in stellar-core - out.puts "stream.writeInt(discriminant.getUint32().getNumber().intValue());" - else - out.puts "stream.writeInt(discriminant.getValue());" - end - if type_string(union.discriminant.type) == "Uint32" - # ugly workaround for compile error after generating source for AuthenticatedMessage in stellar-core - out.puts "switch (discriminant.getUint32().getNumber().intValue()) {" - else - out.puts "switch (discriminant) {" - end - union.arms.each do |arm| - case arm - when AST::Definitions::UnionDefaultArm ; - out.puts "default:" - else - arm.cases.each do |kase| - if kase.value.is_a?(AST::Identifier) - if type_string(union.discriminant.type) == "Integer" - member = union.resolved_case(kase) - out.puts "case #{member.value}:" - else - out.puts "case #{kase.value.name}:" - end - else - out.puts "case #{kase.value.value}:" - end - end - end - encode_member arm, out - out.puts "break;" - end - out.puts "}\n}" - - out.puts "public static #{name union} decode(XdrDataInputStream stream) throws IOException {" - out.puts "#{name union} decoded#{name union} = new #{name union}();" - if union.discriminant.type.is_a?(AST::Typespecs::Int) - out.puts "Integer discriminant = stream.readInt();" - else - out.puts "#{name union.discriminant.type} discriminant = #{name union.discriminant.type}.decode(stream);" - end - out.puts "decoded#{name union}.setDiscriminant(discriminant);" - - if type_string(union.discriminant.type) == "Uint32" - # ugly workaround for compile error after generating source for AuthenticatedMessage in stellar-core - out.puts "switch (decoded#{name union}.getDiscriminant().getUint32().getNumber().intValue()) {" - else - out.puts "switch (decoded#{name union}.getDiscriminant()) {" - end - - union.arms.each do |arm| - case arm - when AST::Definitions::UnionDefaultArm ; - out.puts "default:" - else - arm.cases.each do |kase| - if kase.value.is_a?(AST::Identifier) - if type_string(union.discriminant.type) == "Integer" - member = union.resolved_case(kase) - out.puts "case #{member.value}:" - else - out.puts "case #{kase.value.name}:" - end - else - out.puts "case #{kase.value.value}:" - end - end - end - decode_member "decoded#{name union}", arm, out - out.puts "break;" - end - out.puts "}\n" - out.indent do - out.puts "return decoded#{name union};" - end - out.puts "}" - render_base64((name union), out) - out.break - end - - def render_top_matter(out) - out.puts <<-EOS.strip_heredoc - // Automatically generated by xdrgen - // DO NOT EDIT or your changes may be overwritten - - package #{@namespace}; - - import java.io.IOException; - EOS - out.break - end - - def render_source_comment(out, defn) - return if defn.is_a?(AST::Definitions::Namespace) - - out.puts "/**" - out.puts " * #{name defn}'s original definition in the XDR file is:" - out.puts " *
"
- out.puts " * " + escape_html(defn.text_value).split("\n").join("\n * ")
- out.puts " * "
- out.puts " */"
- end
-
- def render_base64(return_type, out)
- out.puts <<-EOS.strip_heredoc
- public static #{return_type} fromXdrBase64(String xdr) throws IOException {
- byte[] bytes = Base64Factory.getInstance().decode(xdr);
- return fromXdrByteArray(bytes);
- }
-
- public static #{return_type} fromXdrByteArray(byte[] xdr) throws IOException {
- ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr);
- XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream);
- return decode(xdrDataInputStream);
- }
- EOS
- end
-
- def encode_member(member, out)
- case member.declaration
- when AST::Declarations::Void
- return
- end
-
- if member.type.sub_type == :optional
- out.puts "if (#{member.name} != null) {"
- out.puts "stream.writeInt(1);"
- end
- case member.declaration
- when AST::Declarations::Opaque ;
- out.puts "int #{member.name}Size = #{member.name}.length;"
- unless member.declaration.fixed?
- out.puts "stream.writeInt(#{member.name}Size);"
- end
- out.puts <<-EOS.strip_heredoc
- stream.write(get#{member.name.slice(0,1).capitalize+member.name.slice(1..-1)}(), 0, #{member.name}Size);
- EOS
- when AST::Declarations::Array ;
- out.puts "int #{member.name}Size = get#{member.name.slice(0,1).capitalize+member.name.slice(1..-1)}().length;"
- unless member.declaration.fixed?
- out.puts "stream.writeInt(#{member.name}Size);"
- end
- out.puts <<-EOS.strip_heredoc
- for (int i = 0; i < #{member.name}Size; i++) {
- #{encode_type member.declaration.type, "#{member.name}[i]"};
- }
- EOS
- else
- out.puts "#{encode_type member.declaration.type, "#{member.name}"};"
- end
- if member.type.sub_type == :optional
- out.puts "} else {"
- out.puts "stream.writeInt(0);"
- out.puts "}"
- end
- end
-
- def encode_type(type, value)
- case type
- when AST::Typespecs::Int ;
- "stream.writeInt(#{value})"
- when AST::Typespecs::UnsignedInt ;
- "#{value}.encode(stream)"
- when AST::Typespecs::Hyper ;
- "stream.writeLong(#{value})"
- when AST::Typespecs::UnsignedHyper ;
- "#{value}.encode(stream)"
- when AST::Typespecs::Float ;
- "stream.writeFloat(#{value})"
- when AST::Typespecs::Double ;
- "stream.writeDouble(#{value})"
- when AST::Typespecs::Quadruple ;
- raise "cannot render quadruple in golang"
- when AST::Typespecs::Bool ;
- "stream.writeInt(#{value} ? 1 : 0)"
- when AST::Typespecs::String ;
- "#{value}.encode(stream)"
- when AST::Typespecs::Simple ;
- "#{value}.encode(stream)"
- when AST::Concerns::NestedDefinition ;
- "#{value}.encode(stream)"
- else
- raise "Unknown typespec: #{type.class.name}"
- end
- end
-
- def decode_member(value, member, out)
- case member.declaration
- when AST::Declarations::Void ;
- return
- end
- if member.type.sub_type == :optional
- out.puts <<-EOS.strip_heredoc
- int #{member.name}Present = stream.readInt();
- if (#{member.name}Present != 0) {
- EOS
- end
- case member.declaration
- when AST::Declarations::Opaque ;
- if (member.declaration.fixed?)
- out.puts "int #{member.name}Size = #{convert_constant member.declaration.size};"
- else
- out.puts "int #{member.name}Size = stream.readInt();"
- end
- out.puts <<-EOS.strip_heredoc
- #{value}.#{member.name} = new byte[#{member.name}Size];
- stream.read(#{value}.#{member.name}, 0, #{member.name}Size);
- EOS
- when AST::Declarations::Array ;
- if (member.declaration.fixed?)
- out.puts "int #{member.name}Size = #{convert_constant member.declaration.size};"
- else
- out.puts "int #{member.name}Size = stream.readInt();"
- end
- out.puts <<-EOS.strip_heredoc
- #{value}.#{member.name} = new #{type_string member.type}[#{member.name}Size];
- for (int i = 0; i < #{member.name}Size; i++) {
- #{value}.#{member.name}[i] = #{decode_type member.declaration};
- }
- EOS
- else
- out.puts "#{value}.#{member.name} = #{decode_type member.declaration};"
- end
- if member.type.sub_type == :optional
- out.puts "}"
- end
- end
-
- def decode_type(decl)
- case decl.type
- when AST::Typespecs::Int ;
- "stream.readInt()"
- when AST::Typespecs::UnsignedInt ;
- "XdrUnsignedInteger.decode(stream)"
- when AST::Typespecs::Hyper ;
- "stream.readLong()"
- when AST::Typespecs::UnsignedHyper ;
- "XdrUnsignedHyperInteger.decode(stream)"
- when AST::Typespecs::Float ;
- "stream.readFloat()"
- when AST::Typespecs::Double ;
- "stream.readDouble()"
- when AST::Typespecs::Quadruple ;
- raise "cannot render quadruple in golang"
- when AST::Typespecs::Bool ;
- "stream.readInt() == 1 ? true : false"
- when AST::Typespecs::String ;
- "XdrString.decode(stream, #{(convert_constant decl.size) || 'Integer.MAX_VALUE'})"
- when AST::Typespecs::Simple ;
- "#{name decl.type.resolved_type}.decode(stream)"
- when AST::Concerns::NestedDefinition ;
- "#{name decl.type}.decode(stream)"
- else
- raise "Unknown typespec: #{decl.type.class.name}"
- end
- end
-
- def decl_string(decl)
- case decl
- when AST::Declarations::Opaque ;
- "byte[]"
- when AST::Declarations::String ;
- "XdrString"
- when AST::Declarations::Array ;
- "#{type_string decl.type}[]"
- when AST::Declarations::Optional ;
- "#{type_string(decl.type)}"
- when AST::Declarations::Simple ;
- type_string(decl.type)
- else
- raise "Unknown declaration type: #{decl.class.name}"
- end
- end
-
- def is_decl_array(decl)
- case decl
- when AST::Declarations::Opaque ;
- true
- when AST::Declarations::Array ;
- true
- when AST::Declarations::Optional ;
- is_type_array(decl.type)
- when AST::Declarations::Simple ;
- is_type_array(decl.type)
- else
- false
- end
- end
-
- def is_type_array(type)
- case type
- when AST::Typespecs::Opaque ;
- true
- else
- false
- end
- end
-
- def type_string(type)
- case type
- when AST::Typespecs::Int ;
- "Integer"
- when AST::Typespecs::UnsignedInt ;
- "XdrUnsignedInteger"
- when AST::Typespecs::Hyper ;
- "Long"
- when AST::Typespecs::UnsignedHyper ;
- "XdrUnsignedHyperInteger"
- when AST::Typespecs::Float ;
- "Float"
- when AST::Typespecs::Double ;
- "Double"
- when AST::Typespecs::Quadruple ;
- raise "cannot render quadruple in golang"
- when AST::Typespecs::Bool ;
- "Boolean"
- when AST::Typespecs::Opaque ;
- "Byte[#{convert_constant type.size}]"
- when AST::Typespecs::String ;
- "XdrString"
- when AST::Typespecs::Simple ;
- name type.resolved_type
- when AST::Concerns::NestedDefinition ;
- name type
- else
- raise "Unknown typespec: #{type.class.name}"
- end
- end
-
- def name(named)
- parent = name named.parent_defn if named.is_a?(AST::Concerns::NestedDefinition)
- result = named.name.camelize
-
- "#{parent}#{result}"
- end
-
- def name_string(name)
- name.camelize
- end
-
- def escape_html(value)
- value.to_s
- .gsub('&', '&')
- .gsub('<', '<')
- .gsub('>', '>')
- .gsub('*', '*') # to avoid encountering`*/`
- end
-
- def convert_constant(str)
- if str.nil? || str.empty?
- str
- elsif str =~ /\A\d+\z/
- str
- else
- "Constants.#{str}"
- end
- end
- end
- end
-end
diff --git a/lib/xdrgen/generators/java/XdrDataInputStream.erb b/lib/xdrgen/generators/java/XdrDataInputStream.erb
deleted file mode 100644
index 127551e48..000000000
--- a/lib/xdrgen/generators/java/XdrDataInputStream.erb
+++ /dev/null
@@ -1,122 +0,0 @@
-package <%= @namespace %>;
-
-import java.io.DataInputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.nio.charset.Charset;
-
-public class XdrDataInputStream extends DataInputStream {
-
- // The underlying input stream
- private final XdrInputStream mIn;
-
- /**
- * Creates a XdrDataInputStream that uses the specified
- * underlying InputStream.
- *
- * @param in the specified input stream
- */
- public XdrDataInputStream(InputStream in) {
- super(new XdrInputStream(in));
- mIn = (XdrInputStream) super.in;
- }
-
- public int[] readIntArray() throws IOException {
- int l = readInt();
- return readIntArray(l);
- }
-
- private int[] readIntArray(int l) throws IOException {
- int[] arr = new int[l];
- for (int i = 0; i < l; i++) {
- arr[i] = readInt();
- }
- return arr;
- }
-
- public float[] readFloatArray() throws IOException {
- int l = readInt();
- return readFloatArray(l);
- }
-
- private float[] readFloatArray(int l) throws IOException {
- float[] arr = new float[l];
- for (int i = 0; i < l; i++) {
- arr[i] = readFloat();
- }
- return arr;
- }
-
- public double[] readDoubleArray() throws IOException {
- int l = readInt();
- return readDoubleArray(l);
- }
-
- private double[] readDoubleArray(int l) throws IOException {
- double[] arr = new double[l];
- for (int i = 0; i < l; i++) {
- arr[i] = readDouble();
- }
- return arr;
- }
-
- @Override
- public int read() throws IOException {
- return super.read();
- }
-
- /**
- * Need to provide a custom impl of InputStream as DataInputStream's read methods
- * are final and we need to keep track of the count for padding purposes.
- */
- private static final class XdrInputStream extends InputStream {
-
- // The underlying input stream
- private final InputStream mIn;
-
- // The amount of bytes read so far.
- private int mCount;
-
- public XdrInputStream(InputStream in) {
- mIn = in;
- mCount = 0;
- }
-
- @Override
- public int read() throws IOException {
- int read = mIn.read();
- if (read >= 0) {
- mCount++;
- }
- return read;
- }
-
- @Override
- public int read(byte[] b) throws IOException {
- return read(b, 0, b.length);
- }
-
- @Override
- public int read(byte[] b, int off, int len) throws IOException {
- int read = mIn.read(b, off, len);
- mCount += read;
- pad();
- return read;
- }
-
- public void pad() throws IOException {
- int pad = 0;
- int mod = mCount % 4;
- if (mod > 0) {
- pad = 4-mod;
- }
-
- while (pad-- > 0) {
- int b = read();
- if (b != 0) {
- throw new IOException("non-zero padding");
- }
- }
- }
- }
-}
diff --git a/lib/xdrgen/generators/java/XdrDataOutputStream.erb b/lib/xdrgen/generators/java/XdrDataOutputStream.erb
deleted file mode 100644
index 6069833a9..000000000
--- a/lib/xdrgen/generators/java/XdrDataOutputStream.erb
+++ /dev/null
@@ -1,96 +0,0 @@
-package <%= @namespace %>;
-
-import java.io.DataOutputStream;
-import java.io.IOException;
-import java.io.OutputStream;
-import java.nio.charset.Charset;
-
-public class XdrDataOutputStream extends DataOutputStream {
-
- private final XdrOutputStream mOut;
-
- public XdrDataOutputStream(OutputStream out) {
- super(new XdrOutputStream(out));
- mOut = (XdrOutputStream) super.out;
- }
-
- public void writeIntArray(int[] a) throws IOException {
- writeInt(a.length);
- writeIntArray(a, a.length);
- }
-
- private void writeIntArray(int[] a, int l) throws IOException {
- for (int i = 0; i < l; i++) {
- writeInt(a[i]);
- }
- }
-
- public void writeFloatArray(float[] a) throws IOException {
- writeInt(a.length);
- writeFloatArray(a, a.length);
- }
-
- private void writeFloatArray(float[] a, int l) throws IOException {
- for (int i = 0; i < l; i++) {
- writeFloat(a[i]);
- }
- }
-
- public void writeDoubleArray(double[] a) throws IOException {
- writeInt(a.length);
- writeDoubleArray(a, a.length);
- }
-
- private void writeDoubleArray(double[] a, int l) throws IOException {
- for (int i = 0; i < l; i++) {
- writeDouble(a[i]);
- }
- }
-
- private static final class XdrOutputStream extends OutputStream {
-
- private final OutputStream mOut;
-
- // Number of bytes written
- private int mCount;
-
- public XdrOutputStream(OutputStream out) {
- mOut = out;
- mCount = 0;
- }
-
- @Override
- public void write(int b) throws IOException {
- mOut.write(b);
- // https://docs.oracle.com/javase/7/docs/api/java/io/OutputStream.html#write(int):
- // > The byte to be written is the eight low-order bits of the argument b.
- // > The 24 high-order bits of b are ignored.
- mCount++;
- }
-
- @Override
- public void write(byte[] b) throws IOException {
- // https://docs.oracle.com/javase/7/docs/api/java/io/OutputStream.html#write(byte[]):
- // > The general contract for write(b) is that it should have exactly the same effect
- // > as the call write(b, 0, b.length).
- write(b, 0, b.length);
- }
-
- public void write(byte[] b, int offset, int length) throws IOException {
- mOut.write(b, offset, length);
- mCount += length;
- pad();
- }
-
- public void pad() throws IOException {
- int pad = 0;
- int mod = mCount % 4;
- if (mod > 0) {
- pad = 4-mod;
- }
- while (pad-- > 0) {
- write(0);
- }
- }
- }
-}
diff --git a/lib/xdrgen/generators/java/XdrElement.erb b/lib/xdrgen/generators/java/XdrElement.erb
deleted file mode 100644
index 13daaaf5d..000000000
--- a/lib/xdrgen/generators/java/XdrElement.erb
+++ /dev/null
@@ -1,21 +0,0 @@
-package <%= @namespace %>;
-
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import org.stellar.sdk.Base64Factory;
-
-/** Common parent interface for all generated classes. */
-interface XdrElement {
- void encode(XdrDataOutputStream stream) throws IOException;
-
- default String toXdrBase64() throws IOException {
- return Base64Factory.getInstance().encodeToString(toXdrByteArray());
- }
-
- default byte[] toXdrByteArray() throws IOException {
- ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
- XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream);
- encode(xdrDataOutputStream);
- return byteArrayOutputStream.toByteArray();
- }
-}
diff --git a/lib/xdrgen/generators/java/XdrString.erb b/lib/xdrgen/generators/java/XdrString.erb
deleted file mode 100644
index cceb6d475..000000000
--- a/lib/xdrgen/generators/java/XdrString.erb
+++ /dev/null
@@ -1,62 +0,0 @@
-package <%= @namespace %>;
-
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import java.io.InvalidClassException;
-import java.nio.charset.StandardCharsets;
-import lombok.Value;
-import org.stellar.sdk.Base64Factory;
-
-@Value
-public class XdrString implements XdrElement {
- byte[] bytes;
-
- public XdrString(byte[] bytes) {
- this.bytes = bytes;
- }
-
- public XdrString(String text) {
- this.bytes = text.getBytes(StandardCharsets.UTF_8);
- }
-
- @Override
- public void encode(XdrDataOutputStream stream) throws IOException {
- stream.writeInt(this.bytes.length);
- stream.write(this.bytes, 0, this.bytes.length);
- }
-
- public static XdrString decode(XdrDataInputStream stream, int maxSize) throws IOException {
- int size = stream.readInt();
- if (size > maxSize) {
- throw new IllegalArgumentException("String length " + size + " exceeds max size " + maxSize);
- }
- byte[] bytes = new byte[size];
- stream.read(bytes);
- return new XdrString(bytes);
- }
-
- public static XdrString fromXdrBase64(String xdr, int maxSize) throws IOException {
- byte[] bytes = Base64Factory.getInstance().decode(xdr);
- return fromXdrByteArray(bytes, maxSize);
- }
-
- public static XdrString fromXdrBase64(String xdr) throws IOException {
- return fromXdrBase64(xdr, Integer.MAX_VALUE);
- }
-
- public static XdrString fromXdrByteArray(byte[] xdr, int maxSize) throws IOException {
- ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr);
- XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream);
- return decode(xdrDataInputStream, maxSize);
- }
-
- public static XdrString fromXdrByteArray(byte[] xdr) throws IOException {
- return fromXdrByteArray(xdr, Integer.MAX_VALUE);
- }
-
- @Override
- public String toString() {
- return new String(bytes, StandardCharsets.UTF_8);
- }
-}
diff --git a/lib/xdrgen/generators/java/XdrUnsignedHyperInteger.erb b/lib/xdrgen/generators/java/XdrUnsignedHyperInteger.erb
deleted file mode 100644
index e586be844..000000000
--- a/lib/xdrgen/generators/java/XdrUnsignedHyperInteger.erb
+++ /dev/null
@@ -1,69 +0,0 @@
-package <%= @namespace %>;
-
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import java.math.BigInteger;
-import lombok.Value;
-import org.stellar.sdk.Base64Factory;
-
-/**
- * Represents XDR Unsigned Hyper Integer.
- *
- * @see XDR: External Data
- * Representation Standard
- */
-@Value
-public class XdrUnsignedHyperInteger implements XdrElement {
- public static final BigInteger MAX_VALUE = new BigInteger("18446744073709551615");
- public static final BigInteger MIN_VALUE = BigInteger.ZERO;
- BigInteger number;
-
- public XdrUnsignedHyperInteger(BigInteger number) {
- if (number.compareTo(MIN_VALUE) < 0 || number.compareTo(MAX_VALUE) > 0) {
- throw new IllegalArgumentException("number must be between 0 and 2^64 - 1 inclusive");
- }
- this.number = number;
- }
-
- public XdrUnsignedHyperInteger(Long number) {
- if (number < 0) {
- throw new IllegalArgumentException(
- "number must be greater than or equal to 0 if you want to construct it from Long");
- }
- this.number = BigInteger.valueOf(number);
- }
-
- @Override
- public void encode(XdrDataOutputStream stream) throws IOException {
- stream.write(getBytes());
- }
-
- public static XdrUnsignedHyperInteger decode(XdrDataInputStream stream) throws IOException {
- byte[] bytes = new byte[8];
- stream.readFully(bytes);
- BigInteger uint64 = new BigInteger(1, bytes);
- return new XdrUnsignedHyperInteger(uint64);
- }
-
- private byte[] getBytes() {
- byte[] bytes = number.toByteArray();
- byte[] paddedBytes = new byte[8];
-
- int numBytesToCopy = Math.min(bytes.length, 8);
- int copyStartIndex = bytes.length - numBytesToCopy;
- System.arraycopy(bytes, copyStartIndex, paddedBytes, 8 - numBytesToCopy, numBytesToCopy);
- return paddedBytes;
- }
-
- public static XdrUnsignedHyperInteger fromXdrBase64(String xdr) throws IOException {
- byte[] bytes = Base64Factory.getInstance().decode(xdr);
- return fromXdrByteArray(bytes);
- }
-
- public static XdrUnsignedHyperInteger fromXdrByteArray(byte[] xdr) throws IOException {
- ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr);
- XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream);
- return decode(xdrDataInputStream);
- }
-}
diff --git a/lib/xdrgen/generators/java/XdrUnsignedInteger.erb b/lib/xdrgen/generators/java/XdrUnsignedInteger.erb
deleted file mode 100644
index 8767d6d12..000000000
--- a/lib/xdrgen/generators/java/XdrUnsignedInteger.erb
+++ /dev/null
@@ -1,57 +0,0 @@
-package <%= @namespace %>;
-
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import lombok.Value;
-import org.stellar.sdk.Base64Factory;
-
-/**
- * Represents XDR Unsigned Integer.
- *
- * @see XDR: External Data
- * Representation Standard
- */
-@Value
-public class XdrUnsignedInteger implements XdrElement {
- public static final long MAX_VALUE = (1L << 32) - 1;
- public static final long MIN_VALUE = 0;
- Long number;
-
- public XdrUnsignedInteger(Long number) {
- if (number < MIN_VALUE || number > MAX_VALUE) {
- throw new IllegalArgumentException("number must be between 0 and 2^32 - 1 inclusive");
- }
- this.number = number;
- }
-
- public XdrUnsignedInteger(Integer number) {
- if (number < 0) {
- throw new IllegalArgumentException(
- "number must be greater than or equal to 0 if you want to construct it from Integer");
- }
- this.number = number.longValue();
- }
-
- public static XdrUnsignedInteger decode(XdrDataInputStream stream) throws IOException {
- int intValue = stream.readInt();
- long uint32Value = Integer.toUnsignedLong(intValue);
- return new XdrUnsignedInteger(uint32Value);
- }
-
- @Override
- public void encode(XdrDataOutputStream stream) throws IOException {
- stream.writeInt(number.intValue());
- }
-
- public static XdrUnsignedInteger fromXdrBase64(String xdr) throws IOException {
- byte[] bytes = Base64Factory.getInstance().decode(xdr);
- return fromXdrByteArray(bytes);
- }
-
- public static XdrUnsignedInteger fromXdrByteArray(byte[] xdr) throws IOException {
- ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr);
- XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream);
- return decode(xdrDataInputStream);
- }
-}
diff --git a/lib/xdrgen/generators/python.rb b/lib/xdrgen/generators/python.rb
deleted file mode 100644
index 507f49f92..000000000
--- a/lib/xdrgen/generators/python.rb
+++ /dev/null
@@ -1,695 +0,0 @@
-# Note:
-# 1. If the .x file contains Python reserved words, I suggest you change them to non-reserved words.
-# 2. You can generate the file with the following command
-# xdrgen -o OUTPUT_DIR INPUT -l python
-# 3. The generated code is unformatted, I suggest you format it by the following command:
-# autoflake --in-place --ignore-init-module-imports --remove-all-unused-imports OUTPUT_DIR/*.py
-# isort OUTPUT_DIR/
-# black OUTPUT_DIR/
-
-module Xdrgen
- module Generators
- class Python < Xdrgen::Generators::Base
- MAX_SIZE = (2 ** 32) - 1
- CIRCLE_IMPORT_UNION = %w[SCVal SCSpecTypeDef]
-
- def generate
- @constants_out = @output.open("constants.py")
- @constants_out.puts <<-EOS.strip_heredoc
- # This is an automatically generated file.
- # DO NOT EDIT or your changes may be overwritten
- EOS
-
- @init_out = @output.open("__init__.py")
- @init_out.puts <<-EOS.strip_heredoc
- # Automatically generated by xdrgen
- # DO NOT EDIT or your changes may be overwritten
- from .base import *
- from .constants import *
- EOS
-
- render_base_classes
- render_definitions(@top)
- end
-
- private
-
- def render_definitions(node)
- node.definitions.each { |n| render_definition n }
- node.namespaces.each { |n| render_definitions n }
- end
-
- def render_nested_definitions(defn)
- return unless defn.respond_to? :nested_definitions
- defn.nested_definitions.each { |ndefn| render_definition ndefn }
- end
-
- def render_definition(defn)
- render_nested_definitions(defn)
- case defn
- when AST::Definitions::Struct;
- render_struct defn
- when AST::Definitions::Enum
- render_enum defn
- when AST::Definitions::Union;
- if CIRCLE_IMPORT_UNION.include?(defn.name)
- render_union defn, true
- else
- render_union defn
- end
- when AST::Definitions::Typedef
- render_typedef defn
- when AST::Definitions::Const
- render_const defn
- end
- end
-
- def render_const(const)
- render_const_source_comment @constants_out, const
- @constants_out.puts "#{const.name}: int = #{const.value}"
- end
-
- def render_enum(enum)
- enum_name = name enum
- enum_name_underscore = enum_name.underscore
- @init_out.puts "from .#{enum_name_underscore} import #{enum_name}"
-
- file_name = "#{enum_name_underscore}.py"
- out = @output.open(file_name)
- render_common_import out
-
- out.puts "__all__ = ['#{enum_name}']"
-
- out.puts "class #{enum_name}(IntEnum):"
- out.indent(2) do
- render_source_comment out, enum
- enum.members.each do |member|
- out.puts "#{member.name} = #{member.value}"
- end
-
- out.puts <<~HEREDOC
- def pack(self, packer: Packer) -> None:
- packer.pack_int(self.value)
-
- @classmethod
- def unpack(cls, unpacker: Unpacker) -> #{enum_name}:
- value = unpacker.unpack_int()
- return cls(value)
- HEREDOC
-
- render_xdr_utils out, enum_name
- out.close
- end
- end
-
- def render_typedef(typedef)
- typedef_name = typedef.name.camelize
- typedef_name_underscore = typedef.name.underscore
-
- @init_out.puts "from .#{typedef_name_underscore} import #{typedef_name}"
-
- file_name = "#{typedef_name_underscore}.py"
- out = @output.open(file_name)
- render_common_import out
-
- render_import out, typedef, typedef_name
-
- out.puts "__all__ = ['#{typedef_name}']"
-
- out.puts "class #{typedef_name}:"
- out.indent(2) do
- render_source_comment(out, typedef)
- out.puts "def __init__(self, #{typedef_name_underscore}: #{type_hint_string typedef, typedef_name}) -> None:"
- out.indent(2) do
- render_array_length_checker typedef, out
- out.puts "self.#{typedef_name_underscore} = #{typedef_name_underscore}"
- end
-
- out.puts "def pack(self, packer: Packer) -> None:"
- out.indent(2) do
- encode_member typedef, out
- end
-
- out.puts "@classmethod"
- out.puts "def unpack(cls, unpacker: Unpacker) -> #{typedef_name}:"
- out.indent(2) do
- decode_member typedef, out
- out.puts "return cls(#{typedef_name_underscore})"
- end
- render_xdr_utils(out, typedef_name)
- out.puts <<~HEREDOC
- def __hash__(self):
- return hash(self.#{typedef_name_underscore})
- def __eq__(self, other: object):
- if not isinstance(other, self.__class__):
- return NotImplemented
- return self.#{typedef_name_underscore} == other.#{typedef_name_underscore}
-
- def __str__(self):
- return f"<#{typedef_name} [#{typedef_name_underscore}={self.#{typedef_name_underscore}}]>"
- HEREDOC
- end
- out.close
- end
-
- def render_import(out, member, container_name)
- member_type = type_string member.type
- unless is_base_type member.type or container_name == member_type
- out.puts "from .#{member_type.underscore} import #{member_type}"
- end
- end
-
- def render_union(union, render_import_in_func = false)
- union_name = name union
- union_name_underscore = union_name.underscore
- @init_out.puts "from .#{union_name_underscore} import #{union_name}"
-
- file_name = "#{union_name_underscore}.py"
- out = @output.open(file_name)
- render_common_import out
-
- render_import out, union.discriminant, union_name
-
- if render_import_in_func
- out.puts "if TYPE_CHECKING:"
- out.indent(2) do
- union.arms.each do |arm|
- next if arm.void?
- # This may cause duplicate imports, we can remove it with autoflake
- render_import out, arm.declaration, union_name
- end
- end
- else
- union.arms.each do |arm|
- next if arm.void?
- # This may cause duplicate imports, we can remove it with autoflake
- render_import out, arm.declaration, union_name
- end
- end
-
- out.puts "__all__ = ['#{union_name}']"
-
- out.puts "class #{union_name}:"
- out.indent(2) do
- render_source_comment(out, union)
- union_discriminant_name_underscore = union.discriminant.name.underscore
- out.puts <<~HEREDOC
- def __init__(
- self,
- #{union_discriminant_name_underscore}: #{type_hint_string union.discriminant, union_name},
- HEREDOC
-
- out.indent(2) do
- union.arms.each do |arm|
- next if arm.void?
- out.puts "#{arm.name.underscore}: #{type_hint_string arm.declaration, union_name} = None,"
- end
- end
-
- out.puts ") -> None:"
- out.indent(2) do
- union.arms.each do |arm|
- next if arm.void?
- render_array_length_checker arm, out
- end
-
- out.puts "self.#{union_discriminant_name_underscore} = #{union_discriminant_name_underscore}"
- union.arms.each do |arm|
- next if arm.void?
- arm_name_underscore = arm.name.underscore
- out.puts "self.#{arm_name_underscore} = #{arm_name_underscore}"
- end
- end
-
- out.puts "def pack(self, packer: Packer) -> None:"
- out.indent(2) do
- out.puts "#{encode_type union.discriminant, 'self.' + union_discriminant_name_underscore}"
- union.normal_arms.each do |arm|
- arm.cases.each do |c|
- if c.value.is_a?(AST::Identifier)
- out.puts "if self.#{union_discriminant_name_underscore} == #{type_string union.discriminant.type}.#{c.value.name}:"
- else
- out.puts "if self.#{union_discriminant_name_underscore} == #{c.value.value}:"
- end
- out.indent(2) do
- unless arm.void?
- encode_member arm, out, true
- end
- out.puts "return"
- end
- end
- end
- if union.default_arm.present? and not union.default_arm.void?
- encode_member union.default_arm, out, true
- end
- end
-
- out.puts "@classmethod"
- out.puts "def unpack(cls, unpacker: Unpacker) -> #{union_name}:"
- out.indent(2) do
- out.puts "#{union_discriminant_name_underscore} = #{decode_type union.discriminant}"
- union.normal_arms.each do |arm|
- arm.cases.each do |c|
- if c.value.is_a?(AST::Identifier)
- out.puts "if #{union_discriminant_name_underscore} == #{type_string union.discriminant.type}.#{c.value.name}:"
- else
- out.puts "if #{union_discriminant_name_underscore} == #{c.value.value}:"
- end
- out.indent(2) do
- if arm.void?
- out.puts "return cls(#{union_discriminant_name_underscore}=#{union_discriminant_name_underscore})"
- else
- if render_import_in_func
- render_import out, arm.declaration, union_name
- end
-
- decode_member arm, out
- arm_name_underscore = arm.name.underscore
- out.puts "return cls(#{union_discriminant_name_underscore}=#{union_discriminant_name_underscore}, #{arm_name_underscore}=#{arm_name_underscore})"
- end
- end
- end
- end
-
- if union.default_arm.present? and not union.default_arm.void?
- decode_member union.default_arm, out
- arm_name_underscore = union.default_arm.name.underscore
- out.puts "return cls(#{union_discriminant_name_underscore}=#{union_discriminant_name_underscore}, #{arm_name_underscore}=#{arm_name_underscore})"
- else
- out.puts "return cls(#{union_discriminant_name_underscore}=#{union_discriminant_name_underscore})"
- end
- end
-
- render_xdr_utils(out, union_name)
- attribute_names = []
- attribute_names.push(union_discriminant_name_underscore)
- union.arms.each do |arm|
- next if arm.void?
- attribute_names.push(arm.name.underscore)
- end
- out.puts <<~HEREDOC
- def __hash__(self):
- return hash((#{attribute_names.map { |m| 'self.' + m }.join(", ")},))
- def __eq__(self, other: object):
- if not isinstance(other, self.__class__):
- return NotImplemented
- return #{attribute_names.map { |m| 'self.' + m + '== other.' + m }.join(" and ")}
- HEREDOC
-
- out.puts "def __str__(self):"
- out.indent(2) do
- out.puts "out = []"
- out.puts "out.append(f'#{union_discriminant_name_underscore}={self.#{union_discriminant_name_underscore}}')"
- union.arms.each do |arm|
- next if arm.void?
- arm_name_underscore = arm.name.underscore
- out.puts "out.append(f'#{arm_name_underscore}={self.#{arm_name_underscore}}') if self.#{arm_name_underscore} is not None else None"
- end
- out.puts "return f\"<#{union_name} [{', '.join(out)}]>\""
- end
- end
- out.close
- end
-
- def render_struct(struct)
- struct_name = name struct
- struct_name_underscore = struct_name.underscore
- @init_out.puts "from .#{struct_name_underscore} import #{struct_name}"
-
- file_name = "#{struct_name_underscore}.py"
- out = @output.open(file_name)
- render_common_import out
-
- struct.members.each do |member|
- # This may cause duplicate imports, we can remove it through autoflake
- render_import out, member.declaration, struct_name
- end
-
- out.puts "__all__ = ['#{struct_name}']"
-
- out.puts "class #{struct_name}:"
- out.indent(2) do
- render_source_comment(out, struct)
- out.puts <<~HEREDOC
- def __init__(
- self,
- HEREDOC
-
- out.indent(2) do
- struct.members.each do |member|
- out.puts "#{member.name.underscore}: #{type_hint_string member.declaration, struct_name},"
- end
- end
- out.puts ") -> None:"
-
- out.indent(2) do
- struct.members.each do |member|
- render_array_length_checker member, out
- end
- struct.members.each do |member|
- member_name_underscore = member.name.underscore
- out.puts "self.#{member_name_underscore} = #{member_name_underscore}"
- end
- end
- out.puts "def pack(self, packer: Packer) -> None:"
- out.indent(2) do
- struct.members.each do |member|
- encode_member member, out
- end
- end
-
- out.puts "@classmethod"
- out.puts "def unpack(cls, unpacker: Unpacker) -> #{struct_name}:"
- out.indent(2) do
- struct.members.each do |member|
- decode_member member, out
- end
- out.puts "return cls("
- out.indent(2) do
- struct.members.each do |member|
- member_name_underscore = member.name.underscore
- out.puts "#{member_name_underscore}=#{member_name_underscore},"
- end
- end
- out.puts ")"
- end
-
- render_xdr_utils(out, struct_name)
-
- attribute_names = []
- struct.members.each do |member|
- attribute_names.push(member.name.underscore)
- end
- out.puts <<~HEREDOC
- def __hash__(self):
- return hash((#{attribute_names.map { |m| 'self.' + m }.join(", ")},))
- def __eq__(self, other: object):
- if not isinstance(other, self.__class__):
- return NotImplemented
- return #{attribute_names.map { |m| 'self.' + m + '== other.' + m }.join(" and ")}
- HEREDOC
-
- out.puts "def __str__(self):"
- out.indent(2) do
- out.puts "out = ["
- out.indent(2) do
- attribute_names.each do |name|
- name = name
- out.puts "f'#{name}={self.#{name}}',"
- end
- end
- out.puts "]"
- out.puts "return f\"<#{struct_name} [{', '.join(out)}]>\""
- end
-
- end
- out.close
- end
-
- def encode_member(member, out, is_union_member = false)
- case member.declaration
- when AST::Declarations::Void
- out.puts "return"
- end
- member_name_underscore = member.name.underscore
- if member.type.sub_type == :optional
- out.puts <<~HEREDOC
- if self.#{member_name_underscore} is None:
- packer.pack_uint(0)
- else:
- packer.pack_uint(1)
- HEREDOC
- end
-
- out.indent(member.type.sub_type == :optional ? 2 : 0) do
- if is_union_member # All members of union are actually optional
- out.puts <<~HEREDOC
- if self.#{member_name_underscore} is None:
- raise ValueError("#{member_name_underscore} should not be None.")
- HEREDOC
- end
- case member.declaration
- when AST::Declarations::Array
- unless member.declaration.fixed?
- out.puts "packer.pack_uint(len(self.#{member_name_underscore}))"
- end
- out.puts <<~HEREDOC
- for #{member_name_underscore}_item in self.#{member_name_underscore}:
- #{encode_type member.declaration, member_name_underscore + '_item'}
- HEREDOC
- else
- out.puts encode_type member.declaration, 'self.' + member_name_underscore
- end
- end
- end
-
- def decode_member(member, out)
- case member.declaration
- when AST::Declarations::Void;
- out.puts "return"
- end
- member_name_underscore = member.name.underscore
- decoded_member_declaration = decode_type member.declaration
-
- case member.declaration
- when AST::Declarations::Array
- if member.declaration.fixed?
- _, size = member.declaration.type.array_size
- out.puts "length = #{size}"
- else
- out.puts "length = unpacker.unpack_uint()"
- end
- out.puts <<-EOS.strip_heredoc
- #{member_name_underscore} = []
- for _ in range(length):
- #{member_name_underscore}.append(#{decoded_member_declaration})
- EOS
- else
- if member.type.sub_type == :optional
- out.puts "#{member_name_underscore} = #{decoded_member_declaration} if unpacker.unpack_uint() else None"
- else
- out.puts "#{member_name_underscore} = #{decoded_member_declaration}"
- end
- end
- end
-
- def render_common_import(out)
- out.puts <<-EOS.strip_heredoc
- # This is an automatically generated file.
- # DO NOT EDIT or your changes may be overwritten
- from __future__ import annotations
-
- import base64
- from enum import IntEnum
- from typing import List, Optional, TYPE_CHECKING
- from xdrlib3 import Packer, Unpacker
- from .base import Integer, UnsignedInteger, Float, Double, Hyper, UnsignedHyper, Boolean, String, Opaque
- from .constants import *
- EOS
- out.break
- end
-
- def render_array_length_checker(member, out)
- case member.declaration
- when AST::Declarations::Array
- _, size = member.declaration.type.array_size
- member_name_underscore = member.name.underscore
- if member.declaration.fixed?
- out.puts <<~HEREDOC
- _expect_length = #{size}
- if #{member_name_underscore} and len(#{member_name_underscore}) != _expect_length:
- raise ValueError(f\"The length of `#{member_name_underscore}` should be {_expect_length}, but got {len(#{member_name_underscore})}.\")
- HEREDOC
- else
- out.puts <<~HEREDOC
- _expect_max_length = #{size || MAX_SIZE}
- if #{member_name_underscore} and len(#{member_name_underscore}) > _expect_max_length:
- raise ValueError(f\"The maximum length of `#{member_name_underscore}` should be {_expect_max_length}, but got {len(#{member_name_underscore})}.\")
- HEREDOC
- end
- end
- end
-
- def render_xdr_utils(out, name)
- out.puts <<~HEREDOC
- def to_xdr_bytes(self) -> bytes:
- packer = Packer()
- self.pack(packer)
- return packer.get_buffer()
-
- @classmethod
- def from_xdr_bytes(cls, xdr: bytes) -> #{name}:
- unpacker = Unpacker(xdr)
- return cls.unpack(unpacker)
-
- def to_xdr(self) -> str:
- xdr_bytes = self.to_xdr_bytes()
- return base64.b64encode(xdr_bytes).decode()
-
- @classmethod
- def from_xdr(cls, xdr: str) -> #{name}:
- xdr_bytes = base64.b64decode(xdr.encode())
- return cls.from_xdr_bytes(xdr_bytes)
- HEREDOC
- end
-
- def render_base_classes
- file_name = "base.py"
- out = @output.open(file_name)
- base_py_content = IO.read(__dir__ + "/python/base.py")
- out.puts base_py_content
- out.close
- end
-
- def encode_type(decl, value)
- case decl.type
- when AST::Typespecs::Int;
- "Integer(#{value}).pack(packer)"
- when AST::Typespecs::UnsignedInt;
- "UnsignedInteger(#{value}).pack(packer)"
- when AST::Typespecs::Hyper;
- "Hyper(#{value}).pack(packer)"
- when AST::Typespecs::UnsignedHyper;
- "UnsignedHyper(#{value}).pack(packer)"
- when AST::Typespecs::Float;
- "Float(#{value}).pack(packer)"
- when AST::Typespecs::Double;
- "Double(#{value}).pack(packer)"
- when AST::Typespecs::Quadruple;
- raise "cannot render quadruple in Python"
- when AST::Typespecs::Bool;
- "Boolean(#{value}).pack(packer)"
- when AST::Typespecs::Opaque;
- "Opaque(#{value}, #{decl.size || MAX_SIZE}, #{decl.fixed? ? "True" : "False"}).pack(packer)"
- when AST::Typespecs::String;
- "String(#{value}, #{decl.size || MAX_SIZE}).pack(packer)"
- else
- "#{value}.pack(packer)"
- end
- end
-
- def decode_type(decl)
- case decl.type
- when AST::Typespecs::Int
- "Integer.unpack(unpacker)"
- when AST::Typespecs::UnsignedInt
- "UnsignedInteger.unpack(unpacker)"
- when AST::Typespecs::Hyper
- "Hyper.unpack(unpacker)"
- when AST::Typespecs::UnsignedHyper
- "UnsignedHyper.unpack(unpacker)"
- when AST::Typespecs::Float
- "Float.unpack(unpacker)"
- when AST::Typespecs::Double
- "Double.unpack(unpacker)"
- when AST::Typespecs::Quadruple
- raise "cannot render quadruple in Python"
- when AST::Typespecs::Bool
- "Boolean.unpack(unpacker)"
- when AST::Typespecs::Opaque
- "Opaque.unpack(unpacker, #{decl.size || MAX_SIZE}, #{decl.fixed? ? "True" : "False"})"
- when AST::Typespecs::String
- "String.unpack(unpacker)"
- when AST::Typespecs::Simple
- "#{name decl.type.resolved_type}.unpack(unpacker)"
- when AST::Concerns::NestedDefinition
- "#{name decl.type}.unpack(unpacker)"
- else
- raise "Unknown typespec: #{decl.type.class.name}"
- end
- end
-
- def render_source_comment(out, defn)
- return if defn.is_a?(AST::Definitions::Namespace)
-
- out.puts <<-EOS.strip_heredoc
- """
- XDR Source Code::
-
- EOS
- out.indent(2) do
- out.puts defn.text_value
- end
-
- out.puts '"""'
- end
-
- def render_const_source_comment(out, defn)
- return if defn.is_a?(AST::Definitions::Namespace)
- out.puts "#: #{defn.text_value}"
- end
-
- def type_hint_string(decl, container_name)
- type_hint = type_string decl.type
- if type_hint == container_name
- type_hint = "\"#{type_hint}\""
- end
-
- case decl.type.sub_type
- when :optional
- "Optional[#{type_hint}]"
- when :var_array, :array
- "List[#{type_hint}]"
- else
- type_hint
- end
- end
-
- def is_base_type(type)
- case type
- when AST::Typespecs::Bool,
- AST::Typespecs::Double,
- AST::Typespecs::Float,
- AST::Typespecs::Hyper,
- AST::Typespecs::Int,
- AST::Typespecs::Opaque,
- AST::Typespecs::String,
- AST::Typespecs::UnsignedHyper,
- AST::Typespecs::UnsignedInt
- true
- else
- false
- end
- end
-
- def type_string(type)
- case type
- when AST::Typespecs::Bool
- "bool"
- when AST::Typespecs::Double
- "float"
- when AST::Typespecs::Float
- "float"
- when AST::Typespecs::Hyper
- "int"
- when AST::Typespecs::Int
- "int"
- when AST::Typespecs::Opaque
- "bytes"
- when AST::Typespecs::Quadruple
- raise "no quadruple support for Python"
- when AST::Typespecs::String
- "bytes"
- when AST::Typespecs::UnsignedHyper
- "int"
- when AST::Typespecs::UnsignedInt
- "int"
- when AST::Typespecs::Simple
- name type
- when AST::Definitions::Base
- name type
- when AST::Concerns::NestedDefinition
- name type
- else
- raise "Unknown reference type: #{type.class.name}, #{type.class.ancestors}"
- end
- end
-
- def name(named)
- parent = name named.parent_defn if named.is_a?(AST::Concerns::NestedDefinition)
- result = named.name.camelize
- "#{parent}#{result}"
- end
- end
- end
-end
\ No newline at end of file
diff --git a/lib/xdrgen/generators/python/base.py b/lib/xdrgen/generators/python/base.py
deleted file mode 100644
index 65179b8f3..000000000
--- a/lib/xdrgen/generators/python/base.py
+++ /dev/null
@@ -1,252 +0,0 @@
-from xdrlib3 import Packer, Unpacker
-
-__all__ = [
- "Integer",
- "UnsignedInteger",
- "Float",
- "Double",
- "Hyper",
- "UnsignedHyper",
- "Boolean",
- "String",
- "Opaque",
-]
-
-
-class Integer:
- def __init__(self, value: int) -> None:
- self.value = value
-
- def pack(self, packer: Packer) -> None:
- packer.pack_int(self.value)
-
- @staticmethod
- def unpack(unpacker: Unpacker) -> int:
- return unpacker.unpack_int()
-
- def __hash__(self):
- return hash(self.value)
-
- def __eq__(self, other: object) -> bool:
- if not isinstance(other, self.__class__):
- return NotImplemented
- return self.value == other.value
-
- def __str__(self):
- return f"
- * enum AccountFlags
- * { // masks for each flag
- * AUTH_REQUIRED_FLAG = 0x1
- * };
- *
- */
-public enum AccountFlags implements XdrElement {
- AUTH_REQUIRED_FLAG(1);
-
- private final int value;
-
- AccountFlags(int value) {
- this.value = value;
- }
-
- public int getValue() {
- return value;
- }
-
- public static AccountFlags decode(XdrDataInputStream stream) throws IOException {
- int value = stream.readInt();
- switch (value) {
- case 1: return AUTH_REQUIRED_FLAG;
- default:
- throw new IllegalArgumentException("Unknown enum value: " + value);
- }
- }
-
- public void encode(XdrDataOutputStream stream) throws IOException {
- stream.writeInt(value);
- }
- public static AccountFlags fromXdrBase64(String xdr) throws IOException {
- byte[] bytes = Base64Factory.getInstance().decode(xdr);
- return fromXdrByteArray(bytes);
- }
-
- public static AccountFlags fromXdrByteArray(byte[] xdr) throws IOException {
- ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr);
- XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream);
- return decode(xdrDataInputStream);
- }
-}
diff --git a/spec/output/generator_spec_java/block_comments.x/Constants.java b/spec/output/generator_spec_java/block_comments.x/Constants.java
deleted file mode 100644
index d7d9f4cfc..000000000
--- a/spec/output/generator_spec_java/block_comments.x/Constants.java
+++ /dev/null
@@ -1,10 +0,0 @@
-// Automatically generated by xdrgen
-// DO NOT EDIT or your changes may be overwritten
-
-package MyXDR;
-
-import java.io.IOException;
-
-public final class Constants {
- private Constants() {}
-}
diff --git a/spec/output/generator_spec_java/block_comments.x/XdrDataInputStream.java b/spec/output/generator_spec_java/block_comments.x/XdrDataInputStream.java
deleted file mode 100644
index 6d6592026..000000000
--- a/spec/output/generator_spec_java/block_comments.x/XdrDataInputStream.java
+++ /dev/null
@@ -1,122 +0,0 @@
-package MyXDR;
-
-import java.io.DataInputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.nio.charset.Charset;
-
-public class XdrDataInputStream extends DataInputStream {
-
- // The underlying input stream
- private final XdrInputStream mIn;
-
- /**
- * Creates a XdrDataInputStream that uses the specified
- * underlying InputStream.
- *
- * @param in the specified input stream
- */
- public XdrDataInputStream(InputStream in) {
- super(new XdrInputStream(in));
- mIn = (XdrInputStream) super.in;
- }
-
- public int[] readIntArray() throws IOException {
- int l = readInt();
- return readIntArray(l);
- }
-
- private int[] readIntArray(int l) throws IOException {
- int[] arr = new int[l];
- for (int i = 0; i < l; i++) {
- arr[i] = readInt();
- }
- return arr;
- }
-
- public float[] readFloatArray() throws IOException {
- int l = readInt();
- return readFloatArray(l);
- }
-
- private float[] readFloatArray(int l) throws IOException {
- float[] arr = new float[l];
- for (int i = 0; i < l; i++) {
- arr[i] = readFloat();
- }
- return arr;
- }
-
- public double[] readDoubleArray() throws IOException {
- int l = readInt();
- return readDoubleArray(l);
- }
-
- private double[] readDoubleArray(int l) throws IOException {
- double[] arr = new double[l];
- for (int i = 0; i < l; i++) {
- arr[i] = readDouble();
- }
- return arr;
- }
-
- @Override
- public int read() throws IOException {
- return super.read();
- }
-
- /**
- * Need to provide a custom impl of InputStream as DataInputStream's read methods
- * are final and we need to keep track of the count for padding purposes.
- */
- private static final class XdrInputStream extends InputStream {
-
- // The underlying input stream
- private final InputStream mIn;
-
- // The amount of bytes read so far.
- private int mCount;
-
- public XdrInputStream(InputStream in) {
- mIn = in;
- mCount = 0;
- }
-
- @Override
- public int read() throws IOException {
- int read = mIn.read();
- if (read >= 0) {
- mCount++;
- }
- return read;
- }
-
- @Override
- public int read(byte[] b) throws IOException {
- return read(b, 0, b.length);
- }
-
- @Override
- public int read(byte[] b, int off, int len) throws IOException {
- int read = mIn.read(b, off, len);
- mCount += read;
- pad();
- return read;
- }
-
- public void pad() throws IOException {
- int pad = 0;
- int mod = mCount % 4;
- if (mod > 0) {
- pad = 4-mod;
- }
-
- while (pad-- > 0) {
- int b = read();
- if (b != 0) {
- throw new IOException("non-zero padding");
- }
- }
- }
- }
-}
diff --git a/spec/output/generator_spec_java/block_comments.x/XdrDataOutputStream.java b/spec/output/generator_spec_java/block_comments.x/XdrDataOutputStream.java
deleted file mode 100644
index 729aec05b..000000000
--- a/spec/output/generator_spec_java/block_comments.x/XdrDataOutputStream.java
+++ /dev/null
@@ -1,96 +0,0 @@
-package MyXDR;
-
-import java.io.DataOutputStream;
-import java.io.IOException;
-import java.io.OutputStream;
-import java.nio.charset.Charset;
-
-public class XdrDataOutputStream extends DataOutputStream {
-
- private final XdrOutputStream mOut;
-
- public XdrDataOutputStream(OutputStream out) {
- super(new XdrOutputStream(out));
- mOut = (XdrOutputStream) super.out;
- }
-
- public void writeIntArray(int[] a) throws IOException {
- writeInt(a.length);
- writeIntArray(a, a.length);
- }
-
- private void writeIntArray(int[] a, int l) throws IOException {
- for (int i = 0; i < l; i++) {
- writeInt(a[i]);
- }
- }
-
- public void writeFloatArray(float[] a) throws IOException {
- writeInt(a.length);
- writeFloatArray(a, a.length);
- }
-
- private void writeFloatArray(float[] a, int l) throws IOException {
- for (int i = 0; i < l; i++) {
- writeFloat(a[i]);
- }
- }
-
- public void writeDoubleArray(double[] a) throws IOException {
- writeInt(a.length);
- writeDoubleArray(a, a.length);
- }
-
- private void writeDoubleArray(double[] a, int l) throws IOException {
- for (int i = 0; i < l; i++) {
- writeDouble(a[i]);
- }
- }
-
- private static final class XdrOutputStream extends OutputStream {
-
- private final OutputStream mOut;
-
- // Number of bytes written
- private int mCount;
-
- public XdrOutputStream(OutputStream out) {
- mOut = out;
- mCount = 0;
- }
-
- @Override
- public void write(int b) throws IOException {
- mOut.write(b);
- // https://docs.oracle.com/javase/7/docs/api/java/io/OutputStream.html#write(int):
- // > The byte to be written is the eight low-order bits of the argument b.
- // > The 24 high-order bits of b are ignored.
- mCount++;
- }
-
- @Override
- public void write(byte[] b) throws IOException {
- // https://docs.oracle.com/javase/7/docs/api/java/io/OutputStream.html#write(byte[]):
- // > The general contract for write(b) is that it should have exactly the same effect
- // > as the call write(b, 0, b.length).
- write(b, 0, b.length);
- }
-
- public void write(byte[] b, int offset, int length) throws IOException {
- mOut.write(b, offset, length);
- mCount += length;
- pad();
- }
-
- public void pad() throws IOException {
- int pad = 0;
- int mod = mCount % 4;
- if (mod > 0) {
- pad = 4-mod;
- }
- while (pad-- > 0) {
- write(0);
- }
- }
- }
-}
diff --git a/spec/output/generator_spec_java/block_comments.x/XdrElement.java b/spec/output/generator_spec_java/block_comments.x/XdrElement.java
deleted file mode 100644
index 453491ea2..000000000
--- a/spec/output/generator_spec_java/block_comments.x/XdrElement.java
+++ /dev/null
@@ -1,21 +0,0 @@
-package MyXDR;
-
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import org.stellar.sdk.Base64Factory;
-
-/** Common parent interface for all generated classes. */
-interface XdrElement {
- void encode(XdrDataOutputStream stream) throws IOException;
-
- default String toXdrBase64() throws IOException {
- return Base64Factory.getInstance().encodeToString(toXdrByteArray());
- }
-
- default byte[] toXdrByteArray() throws IOException {
- ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
- XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream);
- encode(xdrDataOutputStream);
- return byteArrayOutputStream.toByteArray();
- }
-}
diff --git a/spec/output/generator_spec_java/block_comments.x/XdrString.java b/spec/output/generator_spec_java/block_comments.x/XdrString.java
deleted file mode 100644
index a51eead77..000000000
--- a/spec/output/generator_spec_java/block_comments.x/XdrString.java
+++ /dev/null
@@ -1,62 +0,0 @@
-package MyXDR;
-
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import java.io.InvalidClassException;
-import java.nio.charset.StandardCharsets;
-import lombok.Value;
-import org.stellar.sdk.Base64Factory;
-
-@Value
-public class XdrString implements XdrElement {
- byte[] bytes;
-
- public XdrString(byte[] bytes) {
- this.bytes = bytes;
- }
-
- public XdrString(String text) {
- this.bytes = text.getBytes(StandardCharsets.UTF_8);
- }
-
- @Override
- public void encode(XdrDataOutputStream stream) throws IOException {
- stream.writeInt(this.bytes.length);
- stream.write(this.bytes, 0, this.bytes.length);
- }
-
- public static XdrString decode(XdrDataInputStream stream, int maxSize) throws IOException {
- int size = stream.readInt();
- if (size > maxSize) {
- throw new IllegalArgumentException("String length " + size + " exceeds max size " + maxSize);
- }
- byte[] bytes = new byte[size];
- stream.read(bytes);
- return new XdrString(bytes);
- }
-
- public static XdrString fromXdrBase64(String xdr, int maxSize) throws IOException {
- byte[] bytes = Base64Factory.getInstance().decode(xdr);
- return fromXdrByteArray(bytes, maxSize);
- }
-
- public static XdrString fromXdrBase64(String xdr) throws IOException {
- return fromXdrBase64(xdr, Integer.MAX_VALUE);
- }
-
- public static XdrString fromXdrByteArray(byte[] xdr, int maxSize) throws IOException {
- ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr);
- XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream);
- return decode(xdrDataInputStream, maxSize);
- }
-
- public static XdrString fromXdrByteArray(byte[] xdr) throws IOException {
- return fromXdrByteArray(xdr, Integer.MAX_VALUE);
- }
-
- @Override
- public String toString() {
- return new String(bytes, StandardCharsets.UTF_8);
- }
-}
diff --git a/spec/output/generator_spec_java/block_comments.x/XdrUnsignedHyperInteger.java b/spec/output/generator_spec_java/block_comments.x/XdrUnsignedHyperInteger.java
deleted file mode 100644
index 5d798cded..000000000
--- a/spec/output/generator_spec_java/block_comments.x/XdrUnsignedHyperInteger.java
+++ /dev/null
@@ -1,69 +0,0 @@
-package MyXDR;
-
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import java.math.BigInteger;
-import lombok.Value;
-import org.stellar.sdk.Base64Factory;
-
-/**
- * Represents XDR Unsigned Hyper Integer.
- *
- * @see XDR: External Data
- * Representation Standard
- */
-@Value
-public class XdrUnsignedHyperInteger implements XdrElement {
- public static final BigInteger MAX_VALUE = new BigInteger("18446744073709551615");
- public static final BigInteger MIN_VALUE = BigInteger.ZERO;
- BigInteger number;
-
- public XdrUnsignedHyperInteger(BigInteger number) {
- if (number.compareTo(MIN_VALUE) < 0 || number.compareTo(MAX_VALUE) > 0) {
- throw new IllegalArgumentException("number must be between 0 and 2^64 - 1 inclusive");
- }
- this.number = number;
- }
-
- public XdrUnsignedHyperInteger(Long number) {
- if (number < 0) {
- throw new IllegalArgumentException(
- "number must be greater than or equal to 0 if you want to construct it from Long");
- }
- this.number = BigInteger.valueOf(number);
- }
-
- @Override
- public void encode(XdrDataOutputStream stream) throws IOException {
- stream.write(getBytes());
- }
-
- public static XdrUnsignedHyperInteger decode(XdrDataInputStream stream) throws IOException {
- byte[] bytes = new byte[8];
- stream.readFully(bytes);
- BigInteger uint64 = new BigInteger(1, bytes);
- return new XdrUnsignedHyperInteger(uint64);
- }
-
- private byte[] getBytes() {
- byte[] bytes = number.toByteArray();
- byte[] paddedBytes = new byte[8];
-
- int numBytesToCopy = Math.min(bytes.length, 8);
- int copyStartIndex = bytes.length - numBytesToCopy;
- System.arraycopy(bytes, copyStartIndex, paddedBytes, 8 - numBytesToCopy, numBytesToCopy);
- return paddedBytes;
- }
-
- public static XdrUnsignedHyperInteger fromXdrBase64(String xdr) throws IOException {
- byte[] bytes = Base64Factory.getInstance().decode(xdr);
- return fromXdrByteArray(bytes);
- }
-
- public static XdrUnsignedHyperInteger fromXdrByteArray(byte[] xdr) throws IOException {
- ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr);
- XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream);
- return decode(xdrDataInputStream);
- }
-}
diff --git a/spec/output/generator_spec_java/block_comments.x/XdrUnsignedInteger.java b/spec/output/generator_spec_java/block_comments.x/XdrUnsignedInteger.java
deleted file mode 100644
index bea880aee..000000000
--- a/spec/output/generator_spec_java/block_comments.x/XdrUnsignedInteger.java
+++ /dev/null
@@ -1,57 +0,0 @@
-package MyXDR;
-
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import lombok.Value;
-import org.stellar.sdk.Base64Factory;
-
-/**
- * Represents XDR Unsigned Integer.
- *
- * @see XDR: External Data
- * Representation Standard
- */
-@Value
-public class XdrUnsignedInteger implements XdrElement {
- public static final long MAX_VALUE = (1L << 32) - 1;
- public static final long MIN_VALUE = 0;
- Long number;
-
- public XdrUnsignedInteger(Long number) {
- if (number < MIN_VALUE || number > MAX_VALUE) {
- throw new IllegalArgumentException("number must be between 0 and 2^32 - 1 inclusive");
- }
- this.number = number;
- }
-
- public XdrUnsignedInteger(Integer number) {
- if (number < 0) {
- throw new IllegalArgumentException(
- "number must be greater than or equal to 0 if you want to construct it from Integer");
- }
- this.number = number.longValue();
- }
-
- public static XdrUnsignedInteger decode(XdrDataInputStream stream) throws IOException {
- int intValue = stream.readInt();
- long uint32Value = Integer.toUnsignedLong(intValue);
- return new XdrUnsignedInteger(uint32Value);
- }
-
- @Override
- public void encode(XdrDataOutputStream stream) throws IOException {
- stream.writeInt(number.intValue());
- }
-
- public static XdrUnsignedInteger fromXdrBase64(String xdr) throws IOException {
- byte[] bytes = Base64Factory.getInstance().decode(xdr);
- return fromXdrByteArray(bytes);
- }
-
- public static XdrUnsignedInteger fromXdrByteArray(byte[] xdr) throws IOException {
- ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr);
- XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream);
- return decode(xdrDataInputStream);
- }
-}
diff --git a/spec/output/generator_spec_java/const.x/Constants.java b/spec/output/generator_spec_java/const.x/Constants.java
deleted file mode 100644
index 1e2b80847..000000000
--- a/spec/output/generator_spec_java/const.x/Constants.java
+++ /dev/null
@@ -1,11 +0,0 @@
-// Automatically generated by xdrgen
-// DO NOT EDIT or your changes may be overwritten
-
-package MyXDR;
-
-import java.io.IOException;
-
-public final class Constants {
- private Constants() {}
- public static final int FOO = 1;
-}
diff --git a/spec/output/generator_spec_java/const.x/TestArray.java b/spec/output/generator_spec_java/const.x/TestArray.java
deleted file mode 100644
index 212c7cc38..000000000
--- a/spec/output/generator_spec_java/const.x/TestArray.java
+++ /dev/null
@@ -1,53 +0,0 @@
-// Automatically generated by xdrgen
-// DO NOT EDIT or your changes may be overwritten
-
-package MyXDR;
-
-import java.io.IOException;
-
-import org.stellar.sdk.Base64Factory;
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import lombok.Data;
-import lombok.NoArgsConstructor;
-import lombok.AllArgsConstructor;
-
-/**
- * TestArray's original definition in the XDR file is:
- * - * typedef int TestArray[FOO]; - *- */ -@Data -@NoArgsConstructor -@AllArgsConstructor -public class TestArray implements XdrElement { - private Integer[] TestArray; - public void encode(XdrDataOutputStream stream) throws IOException { - int TestArraySize = getTestArray().length; - for (int i = 0; i < TestArraySize; i++) { - stream.writeInt(TestArray[i]); - } - } - - public static TestArray decode(XdrDataInputStream stream) throws IOException { - TestArray decodedTestArray = new TestArray(); - int TestArraySize = Constants.FOO; - decodedTestArray.TestArray = new Integer[TestArraySize]; - for (int i = 0; i < TestArraySize; i++) { - decodedTestArray.TestArray[i] = stream.readInt(); - } - return decodedTestArray; - } - - public static TestArray fromXdrBase64(String xdr) throws IOException { - byte[] bytes = Base64Factory.getInstance().decode(xdr); - return fromXdrByteArray(bytes); - } - - public static TestArray fromXdrByteArray(byte[] xdr) throws IOException { - ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); - XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); - return decode(xdrDataInputStream); - } -} diff --git a/spec/output/generator_spec_java/const.x/TestArray2.java b/spec/output/generator_spec_java/const.x/TestArray2.java deleted file mode 100644 index 13212a0b3..000000000 --- a/spec/output/generator_spec_java/const.x/TestArray2.java +++ /dev/null @@ -1,54 +0,0 @@ -// Automatically generated by xdrgen -// DO NOT EDIT or your changes may be overwritten - -package MyXDR; - -import java.io.IOException; - -import org.stellar.sdk.Base64Factory; -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; -import lombok.Data; -import lombok.NoArgsConstructor; -import lombok.AllArgsConstructor; - -/** - * TestArray2's original definition in the XDR file is: - *
- * typedef int TestArray2<FOO>; - *- */ -@Data -@NoArgsConstructor -@AllArgsConstructor -public class TestArray2 implements XdrElement { - private Integer[] TestArray2; - public void encode(XdrDataOutputStream stream) throws IOException { - int TestArray2Size = getTestArray2().length; - stream.writeInt(TestArray2Size); - for (int i = 0; i < TestArray2Size; i++) { - stream.writeInt(TestArray2[i]); - } - } - - public static TestArray2 decode(XdrDataInputStream stream) throws IOException { - TestArray2 decodedTestArray2 = new TestArray2(); - int TestArray2Size = stream.readInt(); - decodedTestArray2.TestArray2 = new Integer[TestArray2Size]; - for (int i = 0; i < TestArray2Size; i++) { - decodedTestArray2.TestArray2[i] = stream.readInt(); - } - return decodedTestArray2; - } - - public static TestArray2 fromXdrBase64(String xdr) throws IOException { - byte[] bytes = Base64Factory.getInstance().decode(xdr); - return fromXdrByteArray(bytes); - } - - public static TestArray2 fromXdrByteArray(byte[] xdr) throws IOException { - ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); - XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); - return decode(xdrDataInputStream); - } -} diff --git a/spec/output/generator_spec_java/const.x/XdrDataInputStream.java b/spec/output/generator_spec_java/const.x/XdrDataInputStream.java deleted file mode 100644 index 6d6592026..000000000 --- a/spec/output/generator_spec_java/const.x/XdrDataInputStream.java +++ /dev/null @@ -1,122 +0,0 @@ -package MyXDR; - -import java.io.DataInputStream; -import java.io.IOException; -import java.io.InputStream; -import java.nio.charset.Charset; - -public class XdrDataInputStream extends DataInputStream { - - // The underlying input stream - private final XdrInputStream mIn; - - /** - * Creates a XdrDataInputStream that uses the specified - * underlying InputStream. - * - * @param in the specified input stream - */ - public XdrDataInputStream(InputStream in) { - super(new XdrInputStream(in)); - mIn = (XdrInputStream) super.in; - } - - public int[] readIntArray() throws IOException { - int l = readInt(); - return readIntArray(l); - } - - private int[] readIntArray(int l) throws IOException { - int[] arr = new int[l]; - for (int i = 0; i < l; i++) { - arr[i] = readInt(); - } - return arr; - } - - public float[] readFloatArray() throws IOException { - int l = readInt(); - return readFloatArray(l); - } - - private float[] readFloatArray(int l) throws IOException { - float[] arr = new float[l]; - for (int i = 0; i < l; i++) { - arr[i] = readFloat(); - } - return arr; - } - - public double[] readDoubleArray() throws IOException { - int l = readInt(); - return readDoubleArray(l); - } - - private double[] readDoubleArray(int l) throws IOException { - double[] arr = new double[l]; - for (int i = 0; i < l; i++) { - arr[i] = readDouble(); - } - return arr; - } - - @Override - public int read() throws IOException { - return super.read(); - } - - /** - * Need to provide a custom impl of InputStream as DataInputStream's read methods - * are final and we need to keep track of the count for padding purposes. - */ - private static final class XdrInputStream extends InputStream { - - // The underlying input stream - private final InputStream mIn; - - // The amount of bytes read so far. - private int mCount; - - public XdrInputStream(InputStream in) { - mIn = in; - mCount = 0; - } - - @Override - public int read() throws IOException { - int read = mIn.read(); - if (read >= 0) { - mCount++; - } - return read; - } - - @Override - public int read(byte[] b) throws IOException { - return read(b, 0, b.length); - } - - @Override - public int read(byte[] b, int off, int len) throws IOException { - int read = mIn.read(b, off, len); - mCount += read; - pad(); - return read; - } - - public void pad() throws IOException { - int pad = 0; - int mod = mCount % 4; - if (mod > 0) { - pad = 4-mod; - } - - while (pad-- > 0) { - int b = read(); - if (b != 0) { - throw new IOException("non-zero padding"); - } - } - } - } -} diff --git a/spec/output/generator_spec_java/const.x/XdrDataOutputStream.java b/spec/output/generator_spec_java/const.x/XdrDataOutputStream.java deleted file mode 100644 index 729aec05b..000000000 --- a/spec/output/generator_spec_java/const.x/XdrDataOutputStream.java +++ /dev/null @@ -1,96 +0,0 @@ -package MyXDR; - -import java.io.DataOutputStream; -import java.io.IOException; -import java.io.OutputStream; -import java.nio.charset.Charset; - -public class XdrDataOutputStream extends DataOutputStream { - - private final XdrOutputStream mOut; - - public XdrDataOutputStream(OutputStream out) { - super(new XdrOutputStream(out)); - mOut = (XdrOutputStream) super.out; - } - - public void writeIntArray(int[] a) throws IOException { - writeInt(a.length); - writeIntArray(a, a.length); - } - - private void writeIntArray(int[] a, int l) throws IOException { - for (int i = 0; i < l; i++) { - writeInt(a[i]); - } - } - - public void writeFloatArray(float[] a) throws IOException { - writeInt(a.length); - writeFloatArray(a, a.length); - } - - private void writeFloatArray(float[] a, int l) throws IOException { - for (int i = 0; i < l; i++) { - writeFloat(a[i]); - } - } - - public void writeDoubleArray(double[] a) throws IOException { - writeInt(a.length); - writeDoubleArray(a, a.length); - } - - private void writeDoubleArray(double[] a, int l) throws IOException { - for (int i = 0; i < l; i++) { - writeDouble(a[i]); - } - } - - private static final class XdrOutputStream extends OutputStream { - - private final OutputStream mOut; - - // Number of bytes written - private int mCount; - - public XdrOutputStream(OutputStream out) { - mOut = out; - mCount = 0; - } - - @Override - public void write(int b) throws IOException { - mOut.write(b); - // https://docs.oracle.com/javase/7/docs/api/java/io/OutputStream.html#write(int): - // > The byte to be written is the eight low-order bits of the argument b. - // > The 24 high-order bits of b are ignored. - mCount++; - } - - @Override - public void write(byte[] b) throws IOException { - // https://docs.oracle.com/javase/7/docs/api/java/io/OutputStream.html#write(byte[]): - // > The general contract for write(b) is that it should have exactly the same effect - // > as the call write(b, 0, b.length). - write(b, 0, b.length); - } - - public void write(byte[] b, int offset, int length) throws IOException { - mOut.write(b, offset, length); - mCount += length; - pad(); - } - - public void pad() throws IOException { - int pad = 0; - int mod = mCount % 4; - if (mod > 0) { - pad = 4-mod; - } - while (pad-- > 0) { - write(0); - } - } - } -} diff --git a/spec/output/generator_spec_java/const.x/XdrElement.java b/spec/output/generator_spec_java/const.x/XdrElement.java deleted file mode 100644 index 453491ea2..000000000 --- a/spec/output/generator_spec_java/const.x/XdrElement.java +++ /dev/null @@ -1,21 +0,0 @@ -package MyXDR; - -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import org.stellar.sdk.Base64Factory; - -/** Common parent interface for all generated classes. */ -interface XdrElement { - void encode(XdrDataOutputStream stream) throws IOException; - - default String toXdrBase64() throws IOException { - return Base64Factory.getInstance().encodeToString(toXdrByteArray()); - } - - default byte[] toXdrByteArray() throws IOException { - ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); - XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); - encode(xdrDataOutputStream); - return byteArrayOutputStream.toByteArray(); - } -} diff --git a/spec/output/generator_spec_java/const.x/XdrString.java b/spec/output/generator_spec_java/const.x/XdrString.java deleted file mode 100644 index a51eead77..000000000 --- a/spec/output/generator_spec_java/const.x/XdrString.java +++ /dev/null @@ -1,62 +0,0 @@ -package MyXDR; - -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.io.InvalidClassException; -import java.nio.charset.StandardCharsets; -import lombok.Value; -import org.stellar.sdk.Base64Factory; - -@Value -public class XdrString implements XdrElement { - byte[] bytes; - - public XdrString(byte[] bytes) { - this.bytes = bytes; - } - - public XdrString(String text) { - this.bytes = text.getBytes(StandardCharsets.UTF_8); - } - - @Override - public void encode(XdrDataOutputStream stream) throws IOException { - stream.writeInt(this.bytes.length); - stream.write(this.bytes, 0, this.bytes.length); - } - - public static XdrString decode(XdrDataInputStream stream, int maxSize) throws IOException { - int size = stream.readInt(); - if (size > maxSize) { - throw new IllegalArgumentException("String length " + size + " exceeds max size " + maxSize); - } - byte[] bytes = new byte[size]; - stream.read(bytes); - return new XdrString(bytes); - } - - public static XdrString fromXdrBase64(String xdr, int maxSize) throws IOException { - byte[] bytes = Base64Factory.getInstance().decode(xdr); - return fromXdrByteArray(bytes, maxSize); - } - - public static XdrString fromXdrBase64(String xdr) throws IOException { - return fromXdrBase64(xdr, Integer.MAX_VALUE); - } - - public static XdrString fromXdrByteArray(byte[] xdr, int maxSize) throws IOException { - ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); - XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); - return decode(xdrDataInputStream, maxSize); - } - - public static XdrString fromXdrByteArray(byte[] xdr) throws IOException { - return fromXdrByteArray(xdr, Integer.MAX_VALUE); - } - - @Override - public String toString() { - return new String(bytes, StandardCharsets.UTF_8); - } -} diff --git a/spec/output/generator_spec_java/const.x/XdrUnsignedHyperInteger.java b/spec/output/generator_spec_java/const.x/XdrUnsignedHyperInteger.java deleted file mode 100644 index 5d798cded..000000000 --- a/spec/output/generator_spec_java/const.x/XdrUnsignedHyperInteger.java +++ /dev/null @@ -1,69 +0,0 @@ -package MyXDR; - -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.math.BigInteger; -import lombok.Value; -import org.stellar.sdk.Base64Factory; - -/** - * Represents XDR Unsigned Hyper Integer. - * - * @see XDR: External Data - * Representation Standard - */ -@Value -public class XdrUnsignedHyperInteger implements XdrElement { - public static final BigInteger MAX_VALUE = new BigInteger("18446744073709551615"); - public static final BigInteger MIN_VALUE = BigInteger.ZERO; - BigInteger number; - - public XdrUnsignedHyperInteger(BigInteger number) { - if (number.compareTo(MIN_VALUE) < 0 || number.compareTo(MAX_VALUE) > 0) { - throw new IllegalArgumentException("number must be between 0 and 2^64 - 1 inclusive"); - } - this.number = number; - } - - public XdrUnsignedHyperInteger(Long number) { - if (number < 0) { - throw new IllegalArgumentException( - "number must be greater than or equal to 0 if you want to construct it from Long"); - } - this.number = BigInteger.valueOf(number); - } - - @Override - public void encode(XdrDataOutputStream stream) throws IOException { - stream.write(getBytes()); - } - - public static XdrUnsignedHyperInteger decode(XdrDataInputStream stream) throws IOException { - byte[] bytes = new byte[8]; - stream.readFully(bytes); - BigInteger uint64 = new BigInteger(1, bytes); - return new XdrUnsignedHyperInteger(uint64); - } - - private byte[] getBytes() { - byte[] bytes = number.toByteArray(); - byte[] paddedBytes = new byte[8]; - - int numBytesToCopy = Math.min(bytes.length, 8); - int copyStartIndex = bytes.length - numBytesToCopy; - System.arraycopy(bytes, copyStartIndex, paddedBytes, 8 - numBytesToCopy, numBytesToCopy); - return paddedBytes; - } - - public static XdrUnsignedHyperInteger fromXdrBase64(String xdr) throws IOException { - byte[] bytes = Base64Factory.getInstance().decode(xdr); - return fromXdrByteArray(bytes); - } - - public static XdrUnsignedHyperInteger fromXdrByteArray(byte[] xdr) throws IOException { - ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); - XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); - return decode(xdrDataInputStream); - } -} diff --git a/spec/output/generator_spec_java/const.x/XdrUnsignedInteger.java b/spec/output/generator_spec_java/const.x/XdrUnsignedInteger.java deleted file mode 100644 index bea880aee..000000000 --- a/spec/output/generator_spec_java/const.x/XdrUnsignedInteger.java +++ /dev/null @@ -1,57 +0,0 @@ -package MyXDR; - -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import lombok.Value; -import org.stellar.sdk.Base64Factory; - -/** - * Represents XDR Unsigned Integer. - * - * @see XDR: External Data - * Representation Standard - */ -@Value -public class XdrUnsignedInteger implements XdrElement { - public static final long MAX_VALUE = (1L << 32) - 1; - public static final long MIN_VALUE = 0; - Long number; - - public XdrUnsignedInteger(Long number) { - if (number < MIN_VALUE || number > MAX_VALUE) { - throw new IllegalArgumentException("number must be between 0 and 2^32 - 1 inclusive"); - } - this.number = number; - } - - public XdrUnsignedInteger(Integer number) { - if (number < 0) { - throw new IllegalArgumentException( - "number must be greater than or equal to 0 if you want to construct it from Integer"); - } - this.number = number.longValue(); - } - - public static XdrUnsignedInteger decode(XdrDataInputStream stream) throws IOException { - int intValue = stream.readInt(); - long uint32Value = Integer.toUnsignedLong(intValue); - return new XdrUnsignedInteger(uint32Value); - } - - @Override - public void encode(XdrDataOutputStream stream) throws IOException { - stream.writeInt(number.intValue()); - } - - public static XdrUnsignedInteger fromXdrBase64(String xdr) throws IOException { - byte[] bytes = Base64Factory.getInstance().decode(xdr); - return fromXdrByteArray(bytes); - } - - public static XdrUnsignedInteger fromXdrByteArray(byte[] xdr) throws IOException { - ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); - XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); - return decode(xdrDataInputStream); - } -} diff --git a/spec/output/generator_spec_java/enum.x/Color.java b/spec/output/generator_spec_java/enum.x/Color.java deleted file mode 100644 index 55a7f5587..000000000 --- a/spec/output/generator_spec_java/enum.x/Color.java +++ /dev/null @@ -1,61 +0,0 @@ -// Automatically generated by xdrgen -// DO NOT EDIT or your changes may be overwritten - -package MyXDR; - -import java.io.IOException; - -import org.stellar.sdk.Base64Factory; -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; - -/** - * Color's original definition in the XDR file is: - *
- * enum Color {
- * RED=0,
- * GREEN=1,
- * BLUE=2
- * };
- *
- */
-public enum Color implements XdrElement {
- RED(0),
- GREEN(1),
- BLUE(2);
-
- private final int value;
-
- Color(int value) {
- this.value = value;
- }
-
- public int getValue() {
- return value;
- }
-
- public static Color decode(XdrDataInputStream stream) throws IOException {
- int value = stream.readInt();
- switch (value) {
- case 0: return RED;
- case 1: return GREEN;
- case 2: return BLUE;
- default:
- throw new IllegalArgumentException("Unknown enum value: " + value);
- }
- }
-
- public void encode(XdrDataOutputStream stream) throws IOException {
- stream.writeInt(value);
- }
- public static Color fromXdrBase64(String xdr) throws IOException {
- byte[] bytes = Base64Factory.getInstance().decode(xdr);
- return fromXdrByteArray(bytes);
- }
-
- public static Color fromXdrByteArray(byte[] xdr) throws IOException {
- ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr);
- XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream);
- return decode(xdrDataInputStream);
- }
-}
diff --git a/spec/output/generator_spec_java/enum.x/Color2.java b/spec/output/generator_spec_java/enum.x/Color2.java
deleted file mode 100644
index 57053ce2f..000000000
--- a/spec/output/generator_spec_java/enum.x/Color2.java
+++ /dev/null
@@ -1,61 +0,0 @@
-// Automatically generated by xdrgen
-// DO NOT EDIT or your changes may be overwritten
-
-package MyXDR;
-
-import java.io.IOException;
-
-import org.stellar.sdk.Base64Factory;
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-
-/**
- * Color2's original definition in the XDR file is:
- *
- * enum Color2 {
- * RED2=RED,
- * GREEN2=1,
- * BLUE2=2
- * };
- *
- */
-public enum Color2 implements XdrElement {
- RED2(0),
- GREEN2(1),
- BLUE2(2);
-
- private final int value;
-
- Color2(int value) {
- this.value = value;
- }
-
- public int getValue() {
- return value;
- }
-
- public static Color2 decode(XdrDataInputStream stream) throws IOException {
- int value = stream.readInt();
- switch (value) {
- case 0: return RED2;
- case 1: return GREEN2;
- case 2: return BLUE2;
- default:
- throw new IllegalArgumentException("Unknown enum value: " + value);
- }
- }
-
- public void encode(XdrDataOutputStream stream) throws IOException {
- stream.writeInt(value);
- }
- public static Color2 fromXdrBase64(String xdr) throws IOException {
- byte[] bytes = Base64Factory.getInstance().decode(xdr);
- return fromXdrByteArray(bytes);
- }
-
- public static Color2 fromXdrByteArray(byte[] xdr) throws IOException {
- ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr);
- XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream);
- return decode(xdrDataInputStream);
- }
-}
diff --git a/spec/output/generator_spec_java/enum.x/Color3.java b/spec/output/generator_spec_java/enum.x/Color3.java
deleted file mode 100644
index 210d964db..000000000
--- a/spec/output/generator_spec_java/enum.x/Color3.java
+++ /dev/null
@@ -1,61 +0,0 @@
-// Automatically generated by xdrgen
-// DO NOT EDIT or your changes may be overwritten
-
-package MyXDR;
-
-import java.io.IOException;
-
-import org.stellar.sdk.Base64Factory;
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-
-/**
- * Color3's original definition in the XDR file is:
- *
- * enum Color3 {
- * RED_1=1,
- * RED_2_TWO=2,
- * RED_3=3
- * };
- *
- */
-public enum Color3 implements XdrElement {
- RED_1(1),
- RED_2_TWO(2),
- RED_3(3);
-
- private final int value;
-
- Color3(int value) {
- this.value = value;
- }
-
- public int getValue() {
- return value;
- }
-
- public static Color3 decode(XdrDataInputStream stream) throws IOException {
- int value = stream.readInt();
- switch (value) {
- case 1: return RED_1;
- case 2: return RED_2_TWO;
- case 3: return RED_3;
- default:
- throw new IllegalArgumentException("Unknown enum value: " + value);
- }
- }
-
- public void encode(XdrDataOutputStream stream) throws IOException {
- stream.writeInt(value);
- }
- public static Color3 fromXdrBase64(String xdr) throws IOException {
- byte[] bytes = Base64Factory.getInstance().decode(xdr);
- return fromXdrByteArray(bytes);
- }
-
- public static Color3 fromXdrByteArray(byte[] xdr) throws IOException {
- ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr);
- XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream);
- return decode(xdrDataInputStream);
- }
-}
diff --git a/spec/output/generator_spec_java/enum.x/Constants.java b/spec/output/generator_spec_java/enum.x/Constants.java
deleted file mode 100644
index d7d9f4cfc..000000000
--- a/spec/output/generator_spec_java/enum.x/Constants.java
+++ /dev/null
@@ -1,10 +0,0 @@
-// Automatically generated by xdrgen
-// DO NOT EDIT or your changes may be overwritten
-
-package MyXDR;
-
-import java.io.IOException;
-
-public final class Constants {
- private Constants() {}
-}
diff --git a/spec/output/generator_spec_java/enum.x/MessageType.java b/spec/output/generator_spec_java/enum.x/MessageType.java
deleted file mode 100644
index 1ea906d4b..000000000
--- a/spec/output/generator_spec_java/enum.x/MessageType.java
+++ /dev/null
@@ -1,101 +0,0 @@
-// Automatically generated by xdrgen
-// DO NOT EDIT or your changes may be overwritten
-
-package MyXDR;
-
-import java.io.IOException;
-
-import org.stellar.sdk.Base64Factory;
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-
-/**
- * MessageType's original definition in the XDR file is:
- *
- * enum MessageType
- * {
- * ERROR_MSG,
- * HELLO,
- * DONT_HAVE,
- *
- * GET_PEERS, // gets a list of peers this guy knows about
- * PEERS,
- *
- * GET_TX_SET, // gets a particular txset by hash
- * TX_SET,
- *
- * GET_VALIDATIONS, // gets validations for a given ledger hash
- * VALIDATIONS,
- *
- * TRANSACTION, //pass on a tx you have heard about
- * JSON_TRANSACTION,
- *
- * // FBA
- * GET_FBA_QUORUMSET,
- * FBA_QUORUMSET,
- * FBA_MESSAGE
- * };
- *
- */
-public enum MessageType implements XdrElement {
- ERROR_MSG(0),
- HELLO(1),
- DONT_HAVE(2),
- GET_PEERS(3),
- PEERS(4),
- GET_TX_SET(5),
- TX_SET(6),
- GET_VALIDATIONS(7),
- VALIDATIONS(8),
- TRANSACTION(9),
- JSON_TRANSACTION(10),
- GET_FBA_QUORUMSET(11),
- FBA_QUORUMSET(12),
- FBA_MESSAGE(13);
-
- private final int value;
-
- MessageType(int value) {
- this.value = value;
- }
-
- public int getValue() {
- return value;
- }
-
- public static MessageType decode(XdrDataInputStream stream) throws IOException {
- int value = stream.readInt();
- switch (value) {
- case 0: return ERROR_MSG;
- case 1: return HELLO;
- case 2: return DONT_HAVE;
- case 3: return GET_PEERS;
- case 4: return PEERS;
- case 5: return GET_TX_SET;
- case 6: return TX_SET;
- case 7: return GET_VALIDATIONS;
- case 8: return VALIDATIONS;
- case 9: return TRANSACTION;
- case 10: return JSON_TRANSACTION;
- case 11: return GET_FBA_QUORUMSET;
- case 12: return FBA_QUORUMSET;
- case 13: return FBA_MESSAGE;
- default:
- throw new IllegalArgumentException("Unknown enum value: " + value);
- }
- }
-
- public void encode(XdrDataOutputStream stream) throws IOException {
- stream.writeInt(value);
- }
- public static MessageType fromXdrBase64(String xdr) throws IOException {
- byte[] bytes = Base64Factory.getInstance().decode(xdr);
- return fromXdrByteArray(bytes);
- }
-
- public static MessageType fromXdrByteArray(byte[] xdr) throws IOException {
- ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr);
- XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream);
- return decode(xdrDataInputStream);
- }
-}
diff --git a/spec/output/generator_spec_java/enum.x/XdrDataInputStream.java b/spec/output/generator_spec_java/enum.x/XdrDataInputStream.java
deleted file mode 100644
index 6d6592026..000000000
--- a/spec/output/generator_spec_java/enum.x/XdrDataInputStream.java
+++ /dev/null
@@ -1,122 +0,0 @@
-package MyXDR;
-
-import java.io.DataInputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.nio.charset.Charset;
-
-public class XdrDataInputStream extends DataInputStream {
-
- // The underlying input stream
- private final XdrInputStream mIn;
-
- /**
- * Creates a XdrDataInputStream that uses the specified
- * underlying InputStream.
- *
- * @param in the specified input stream
- */
- public XdrDataInputStream(InputStream in) {
- super(new XdrInputStream(in));
- mIn = (XdrInputStream) super.in;
- }
-
- public int[] readIntArray() throws IOException {
- int l = readInt();
- return readIntArray(l);
- }
-
- private int[] readIntArray(int l) throws IOException {
- int[] arr = new int[l];
- for (int i = 0; i < l; i++) {
- arr[i] = readInt();
- }
- return arr;
- }
-
- public float[] readFloatArray() throws IOException {
- int l = readInt();
- return readFloatArray(l);
- }
-
- private float[] readFloatArray(int l) throws IOException {
- float[] arr = new float[l];
- for (int i = 0; i < l; i++) {
- arr[i] = readFloat();
- }
- return arr;
- }
-
- public double[] readDoubleArray() throws IOException {
- int l = readInt();
- return readDoubleArray(l);
- }
-
- private double[] readDoubleArray(int l) throws IOException {
- double[] arr = new double[l];
- for (int i = 0; i < l; i++) {
- arr[i] = readDouble();
- }
- return arr;
- }
-
- @Override
- public int read() throws IOException {
- return super.read();
- }
-
- /**
- * Need to provide a custom impl of InputStream as DataInputStream's read methods
- * are final and we need to keep track of the count for padding purposes.
- */
- private static final class XdrInputStream extends InputStream {
-
- // The underlying input stream
- private final InputStream mIn;
-
- // The amount of bytes read so far.
- private int mCount;
-
- public XdrInputStream(InputStream in) {
- mIn = in;
- mCount = 0;
- }
-
- @Override
- public int read() throws IOException {
- int read = mIn.read();
- if (read >= 0) {
- mCount++;
- }
- return read;
- }
-
- @Override
- public int read(byte[] b) throws IOException {
- return read(b, 0, b.length);
- }
-
- @Override
- public int read(byte[] b, int off, int len) throws IOException {
- int read = mIn.read(b, off, len);
- mCount += read;
- pad();
- return read;
- }
-
- public void pad() throws IOException {
- int pad = 0;
- int mod = mCount % 4;
- if (mod > 0) {
- pad = 4-mod;
- }
-
- while (pad-- > 0) {
- int b = read();
- if (b != 0) {
- throw new IOException("non-zero padding");
- }
- }
- }
- }
-}
diff --git a/spec/output/generator_spec_java/enum.x/XdrDataOutputStream.java b/spec/output/generator_spec_java/enum.x/XdrDataOutputStream.java
deleted file mode 100644
index 729aec05b..000000000
--- a/spec/output/generator_spec_java/enum.x/XdrDataOutputStream.java
+++ /dev/null
@@ -1,96 +0,0 @@
-package MyXDR;
-
-import java.io.DataOutputStream;
-import java.io.IOException;
-import java.io.OutputStream;
-import java.nio.charset.Charset;
-
-public class XdrDataOutputStream extends DataOutputStream {
-
- private final XdrOutputStream mOut;
-
- public XdrDataOutputStream(OutputStream out) {
- super(new XdrOutputStream(out));
- mOut = (XdrOutputStream) super.out;
- }
-
- public void writeIntArray(int[] a) throws IOException {
- writeInt(a.length);
- writeIntArray(a, a.length);
- }
-
- private void writeIntArray(int[] a, int l) throws IOException {
- for (int i = 0; i < l; i++) {
- writeInt(a[i]);
- }
- }
-
- public void writeFloatArray(float[] a) throws IOException {
- writeInt(a.length);
- writeFloatArray(a, a.length);
- }
-
- private void writeFloatArray(float[] a, int l) throws IOException {
- for (int i = 0; i < l; i++) {
- writeFloat(a[i]);
- }
- }
-
- public void writeDoubleArray(double[] a) throws IOException {
- writeInt(a.length);
- writeDoubleArray(a, a.length);
- }
-
- private void writeDoubleArray(double[] a, int l) throws IOException {
- for (int i = 0; i < l; i++) {
- writeDouble(a[i]);
- }
- }
-
- private static final class XdrOutputStream extends OutputStream {
-
- private final OutputStream mOut;
-
- // Number of bytes written
- private int mCount;
-
- public XdrOutputStream(OutputStream out) {
- mOut = out;
- mCount = 0;
- }
-
- @Override
- public void write(int b) throws IOException {
- mOut.write(b);
- // https://docs.oracle.com/javase/7/docs/api/java/io/OutputStream.html#write(int):
- // > The byte to be written is the eight low-order bits of the argument b.
- // > The 24 high-order bits of b are ignored.
- mCount++;
- }
-
- @Override
- public void write(byte[] b) throws IOException {
- // https://docs.oracle.com/javase/7/docs/api/java/io/OutputStream.html#write(byte[]):
- // > The general contract for write(b) is that it should have exactly the same effect
- // > as the call write(b, 0, b.length).
- write(b, 0, b.length);
- }
-
- public void write(byte[] b, int offset, int length) throws IOException {
- mOut.write(b, offset, length);
- mCount += length;
- pad();
- }
-
- public void pad() throws IOException {
- int pad = 0;
- int mod = mCount % 4;
- if (mod > 0) {
- pad = 4-mod;
- }
- while (pad-- > 0) {
- write(0);
- }
- }
- }
-}
diff --git a/spec/output/generator_spec_java/enum.x/XdrElement.java b/spec/output/generator_spec_java/enum.x/XdrElement.java
deleted file mode 100644
index 453491ea2..000000000
--- a/spec/output/generator_spec_java/enum.x/XdrElement.java
+++ /dev/null
@@ -1,21 +0,0 @@
-package MyXDR;
-
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import org.stellar.sdk.Base64Factory;
-
-/** Common parent interface for all generated classes. */
-interface XdrElement {
- void encode(XdrDataOutputStream stream) throws IOException;
-
- default String toXdrBase64() throws IOException {
- return Base64Factory.getInstance().encodeToString(toXdrByteArray());
- }
-
- default byte[] toXdrByteArray() throws IOException {
- ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
- XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream);
- encode(xdrDataOutputStream);
- return byteArrayOutputStream.toByteArray();
- }
-}
diff --git a/spec/output/generator_spec_java/enum.x/XdrString.java b/spec/output/generator_spec_java/enum.x/XdrString.java
deleted file mode 100644
index a51eead77..000000000
--- a/spec/output/generator_spec_java/enum.x/XdrString.java
+++ /dev/null
@@ -1,62 +0,0 @@
-package MyXDR;
-
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import java.io.InvalidClassException;
-import java.nio.charset.StandardCharsets;
-import lombok.Value;
-import org.stellar.sdk.Base64Factory;
-
-@Value
-public class XdrString implements XdrElement {
- byte[] bytes;
-
- public XdrString(byte[] bytes) {
- this.bytes = bytes;
- }
-
- public XdrString(String text) {
- this.bytes = text.getBytes(StandardCharsets.UTF_8);
- }
-
- @Override
- public void encode(XdrDataOutputStream stream) throws IOException {
- stream.writeInt(this.bytes.length);
- stream.write(this.bytes, 0, this.bytes.length);
- }
-
- public static XdrString decode(XdrDataInputStream stream, int maxSize) throws IOException {
- int size = stream.readInt();
- if (size > maxSize) {
- throw new IllegalArgumentException("String length " + size + " exceeds max size " + maxSize);
- }
- byte[] bytes = new byte[size];
- stream.read(bytes);
- return new XdrString(bytes);
- }
-
- public static XdrString fromXdrBase64(String xdr, int maxSize) throws IOException {
- byte[] bytes = Base64Factory.getInstance().decode(xdr);
- return fromXdrByteArray(bytes, maxSize);
- }
-
- public static XdrString fromXdrBase64(String xdr) throws IOException {
- return fromXdrBase64(xdr, Integer.MAX_VALUE);
- }
-
- public static XdrString fromXdrByteArray(byte[] xdr, int maxSize) throws IOException {
- ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr);
- XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream);
- return decode(xdrDataInputStream, maxSize);
- }
-
- public static XdrString fromXdrByteArray(byte[] xdr) throws IOException {
- return fromXdrByteArray(xdr, Integer.MAX_VALUE);
- }
-
- @Override
- public String toString() {
- return new String(bytes, StandardCharsets.UTF_8);
- }
-}
diff --git a/spec/output/generator_spec_java/enum.x/XdrUnsignedHyperInteger.java b/spec/output/generator_spec_java/enum.x/XdrUnsignedHyperInteger.java
deleted file mode 100644
index 5d798cded..000000000
--- a/spec/output/generator_spec_java/enum.x/XdrUnsignedHyperInteger.java
+++ /dev/null
@@ -1,69 +0,0 @@
-package MyXDR;
-
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import java.math.BigInteger;
-import lombok.Value;
-import org.stellar.sdk.Base64Factory;
-
-/**
- * Represents XDR Unsigned Hyper Integer.
- *
- * @see XDR: External Data
- * Representation Standard
- */
-@Value
-public class XdrUnsignedHyperInteger implements XdrElement {
- public static final BigInteger MAX_VALUE = new BigInteger("18446744073709551615");
- public static final BigInteger MIN_VALUE = BigInteger.ZERO;
- BigInteger number;
-
- public XdrUnsignedHyperInteger(BigInteger number) {
- if (number.compareTo(MIN_VALUE) < 0 || number.compareTo(MAX_VALUE) > 0) {
- throw new IllegalArgumentException("number must be between 0 and 2^64 - 1 inclusive");
- }
- this.number = number;
- }
-
- public XdrUnsignedHyperInteger(Long number) {
- if (number < 0) {
- throw new IllegalArgumentException(
- "number must be greater than or equal to 0 if you want to construct it from Long");
- }
- this.number = BigInteger.valueOf(number);
- }
-
- @Override
- public void encode(XdrDataOutputStream stream) throws IOException {
- stream.write(getBytes());
- }
-
- public static XdrUnsignedHyperInteger decode(XdrDataInputStream stream) throws IOException {
- byte[] bytes = new byte[8];
- stream.readFully(bytes);
- BigInteger uint64 = new BigInteger(1, bytes);
- return new XdrUnsignedHyperInteger(uint64);
- }
-
- private byte[] getBytes() {
- byte[] bytes = number.toByteArray();
- byte[] paddedBytes = new byte[8];
-
- int numBytesToCopy = Math.min(bytes.length, 8);
- int copyStartIndex = bytes.length - numBytesToCopy;
- System.arraycopy(bytes, copyStartIndex, paddedBytes, 8 - numBytesToCopy, numBytesToCopy);
- return paddedBytes;
- }
-
- public static XdrUnsignedHyperInteger fromXdrBase64(String xdr) throws IOException {
- byte[] bytes = Base64Factory.getInstance().decode(xdr);
- return fromXdrByteArray(bytes);
- }
-
- public static XdrUnsignedHyperInteger fromXdrByteArray(byte[] xdr) throws IOException {
- ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr);
- XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream);
- return decode(xdrDataInputStream);
- }
-}
diff --git a/spec/output/generator_spec_java/enum.x/XdrUnsignedInteger.java b/spec/output/generator_spec_java/enum.x/XdrUnsignedInteger.java
deleted file mode 100644
index bea880aee..000000000
--- a/spec/output/generator_spec_java/enum.x/XdrUnsignedInteger.java
+++ /dev/null
@@ -1,57 +0,0 @@
-package MyXDR;
-
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import lombok.Value;
-import org.stellar.sdk.Base64Factory;
-
-/**
- * Represents XDR Unsigned Integer.
- *
- * @see XDR: External Data
- * Representation Standard
- */
-@Value
-public class XdrUnsignedInteger implements XdrElement {
- public static final long MAX_VALUE = (1L << 32) - 1;
- public static final long MIN_VALUE = 0;
- Long number;
-
- public XdrUnsignedInteger(Long number) {
- if (number < MIN_VALUE || number > MAX_VALUE) {
- throw new IllegalArgumentException("number must be between 0 and 2^32 - 1 inclusive");
- }
- this.number = number;
- }
-
- public XdrUnsignedInteger(Integer number) {
- if (number < 0) {
- throw new IllegalArgumentException(
- "number must be greater than or equal to 0 if you want to construct it from Integer");
- }
- this.number = number.longValue();
- }
-
- public static XdrUnsignedInteger decode(XdrDataInputStream stream) throws IOException {
- int intValue = stream.readInt();
- long uint32Value = Integer.toUnsignedLong(intValue);
- return new XdrUnsignedInteger(uint32Value);
- }
-
- @Override
- public void encode(XdrDataOutputStream stream) throws IOException {
- stream.writeInt(number.intValue());
- }
-
- public static XdrUnsignedInteger fromXdrBase64(String xdr) throws IOException {
- byte[] bytes = Base64Factory.getInstance().decode(xdr);
- return fromXdrByteArray(bytes);
- }
-
- public static XdrUnsignedInteger fromXdrByteArray(byte[] xdr) throws IOException {
- ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr);
- XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream);
- return decode(xdrDataInputStream);
- }
-}
diff --git a/spec/output/generator_spec_java/nesting.x/Constants.java b/spec/output/generator_spec_java/nesting.x/Constants.java
deleted file mode 100644
index d7d9f4cfc..000000000
--- a/spec/output/generator_spec_java/nesting.x/Constants.java
+++ /dev/null
@@ -1,10 +0,0 @@
-// Automatically generated by xdrgen
-// DO NOT EDIT or your changes may be overwritten
-
-package MyXDR;
-
-import java.io.IOException;
-
-public final class Constants {
- private Constants() {}
-}
diff --git a/spec/output/generator_spec_java/nesting.x/Foo.java b/spec/output/generator_spec_java/nesting.x/Foo.java
deleted file mode 100644
index 1455c50e5..000000000
--- a/spec/output/generator_spec_java/nesting.x/Foo.java
+++ /dev/null
@@ -1,46 +0,0 @@
-// Automatically generated by xdrgen
-// DO NOT EDIT or your changes may be overwritten
-
-package MyXDR;
-
-import java.io.IOException;
-
-import org.stellar.sdk.Base64Factory;
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import lombok.Data;
-import lombok.NoArgsConstructor;
-import lombok.AllArgsConstructor;
-
-/**
- * Foo's original definition in the XDR file is:
- * - * typedef int Foo; - *- */ -@Data -@NoArgsConstructor -@AllArgsConstructor -public class Foo implements XdrElement { - private Integer Foo; - public void encode(XdrDataOutputStream stream) throws IOException { - stream.writeInt(Foo); - } - - public static Foo decode(XdrDataInputStream stream) throws IOException { - Foo decodedFoo = new Foo(); - decodedFoo.Foo = stream.readInt(); - return decodedFoo; - } - - public static Foo fromXdrBase64(String xdr) throws IOException { - byte[] bytes = Base64Factory.getInstance().decode(xdr); - return fromXdrByteArray(bytes); - } - - public static Foo fromXdrByteArray(byte[] xdr) throws IOException { - ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); - XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); - return decode(xdrDataInputStream); - } -} diff --git a/spec/output/generator_spec_java/nesting.x/MyUnion.java b/spec/output/generator_spec_java/nesting.x/MyUnion.java deleted file mode 100644 index bc59082e8..000000000 --- a/spec/output/generator_spec_java/nesting.x/MyUnion.java +++ /dev/null @@ -1,158 +0,0 @@ -// Automatically generated by xdrgen -// DO NOT EDIT or your changes may be overwritten - -package MyXDR; - -import java.io.IOException; - -import org.stellar.sdk.Base64Factory; -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; -import lombok.Data; -import lombok.NoArgsConstructor; -import lombok.AllArgsConstructor; -import lombok.Builder; - -/** - * MyUnion's original definition in the XDR file is: - *
- * union MyUnion switch (UnionKey type)
- * {
- * case ONE:
- * struct {
- * int someInt;
- * } one;
- *
- * case TWO:
- * struct {
- * int someInt;
- * Foo foo;
- * } two;
- *
- * case OFFER:
- * void;
- * };
- *
- */
-@Data
-@NoArgsConstructor
-@AllArgsConstructor
-@Builder(toBuilder = true)
-public class MyUnion implements XdrElement {
- private UnionKey discriminant;
- private MyUnionOne one;
- private MyUnionTwo two;
-
- public void encode(XdrDataOutputStream stream) throws IOException {
- stream.writeInt(discriminant.getValue());
- switch (discriminant) {
- case ONE:
- one.encode(stream);
- break;
- case TWO:
- two.encode(stream);
- break;
- case OFFER:
- break;
- }
- }
- public static MyUnion decode(XdrDataInputStream stream) throws IOException {
- MyUnion decodedMyUnion = new MyUnion();
- UnionKey discriminant = UnionKey.decode(stream);
- decodedMyUnion.setDiscriminant(discriminant);
- switch (decodedMyUnion.getDiscriminant()) {
- case ONE:
- decodedMyUnion.one = MyUnionOne.decode(stream);
- break;
- case TWO:
- decodedMyUnion.two = MyUnionTwo.decode(stream);
- break;
- case OFFER:
- break;
- }
- return decodedMyUnion;
- }
- public static MyUnion fromXdrBase64(String xdr) throws IOException {
- byte[] bytes = Base64Factory.getInstance().decode(xdr);
- return fromXdrByteArray(bytes);
- }
-
- public static MyUnion fromXdrByteArray(byte[] xdr) throws IOException {
- ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr);
- XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream);
- return decode(xdrDataInputStream);
- }
-
- /**
- * MyUnionOne's original definition in the XDR file is:
- *
- * struct {
- * int someInt;
- * }
- *
- */
- @Data
- @NoArgsConstructor
- @AllArgsConstructor
- @Builder(toBuilder = true)
- public static class MyUnionOne implements XdrElement {
- private Integer someInt;
- public void encode(XdrDataOutputStream stream) throws IOException{
- stream.writeInt(someInt);
- }
- public static MyUnionOne decode(XdrDataInputStream stream) throws IOException {
- MyUnionOne decodedMyUnionOne = new MyUnionOne();
- decodedMyUnionOne.someInt = stream.readInt();
- return decodedMyUnionOne;
- }
- public static MyUnionOne fromXdrBase64(String xdr) throws IOException {
- byte[] bytes = Base64Factory.getInstance().decode(xdr);
- return fromXdrByteArray(bytes);
- }
-
- public static MyUnionOne fromXdrByteArray(byte[] xdr) throws IOException {
- ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr);
- XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream);
- return decode(xdrDataInputStream);
- }
-
- }
- /**
- * MyUnionTwo's original definition in the XDR file is:
- *
- * struct {
- * int someInt;
- * Foo foo;
- * }
- *
- */
- @Data
- @NoArgsConstructor
- @AllArgsConstructor
- @Builder(toBuilder = true)
- public static class MyUnionTwo implements XdrElement {
- private Integer someInt;
- private Foo foo;
- public void encode(XdrDataOutputStream stream) throws IOException{
- stream.writeInt(someInt);
- foo.encode(stream);
- }
- public static MyUnionTwo decode(XdrDataInputStream stream) throws IOException {
- MyUnionTwo decodedMyUnionTwo = new MyUnionTwo();
- decodedMyUnionTwo.someInt = stream.readInt();
- decodedMyUnionTwo.foo = Foo.decode(stream);
- return decodedMyUnionTwo;
- }
- public static MyUnionTwo fromXdrBase64(String xdr) throws IOException {
- byte[] bytes = Base64Factory.getInstance().decode(xdr);
- return fromXdrByteArray(bytes);
- }
-
- public static MyUnionTwo fromXdrByteArray(byte[] xdr) throws IOException {
- ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr);
- XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream);
- return decode(xdrDataInputStream);
- }
-
- }
-}
diff --git a/spec/output/generator_spec_java/nesting.x/UnionKey.java b/spec/output/generator_spec_java/nesting.x/UnionKey.java
deleted file mode 100644
index 80278b683..000000000
--- a/spec/output/generator_spec_java/nesting.x/UnionKey.java
+++ /dev/null
@@ -1,61 +0,0 @@
-// Automatically generated by xdrgen
-// DO NOT EDIT or your changes may be overwritten
-
-package MyXDR;
-
-import java.io.IOException;
-
-import org.stellar.sdk.Base64Factory;
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-
-/**
- * UnionKey's original definition in the XDR file is:
- *
- * enum UnionKey {
- * ONE = 1,
- * TWO = 2,
- * OFFER = 3
- * };
- *
- */
-public enum UnionKey implements XdrElement {
- ONE(1),
- TWO(2),
- OFFER(3);
-
- private final int value;
-
- UnionKey(int value) {
- this.value = value;
- }
-
- public int getValue() {
- return value;
- }
-
- public static UnionKey decode(XdrDataInputStream stream) throws IOException {
- int value = stream.readInt();
- switch (value) {
- case 1: return ONE;
- case 2: return TWO;
- case 3: return OFFER;
- default:
- throw new IllegalArgumentException("Unknown enum value: " + value);
- }
- }
-
- public void encode(XdrDataOutputStream stream) throws IOException {
- stream.writeInt(value);
- }
- public static UnionKey fromXdrBase64(String xdr) throws IOException {
- byte[] bytes = Base64Factory.getInstance().decode(xdr);
- return fromXdrByteArray(bytes);
- }
-
- public static UnionKey fromXdrByteArray(byte[] xdr) throws IOException {
- ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr);
- XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream);
- return decode(xdrDataInputStream);
- }
-}
diff --git a/spec/output/generator_spec_java/nesting.x/XdrDataInputStream.java b/spec/output/generator_spec_java/nesting.x/XdrDataInputStream.java
deleted file mode 100644
index 6d6592026..000000000
--- a/spec/output/generator_spec_java/nesting.x/XdrDataInputStream.java
+++ /dev/null
@@ -1,122 +0,0 @@
-package MyXDR;
-
-import java.io.DataInputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.nio.charset.Charset;
-
-public class XdrDataInputStream extends DataInputStream {
-
- // The underlying input stream
- private final XdrInputStream mIn;
-
- /**
- * Creates a XdrDataInputStream that uses the specified
- * underlying InputStream.
- *
- * @param in the specified input stream
- */
- public XdrDataInputStream(InputStream in) {
- super(new XdrInputStream(in));
- mIn = (XdrInputStream) super.in;
- }
-
- public int[] readIntArray() throws IOException {
- int l = readInt();
- return readIntArray(l);
- }
-
- private int[] readIntArray(int l) throws IOException {
- int[] arr = new int[l];
- for (int i = 0; i < l; i++) {
- arr[i] = readInt();
- }
- return arr;
- }
-
- public float[] readFloatArray() throws IOException {
- int l = readInt();
- return readFloatArray(l);
- }
-
- private float[] readFloatArray(int l) throws IOException {
- float[] arr = new float[l];
- for (int i = 0; i < l; i++) {
- arr[i] = readFloat();
- }
- return arr;
- }
-
- public double[] readDoubleArray() throws IOException {
- int l = readInt();
- return readDoubleArray(l);
- }
-
- private double[] readDoubleArray(int l) throws IOException {
- double[] arr = new double[l];
- for (int i = 0; i < l; i++) {
- arr[i] = readDouble();
- }
- return arr;
- }
-
- @Override
- public int read() throws IOException {
- return super.read();
- }
-
- /**
- * Need to provide a custom impl of InputStream as DataInputStream's read methods
- * are final and we need to keep track of the count for padding purposes.
- */
- private static final class XdrInputStream extends InputStream {
-
- // The underlying input stream
- private final InputStream mIn;
-
- // The amount of bytes read so far.
- private int mCount;
-
- public XdrInputStream(InputStream in) {
- mIn = in;
- mCount = 0;
- }
-
- @Override
- public int read() throws IOException {
- int read = mIn.read();
- if (read >= 0) {
- mCount++;
- }
- return read;
- }
-
- @Override
- public int read(byte[] b) throws IOException {
- return read(b, 0, b.length);
- }
-
- @Override
- public int read(byte[] b, int off, int len) throws IOException {
- int read = mIn.read(b, off, len);
- mCount += read;
- pad();
- return read;
- }
-
- public void pad() throws IOException {
- int pad = 0;
- int mod = mCount % 4;
- if (mod > 0) {
- pad = 4-mod;
- }
-
- while (pad-- > 0) {
- int b = read();
- if (b != 0) {
- throw new IOException("non-zero padding");
- }
- }
- }
- }
-}
diff --git a/spec/output/generator_spec_java/nesting.x/XdrDataOutputStream.java b/spec/output/generator_spec_java/nesting.x/XdrDataOutputStream.java
deleted file mode 100644
index 729aec05b..000000000
--- a/spec/output/generator_spec_java/nesting.x/XdrDataOutputStream.java
+++ /dev/null
@@ -1,96 +0,0 @@
-package MyXDR;
-
-import java.io.DataOutputStream;
-import java.io.IOException;
-import java.io.OutputStream;
-import java.nio.charset.Charset;
-
-public class XdrDataOutputStream extends DataOutputStream {
-
- private final XdrOutputStream mOut;
-
- public XdrDataOutputStream(OutputStream out) {
- super(new XdrOutputStream(out));
- mOut = (XdrOutputStream) super.out;
- }
-
- public void writeIntArray(int[] a) throws IOException {
- writeInt(a.length);
- writeIntArray(a, a.length);
- }
-
- private void writeIntArray(int[] a, int l) throws IOException {
- for (int i = 0; i < l; i++) {
- writeInt(a[i]);
- }
- }
-
- public void writeFloatArray(float[] a) throws IOException {
- writeInt(a.length);
- writeFloatArray(a, a.length);
- }
-
- private void writeFloatArray(float[] a, int l) throws IOException {
- for (int i = 0; i < l; i++) {
- writeFloat(a[i]);
- }
- }
-
- public void writeDoubleArray(double[] a) throws IOException {
- writeInt(a.length);
- writeDoubleArray(a, a.length);
- }
-
- private void writeDoubleArray(double[] a, int l) throws IOException {
- for (int i = 0; i < l; i++) {
- writeDouble(a[i]);
- }
- }
-
- private static final class XdrOutputStream extends OutputStream {
-
- private final OutputStream mOut;
-
- // Number of bytes written
- private int mCount;
-
- public XdrOutputStream(OutputStream out) {
- mOut = out;
- mCount = 0;
- }
-
- @Override
- public void write(int b) throws IOException {
- mOut.write(b);
- // https://docs.oracle.com/javase/7/docs/api/java/io/OutputStream.html#write(int):
- // > The byte to be written is the eight low-order bits of the argument b.
- // > The 24 high-order bits of b are ignored.
- mCount++;
- }
-
- @Override
- public void write(byte[] b) throws IOException {
- // https://docs.oracle.com/javase/7/docs/api/java/io/OutputStream.html#write(byte[]):
- // > The general contract for write(b) is that it should have exactly the same effect
- // > as the call write(b, 0, b.length).
- write(b, 0, b.length);
- }
-
- public void write(byte[] b, int offset, int length) throws IOException {
- mOut.write(b, offset, length);
- mCount += length;
- pad();
- }
-
- public void pad() throws IOException {
- int pad = 0;
- int mod = mCount % 4;
- if (mod > 0) {
- pad = 4-mod;
- }
- while (pad-- > 0) {
- write(0);
- }
- }
- }
-}
diff --git a/spec/output/generator_spec_java/nesting.x/XdrElement.java b/spec/output/generator_spec_java/nesting.x/XdrElement.java
deleted file mode 100644
index 453491ea2..000000000
--- a/spec/output/generator_spec_java/nesting.x/XdrElement.java
+++ /dev/null
@@ -1,21 +0,0 @@
-package MyXDR;
-
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import org.stellar.sdk.Base64Factory;
-
-/** Common parent interface for all generated classes. */
-interface XdrElement {
- void encode(XdrDataOutputStream stream) throws IOException;
-
- default String toXdrBase64() throws IOException {
- return Base64Factory.getInstance().encodeToString(toXdrByteArray());
- }
-
- default byte[] toXdrByteArray() throws IOException {
- ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
- XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream);
- encode(xdrDataOutputStream);
- return byteArrayOutputStream.toByteArray();
- }
-}
diff --git a/spec/output/generator_spec_java/nesting.x/XdrString.java b/spec/output/generator_spec_java/nesting.x/XdrString.java
deleted file mode 100644
index a51eead77..000000000
--- a/spec/output/generator_spec_java/nesting.x/XdrString.java
+++ /dev/null
@@ -1,62 +0,0 @@
-package MyXDR;
-
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import java.io.InvalidClassException;
-import java.nio.charset.StandardCharsets;
-import lombok.Value;
-import org.stellar.sdk.Base64Factory;
-
-@Value
-public class XdrString implements XdrElement {
- byte[] bytes;
-
- public XdrString(byte[] bytes) {
- this.bytes = bytes;
- }
-
- public XdrString(String text) {
- this.bytes = text.getBytes(StandardCharsets.UTF_8);
- }
-
- @Override
- public void encode(XdrDataOutputStream stream) throws IOException {
- stream.writeInt(this.bytes.length);
- stream.write(this.bytes, 0, this.bytes.length);
- }
-
- public static XdrString decode(XdrDataInputStream stream, int maxSize) throws IOException {
- int size = stream.readInt();
- if (size > maxSize) {
- throw new IllegalArgumentException("String length " + size + " exceeds max size " + maxSize);
- }
- byte[] bytes = new byte[size];
- stream.read(bytes);
- return new XdrString(bytes);
- }
-
- public static XdrString fromXdrBase64(String xdr, int maxSize) throws IOException {
- byte[] bytes = Base64Factory.getInstance().decode(xdr);
- return fromXdrByteArray(bytes, maxSize);
- }
-
- public static XdrString fromXdrBase64(String xdr) throws IOException {
- return fromXdrBase64(xdr, Integer.MAX_VALUE);
- }
-
- public static XdrString fromXdrByteArray(byte[] xdr, int maxSize) throws IOException {
- ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr);
- XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream);
- return decode(xdrDataInputStream, maxSize);
- }
-
- public static XdrString fromXdrByteArray(byte[] xdr) throws IOException {
- return fromXdrByteArray(xdr, Integer.MAX_VALUE);
- }
-
- @Override
- public String toString() {
- return new String(bytes, StandardCharsets.UTF_8);
- }
-}
diff --git a/spec/output/generator_spec_java/nesting.x/XdrUnsignedHyperInteger.java b/spec/output/generator_spec_java/nesting.x/XdrUnsignedHyperInteger.java
deleted file mode 100644
index 5d798cded..000000000
--- a/spec/output/generator_spec_java/nesting.x/XdrUnsignedHyperInteger.java
+++ /dev/null
@@ -1,69 +0,0 @@
-package MyXDR;
-
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import java.math.BigInteger;
-import lombok.Value;
-import org.stellar.sdk.Base64Factory;
-
-/**
- * Represents XDR Unsigned Hyper Integer.
- *
- * @see XDR: External Data
- * Representation Standard
- */
-@Value
-public class XdrUnsignedHyperInteger implements XdrElement {
- public static final BigInteger MAX_VALUE = new BigInteger("18446744073709551615");
- public static final BigInteger MIN_VALUE = BigInteger.ZERO;
- BigInteger number;
-
- public XdrUnsignedHyperInteger(BigInteger number) {
- if (number.compareTo(MIN_VALUE) < 0 || number.compareTo(MAX_VALUE) > 0) {
- throw new IllegalArgumentException("number must be between 0 and 2^64 - 1 inclusive");
- }
- this.number = number;
- }
-
- public XdrUnsignedHyperInteger(Long number) {
- if (number < 0) {
- throw new IllegalArgumentException(
- "number must be greater than or equal to 0 if you want to construct it from Long");
- }
- this.number = BigInteger.valueOf(number);
- }
-
- @Override
- public void encode(XdrDataOutputStream stream) throws IOException {
- stream.write(getBytes());
- }
-
- public static XdrUnsignedHyperInteger decode(XdrDataInputStream stream) throws IOException {
- byte[] bytes = new byte[8];
- stream.readFully(bytes);
- BigInteger uint64 = new BigInteger(1, bytes);
- return new XdrUnsignedHyperInteger(uint64);
- }
-
- private byte[] getBytes() {
- byte[] bytes = number.toByteArray();
- byte[] paddedBytes = new byte[8];
-
- int numBytesToCopy = Math.min(bytes.length, 8);
- int copyStartIndex = bytes.length - numBytesToCopy;
- System.arraycopy(bytes, copyStartIndex, paddedBytes, 8 - numBytesToCopy, numBytesToCopy);
- return paddedBytes;
- }
-
- public static XdrUnsignedHyperInteger fromXdrBase64(String xdr) throws IOException {
- byte[] bytes = Base64Factory.getInstance().decode(xdr);
- return fromXdrByteArray(bytes);
- }
-
- public static XdrUnsignedHyperInteger fromXdrByteArray(byte[] xdr) throws IOException {
- ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr);
- XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream);
- return decode(xdrDataInputStream);
- }
-}
diff --git a/spec/output/generator_spec_java/nesting.x/XdrUnsignedInteger.java b/spec/output/generator_spec_java/nesting.x/XdrUnsignedInteger.java
deleted file mode 100644
index bea880aee..000000000
--- a/spec/output/generator_spec_java/nesting.x/XdrUnsignedInteger.java
+++ /dev/null
@@ -1,57 +0,0 @@
-package MyXDR;
-
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import lombok.Value;
-import org.stellar.sdk.Base64Factory;
-
-/**
- * Represents XDR Unsigned Integer.
- *
- * @see XDR: External Data
- * Representation Standard
- */
-@Value
-public class XdrUnsignedInteger implements XdrElement {
- public static final long MAX_VALUE = (1L << 32) - 1;
- public static final long MIN_VALUE = 0;
- Long number;
-
- public XdrUnsignedInteger(Long number) {
- if (number < MIN_VALUE || number > MAX_VALUE) {
- throw new IllegalArgumentException("number must be between 0 and 2^32 - 1 inclusive");
- }
- this.number = number;
- }
-
- public XdrUnsignedInteger(Integer number) {
- if (number < 0) {
- throw new IllegalArgumentException(
- "number must be greater than or equal to 0 if you want to construct it from Integer");
- }
- this.number = number.longValue();
- }
-
- public static XdrUnsignedInteger decode(XdrDataInputStream stream) throws IOException {
- int intValue = stream.readInt();
- long uint32Value = Integer.toUnsignedLong(intValue);
- return new XdrUnsignedInteger(uint32Value);
- }
-
- @Override
- public void encode(XdrDataOutputStream stream) throws IOException {
- stream.writeInt(number.intValue());
- }
-
- public static XdrUnsignedInteger fromXdrBase64(String xdr) throws IOException {
- byte[] bytes = Base64Factory.getInstance().decode(xdr);
- return fromXdrByteArray(bytes);
- }
-
- public static XdrUnsignedInteger fromXdrByteArray(byte[] xdr) throws IOException {
- ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr);
- XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream);
- return decode(xdrDataInputStream);
- }
-}
diff --git a/spec/output/generator_spec_java/optional.x/Arr.java b/spec/output/generator_spec_java/optional.x/Arr.java
deleted file mode 100644
index 4ca07a5cb..000000000
--- a/spec/output/generator_spec_java/optional.x/Arr.java
+++ /dev/null
@@ -1,53 +0,0 @@
-// Automatically generated by xdrgen
-// DO NOT EDIT or your changes may be overwritten
-
-package MyXDR;
-
-import java.io.IOException;
-
-import org.stellar.sdk.Base64Factory;
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import lombok.Data;
-import lombok.NoArgsConstructor;
-import lombok.AllArgsConstructor;
-
-/**
- * Arr's original definition in the XDR file is:
- * - * typedef int Arr[2]; - *- */ -@Data -@NoArgsConstructor -@AllArgsConstructor -public class Arr implements XdrElement { - private Integer[] Arr; - public void encode(XdrDataOutputStream stream) throws IOException { - int ArrSize = getArr().length; - for (int i = 0; i < ArrSize; i++) { - stream.writeInt(Arr[i]); - } - } - - public static Arr decode(XdrDataInputStream stream) throws IOException { - Arr decodedArr = new Arr(); - int ArrSize = 2; - decodedArr.Arr = new Integer[ArrSize]; - for (int i = 0; i < ArrSize; i++) { - decodedArr.Arr[i] = stream.readInt(); - } - return decodedArr; - } - - public static Arr fromXdrBase64(String xdr) throws IOException { - byte[] bytes = Base64Factory.getInstance().decode(xdr); - return fromXdrByteArray(bytes); - } - - public static Arr fromXdrByteArray(byte[] xdr) throws IOException { - ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); - XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); - return decode(xdrDataInputStream); - } -} diff --git a/spec/output/generator_spec_java/optional.x/Constants.java b/spec/output/generator_spec_java/optional.x/Constants.java deleted file mode 100644 index d7d9f4cfc..000000000 --- a/spec/output/generator_spec_java/optional.x/Constants.java +++ /dev/null @@ -1,10 +0,0 @@ -// Automatically generated by xdrgen -// DO NOT EDIT or your changes may be overwritten - -package MyXDR; - -import java.io.IOException; - -public final class Constants { - private Constants() {} -} diff --git a/spec/output/generator_spec_java/optional.x/HasOptions.java b/spec/output/generator_spec_java/optional.x/HasOptions.java deleted file mode 100644 index f9bdba731..000000000 --- a/spec/output/generator_spec_java/optional.x/HasOptions.java +++ /dev/null @@ -1,81 +0,0 @@ -// Automatically generated by xdrgen -// DO NOT EDIT or your changes may be overwritten - -package MyXDR; - -import java.io.IOException; - -import org.stellar.sdk.Base64Factory; -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; -import lombok.Data; -import lombok.NoArgsConstructor; -import lombok.AllArgsConstructor; -import lombok.Builder; - -/** - * HasOptions's original definition in the XDR file is: - *
- * struct HasOptions
- * {
- * int* firstOption;
- * int *secondOption;
- * Arr *thirdOption;
- * };
- *
- */
-@Data
-@NoArgsConstructor
-@AllArgsConstructor
-@Builder(toBuilder = true)
-public class HasOptions implements XdrElement {
- private Integer firstOption;
- private Integer secondOption;
- private Arr thirdOption;
- public void encode(XdrDataOutputStream stream) throws IOException{
- if (firstOption != null) {
- stream.writeInt(1);
- stream.writeInt(firstOption);
- } else {
- stream.writeInt(0);
- }
- if (secondOption != null) {
- stream.writeInt(1);
- stream.writeInt(secondOption);
- } else {
- stream.writeInt(0);
- }
- if (thirdOption != null) {
- stream.writeInt(1);
- thirdOption.encode(stream);
- } else {
- stream.writeInt(0);
- }
- }
- public static HasOptions decode(XdrDataInputStream stream) throws IOException {
- HasOptions decodedHasOptions = new HasOptions();
- int firstOptionPresent = stream.readInt();
- if (firstOptionPresent != 0) {
- decodedHasOptions.firstOption = stream.readInt();
- }
- int secondOptionPresent = stream.readInt();
- if (secondOptionPresent != 0) {
- decodedHasOptions.secondOption = stream.readInt();
- }
- int thirdOptionPresent = stream.readInt();
- if (thirdOptionPresent != 0) {
- decodedHasOptions.thirdOption = Arr.decode(stream);
- }
- return decodedHasOptions;
- }
- public static HasOptions fromXdrBase64(String xdr) throws IOException {
- byte[] bytes = Base64Factory.getInstance().decode(xdr);
- return fromXdrByteArray(bytes);
- }
-
- public static HasOptions fromXdrByteArray(byte[] xdr) throws IOException {
- ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr);
- XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream);
- return decode(xdrDataInputStream);
- }
-}
diff --git a/spec/output/generator_spec_java/optional.x/XdrDataInputStream.java b/spec/output/generator_spec_java/optional.x/XdrDataInputStream.java
deleted file mode 100644
index 6d6592026..000000000
--- a/spec/output/generator_spec_java/optional.x/XdrDataInputStream.java
+++ /dev/null
@@ -1,122 +0,0 @@
-package MyXDR;
-
-import java.io.DataInputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.nio.charset.Charset;
-
-public class XdrDataInputStream extends DataInputStream {
-
- // The underlying input stream
- private final XdrInputStream mIn;
-
- /**
- * Creates a XdrDataInputStream that uses the specified
- * underlying InputStream.
- *
- * @param in the specified input stream
- */
- public XdrDataInputStream(InputStream in) {
- super(new XdrInputStream(in));
- mIn = (XdrInputStream) super.in;
- }
-
- public int[] readIntArray() throws IOException {
- int l = readInt();
- return readIntArray(l);
- }
-
- private int[] readIntArray(int l) throws IOException {
- int[] arr = new int[l];
- for (int i = 0; i < l; i++) {
- arr[i] = readInt();
- }
- return arr;
- }
-
- public float[] readFloatArray() throws IOException {
- int l = readInt();
- return readFloatArray(l);
- }
-
- private float[] readFloatArray(int l) throws IOException {
- float[] arr = new float[l];
- for (int i = 0; i < l; i++) {
- arr[i] = readFloat();
- }
- return arr;
- }
-
- public double[] readDoubleArray() throws IOException {
- int l = readInt();
- return readDoubleArray(l);
- }
-
- private double[] readDoubleArray(int l) throws IOException {
- double[] arr = new double[l];
- for (int i = 0; i < l; i++) {
- arr[i] = readDouble();
- }
- return arr;
- }
-
- @Override
- public int read() throws IOException {
- return super.read();
- }
-
- /**
- * Need to provide a custom impl of InputStream as DataInputStream's read methods
- * are final and we need to keep track of the count for padding purposes.
- */
- private static final class XdrInputStream extends InputStream {
-
- // The underlying input stream
- private final InputStream mIn;
-
- // The amount of bytes read so far.
- private int mCount;
-
- public XdrInputStream(InputStream in) {
- mIn = in;
- mCount = 0;
- }
-
- @Override
- public int read() throws IOException {
- int read = mIn.read();
- if (read >= 0) {
- mCount++;
- }
- return read;
- }
-
- @Override
- public int read(byte[] b) throws IOException {
- return read(b, 0, b.length);
- }
-
- @Override
- public int read(byte[] b, int off, int len) throws IOException {
- int read = mIn.read(b, off, len);
- mCount += read;
- pad();
- return read;
- }
-
- public void pad() throws IOException {
- int pad = 0;
- int mod = mCount % 4;
- if (mod > 0) {
- pad = 4-mod;
- }
-
- while (pad-- > 0) {
- int b = read();
- if (b != 0) {
- throw new IOException("non-zero padding");
- }
- }
- }
- }
-}
diff --git a/spec/output/generator_spec_java/optional.x/XdrDataOutputStream.java b/spec/output/generator_spec_java/optional.x/XdrDataOutputStream.java
deleted file mode 100644
index 729aec05b..000000000
--- a/spec/output/generator_spec_java/optional.x/XdrDataOutputStream.java
+++ /dev/null
@@ -1,96 +0,0 @@
-package MyXDR;
-
-import java.io.DataOutputStream;
-import java.io.IOException;
-import java.io.OutputStream;
-import java.nio.charset.Charset;
-
-public class XdrDataOutputStream extends DataOutputStream {
-
- private final XdrOutputStream mOut;
-
- public XdrDataOutputStream(OutputStream out) {
- super(new XdrOutputStream(out));
- mOut = (XdrOutputStream) super.out;
- }
-
- public void writeIntArray(int[] a) throws IOException {
- writeInt(a.length);
- writeIntArray(a, a.length);
- }
-
- private void writeIntArray(int[] a, int l) throws IOException {
- for (int i = 0; i < l; i++) {
- writeInt(a[i]);
- }
- }
-
- public void writeFloatArray(float[] a) throws IOException {
- writeInt(a.length);
- writeFloatArray(a, a.length);
- }
-
- private void writeFloatArray(float[] a, int l) throws IOException {
- for (int i = 0; i < l; i++) {
- writeFloat(a[i]);
- }
- }
-
- public void writeDoubleArray(double[] a) throws IOException {
- writeInt(a.length);
- writeDoubleArray(a, a.length);
- }
-
- private void writeDoubleArray(double[] a, int l) throws IOException {
- for (int i = 0; i < l; i++) {
- writeDouble(a[i]);
- }
- }
-
- private static final class XdrOutputStream extends OutputStream {
-
- private final OutputStream mOut;
-
- // Number of bytes written
- private int mCount;
-
- public XdrOutputStream(OutputStream out) {
- mOut = out;
- mCount = 0;
- }
-
- @Override
- public void write(int b) throws IOException {
- mOut.write(b);
- // https://docs.oracle.com/javase/7/docs/api/java/io/OutputStream.html#write(int):
- // > The byte to be written is the eight low-order bits of the argument b.
- // > The 24 high-order bits of b are ignored.
- mCount++;
- }
-
- @Override
- public void write(byte[] b) throws IOException {
- // https://docs.oracle.com/javase/7/docs/api/java/io/OutputStream.html#write(byte[]):
- // > The general contract for write(b) is that it should have exactly the same effect
- // > as the call write(b, 0, b.length).
- write(b, 0, b.length);
- }
-
- public void write(byte[] b, int offset, int length) throws IOException {
- mOut.write(b, offset, length);
- mCount += length;
- pad();
- }
-
- public void pad() throws IOException {
- int pad = 0;
- int mod = mCount % 4;
- if (mod > 0) {
- pad = 4-mod;
- }
- while (pad-- > 0) {
- write(0);
- }
- }
- }
-}
diff --git a/spec/output/generator_spec_java/optional.x/XdrElement.java b/spec/output/generator_spec_java/optional.x/XdrElement.java
deleted file mode 100644
index 453491ea2..000000000
--- a/spec/output/generator_spec_java/optional.x/XdrElement.java
+++ /dev/null
@@ -1,21 +0,0 @@
-package MyXDR;
-
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import org.stellar.sdk.Base64Factory;
-
-/** Common parent interface for all generated classes. */
-interface XdrElement {
- void encode(XdrDataOutputStream stream) throws IOException;
-
- default String toXdrBase64() throws IOException {
- return Base64Factory.getInstance().encodeToString(toXdrByteArray());
- }
-
- default byte[] toXdrByteArray() throws IOException {
- ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
- XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream);
- encode(xdrDataOutputStream);
- return byteArrayOutputStream.toByteArray();
- }
-}
diff --git a/spec/output/generator_spec_java/optional.x/XdrString.java b/spec/output/generator_spec_java/optional.x/XdrString.java
deleted file mode 100644
index a51eead77..000000000
--- a/spec/output/generator_spec_java/optional.x/XdrString.java
+++ /dev/null
@@ -1,62 +0,0 @@
-package MyXDR;
-
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import java.io.InvalidClassException;
-import java.nio.charset.StandardCharsets;
-import lombok.Value;
-import org.stellar.sdk.Base64Factory;
-
-@Value
-public class XdrString implements XdrElement {
- byte[] bytes;
-
- public XdrString(byte[] bytes) {
- this.bytes = bytes;
- }
-
- public XdrString(String text) {
- this.bytes = text.getBytes(StandardCharsets.UTF_8);
- }
-
- @Override
- public void encode(XdrDataOutputStream stream) throws IOException {
- stream.writeInt(this.bytes.length);
- stream.write(this.bytes, 0, this.bytes.length);
- }
-
- public static XdrString decode(XdrDataInputStream stream, int maxSize) throws IOException {
- int size = stream.readInt();
- if (size > maxSize) {
- throw new IllegalArgumentException("String length " + size + " exceeds max size " + maxSize);
- }
- byte[] bytes = new byte[size];
- stream.read(bytes);
- return new XdrString(bytes);
- }
-
- public static XdrString fromXdrBase64(String xdr, int maxSize) throws IOException {
- byte[] bytes = Base64Factory.getInstance().decode(xdr);
- return fromXdrByteArray(bytes, maxSize);
- }
-
- public static XdrString fromXdrBase64(String xdr) throws IOException {
- return fromXdrBase64(xdr, Integer.MAX_VALUE);
- }
-
- public static XdrString fromXdrByteArray(byte[] xdr, int maxSize) throws IOException {
- ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr);
- XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream);
- return decode(xdrDataInputStream, maxSize);
- }
-
- public static XdrString fromXdrByteArray(byte[] xdr) throws IOException {
- return fromXdrByteArray(xdr, Integer.MAX_VALUE);
- }
-
- @Override
- public String toString() {
- return new String(bytes, StandardCharsets.UTF_8);
- }
-}
diff --git a/spec/output/generator_spec_java/optional.x/XdrUnsignedHyperInteger.java b/spec/output/generator_spec_java/optional.x/XdrUnsignedHyperInteger.java
deleted file mode 100644
index 5d798cded..000000000
--- a/spec/output/generator_spec_java/optional.x/XdrUnsignedHyperInteger.java
+++ /dev/null
@@ -1,69 +0,0 @@
-package MyXDR;
-
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import java.math.BigInteger;
-import lombok.Value;
-import org.stellar.sdk.Base64Factory;
-
-/**
- * Represents XDR Unsigned Hyper Integer.
- *
- * @see XDR: External Data
- * Representation Standard
- */
-@Value
-public class XdrUnsignedHyperInteger implements XdrElement {
- public static final BigInteger MAX_VALUE = new BigInteger("18446744073709551615");
- public static final BigInteger MIN_VALUE = BigInteger.ZERO;
- BigInteger number;
-
- public XdrUnsignedHyperInteger(BigInteger number) {
- if (number.compareTo(MIN_VALUE) < 0 || number.compareTo(MAX_VALUE) > 0) {
- throw new IllegalArgumentException("number must be between 0 and 2^64 - 1 inclusive");
- }
- this.number = number;
- }
-
- public XdrUnsignedHyperInteger(Long number) {
- if (number < 0) {
- throw new IllegalArgumentException(
- "number must be greater than or equal to 0 if you want to construct it from Long");
- }
- this.number = BigInteger.valueOf(number);
- }
-
- @Override
- public void encode(XdrDataOutputStream stream) throws IOException {
- stream.write(getBytes());
- }
-
- public static XdrUnsignedHyperInteger decode(XdrDataInputStream stream) throws IOException {
- byte[] bytes = new byte[8];
- stream.readFully(bytes);
- BigInteger uint64 = new BigInteger(1, bytes);
- return new XdrUnsignedHyperInteger(uint64);
- }
-
- private byte[] getBytes() {
- byte[] bytes = number.toByteArray();
- byte[] paddedBytes = new byte[8];
-
- int numBytesToCopy = Math.min(bytes.length, 8);
- int copyStartIndex = bytes.length - numBytesToCopy;
- System.arraycopy(bytes, copyStartIndex, paddedBytes, 8 - numBytesToCopy, numBytesToCopy);
- return paddedBytes;
- }
-
- public static XdrUnsignedHyperInteger fromXdrBase64(String xdr) throws IOException {
- byte[] bytes = Base64Factory.getInstance().decode(xdr);
- return fromXdrByteArray(bytes);
- }
-
- public static XdrUnsignedHyperInteger fromXdrByteArray(byte[] xdr) throws IOException {
- ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr);
- XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream);
- return decode(xdrDataInputStream);
- }
-}
diff --git a/spec/output/generator_spec_java/optional.x/XdrUnsignedInteger.java b/spec/output/generator_spec_java/optional.x/XdrUnsignedInteger.java
deleted file mode 100644
index bea880aee..000000000
--- a/spec/output/generator_spec_java/optional.x/XdrUnsignedInteger.java
+++ /dev/null
@@ -1,57 +0,0 @@
-package MyXDR;
-
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import lombok.Value;
-import org.stellar.sdk.Base64Factory;
-
-/**
- * Represents XDR Unsigned Integer.
- *
- * @see XDR: External Data
- * Representation Standard
- */
-@Value
-public class XdrUnsignedInteger implements XdrElement {
- public static final long MAX_VALUE = (1L << 32) - 1;
- public static final long MIN_VALUE = 0;
- Long number;
-
- public XdrUnsignedInteger(Long number) {
- if (number < MIN_VALUE || number > MAX_VALUE) {
- throw new IllegalArgumentException("number must be between 0 and 2^32 - 1 inclusive");
- }
- this.number = number;
- }
-
- public XdrUnsignedInteger(Integer number) {
- if (number < 0) {
- throw new IllegalArgumentException(
- "number must be greater than or equal to 0 if you want to construct it from Integer");
- }
- this.number = number.longValue();
- }
-
- public static XdrUnsignedInteger decode(XdrDataInputStream stream) throws IOException {
- int intValue = stream.readInt();
- long uint32Value = Integer.toUnsignedLong(intValue);
- return new XdrUnsignedInteger(uint32Value);
- }
-
- @Override
- public void encode(XdrDataOutputStream stream) throws IOException {
- stream.writeInt(number.intValue());
- }
-
- public static XdrUnsignedInteger fromXdrBase64(String xdr) throws IOException {
- byte[] bytes = Base64Factory.getInstance().decode(xdr);
- return fromXdrByteArray(bytes);
- }
-
- public static XdrUnsignedInteger fromXdrByteArray(byte[] xdr) throws IOException {
- ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr);
- XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream);
- return decode(xdrDataInputStream);
- }
-}
diff --git a/spec/output/generator_spec_java/struct.x/Constants.java b/spec/output/generator_spec_java/struct.x/Constants.java
deleted file mode 100644
index d7d9f4cfc..000000000
--- a/spec/output/generator_spec_java/struct.x/Constants.java
+++ /dev/null
@@ -1,10 +0,0 @@
-// Automatically generated by xdrgen
-// DO NOT EDIT or your changes may be overwritten
-
-package MyXDR;
-
-import java.io.IOException;
-
-public final class Constants {
- private Constants() {}
-}
diff --git a/spec/output/generator_spec_java/struct.x/Int64.java b/spec/output/generator_spec_java/struct.x/Int64.java
deleted file mode 100644
index 2ea7adf9b..000000000
--- a/spec/output/generator_spec_java/struct.x/Int64.java
+++ /dev/null
@@ -1,46 +0,0 @@
-// Automatically generated by xdrgen
-// DO NOT EDIT or your changes may be overwritten
-
-package MyXDR;
-
-import java.io.IOException;
-
-import org.stellar.sdk.Base64Factory;
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import lombok.Data;
-import lombok.NoArgsConstructor;
-import lombok.AllArgsConstructor;
-
-/**
- * Int64's original definition in the XDR file is:
- * - * typedef hyper int64; - *- */ -@Data -@NoArgsConstructor -@AllArgsConstructor -public class Int64 implements XdrElement { - private Long int64; - public void encode(XdrDataOutputStream stream) throws IOException { - stream.writeLong(int64); - } - - public static Int64 decode(XdrDataInputStream stream) throws IOException { - Int64 decodedInt64 = new Int64(); - decodedInt64.int64 = stream.readLong(); - return decodedInt64; - } - - public static Int64 fromXdrBase64(String xdr) throws IOException { - byte[] bytes = Base64Factory.getInstance().decode(xdr); - return fromXdrByteArray(bytes); - } - - public static Int64 fromXdrByteArray(byte[] xdr) throws IOException { - ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); - XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); - return decode(xdrDataInputStream); - } -} diff --git a/spec/output/generator_spec_java/struct.x/MyStruct.java b/spec/output/generator_spec_java/struct.x/MyStruct.java deleted file mode 100644 index 446224f88..000000000 --- a/spec/output/generator_spec_java/struct.x/MyStruct.java +++ /dev/null @@ -1,68 +0,0 @@ -// Automatically generated by xdrgen -// DO NOT EDIT or your changes may be overwritten - -package MyXDR; - -import java.io.IOException; - -import org.stellar.sdk.Base64Factory; -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; -import lombok.Data; -import lombok.NoArgsConstructor; -import lombok.AllArgsConstructor; -import lombok.Builder; - -/** - * MyStruct's original definition in the XDR file is: - *
- * struct MyStruct
- * {
- * int someInt;
- * int64 aBigInt;
- * opaque someOpaque[10];
- * string someString<>;
- * string maxString<100>;
- * };
- *
- */
-@Data
-@NoArgsConstructor
-@AllArgsConstructor
-@Builder(toBuilder = true)
-public class MyStruct implements XdrElement {
- private Integer someInt;
- private Int64 aBigInt;
- private byte[] someOpaque;
- private XdrString someString;
- private XdrString maxString;
- public void encode(XdrDataOutputStream stream) throws IOException{
- stream.writeInt(someInt);
- aBigInt.encode(stream);
- int someOpaqueSize = someOpaque.length;
- stream.write(getSomeOpaque(), 0, someOpaqueSize);
- someString.encode(stream);
- maxString.encode(stream);
- }
- public static MyStruct decode(XdrDataInputStream stream) throws IOException {
- MyStruct decodedMyStruct = new MyStruct();
- decodedMyStruct.someInt = stream.readInt();
- decodedMyStruct.aBigInt = Int64.decode(stream);
- int someOpaqueSize = 10;
- decodedMyStruct.someOpaque = new byte[someOpaqueSize];
- stream.read(decodedMyStruct.someOpaque, 0, someOpaqueSize);
- decodedMyStruct.someString = XdrString.decode(stream, Integer.MAX_VALUE);
- decodedMyStruct.maxString = XdrString.decode(stream, 100);
- return decodedMyStruct;
- }
- public static MyStruct fromXdrBase64(String xdr) throws IOException {
- byte[] bytes = Base64Factory.getInstance().decode(xdr);
- return fromXdrByteArray(bytes);
- }
-
- public static MyStruct fromXdrByteArray(byte[] xdr) throws IOException {
- ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr);
- XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream);
- return decode(xdrDataInputStream);
- }
-}
diff --git a/spec/output/generator_spec_java/struct.x/XdrDataInputStream.java b/spec/output/generator_spec_java/struct.x/XdrDataInputStream.java
deleted file mode 100644
index 6d6592026..000000000
--- a/spec/output/generator_spec_java/struct.x/XdrDataInputStream.java
+++ /dev/null
@@ -1,122 +0,0 @@
-package MyXDR;
-
-import java.io.DataInputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.nio.charset.Charset;
-
-public class XdrDataInputStream extends DataInputStream {
-
- // The underlying input stream
- private final XdrInputStream mIn;
-
- /**
- * Creates a XdrDataInputStream that uses the specified
- * underlying InputStream.
- *
- * @param in the specified input stream
- */
- public XdrDataInputStream(InputStream in) {
- super(new XdrInputStream(in));
- mIn = (XdrInputStream) super.in;
- }
-
- public int[] readIntArray() throws IOException {
- int l = readInt();
- return readIntArray(l);
- }
-
- private int[] readIntArray(int l) throws IOException {
- int[] arr = new int[l];
- for (int i = 0; i < l; i++) {
- arr[i] = readInt();
- }
- return arr;
- }
-
- public float[] readFloatArray() throws IOException {
- int l = readInt();
- return readFloatArray(l);
- }
-
- private float[] readFloatArray(int l) throws IOException {
- float[] arr = new float[l];
- for (int i = 0; i < l; i++) {
- arr[i] = readFloat();
- }
- return arr;
- }
-
- public double[] readDoubleArray() throws IOException {
- int l = readInt();
- return readDoubleArray(l);
- }
-
- private double[] readDoubleArray(int l) throws IOException {
- double[] arr = new double[l];
- for (int i = 0; i < l; i++) {
- arr[i] = readDouble();
- }
- return arr;
- }
-
- @Override
- public int read() throws IOException {
- return super.read();
- }
-
- /**
- * Need to provide a custom impl of InputStream as DataInputStream's read methods
- * are final and we need to keep track of the count for padding purposes.
- */
- private static final class XdrInputStream extends InputStream {
-
- // The underlying input stream
- private final InputStream mIn;
-
- // The amount of bytes read so far.
- private int mCount;
-
- public XdrInputStream(InputStream in) {
- mIn = in;
- mCount = 0;
- }
-
- @Override
- public int read() throws IOException {
- int read = mIn.read();
- if (read >= 0) {
- mCount++;
- }
- return read;
- }
-
- @Override
- public int read(byte[] b) throws IOException {
- return read(b, 0, b.length);
- }
-
- @Override
- public int read(byte[] b, int off, int len) throws IOException {
- int read = mIn.read(b, off, len);
- mCount += read;
- pad();
- return read;
- }
-
- public void pad() throws IOException {
- int pad = 0;
- int mod = mCount % 4;
- if (mod > 0) {
- pad = 4-mod;
- }
-
- while (pad-- > 0) {
- int b = read();
- if (b != 0) {
- throw new IOException("non-zero padding");
- }
- }
- }
- }
-}
diff --git a/spec/output/generator_spec_java/struct.x/XdrDataOutputStream.java b/spec/output/generator_spec_java/struct.x/XdrDataOutputStream.java
deleted file mode 100644
index 729aec05b..000000000
--- a/spec/output/generator_spec_java/struct.x/XdrDataOutputStream.java
+++ /dev/null
@@ -1,96 +0,0 @@
-package MyXDR;
-
-import java.io.DataOutputStream;
-import java.io.IOException;
-import java.io.OutputStream;
-import java.nio.charset.Charset;
-
-public class XdrDataOutputStream extends DataOutputStream {
-
- private final XdrOutputStream mOut;
-
- public XdrDataOutputStream(OutputStream out) {
- super(new XdrOutputStream(out));
- mOut = (XdrOutputStream) super.out;
- }
-
- public void writeIntArray(int[] a) throws IOException {
- writeInt(a.length);
- writeIntArray(a, a.length);
- }
-
- private void writeIntArray(int[] a, int l) throws IOException {
- for (int i = 0; i < l; i++) {
- writeInt(a[i]);
- }
- }
-
- public void writeFloatArray(float[] a) throws IOException {
- writeInt(a.length);
- writeFloatArray(a, a.length);
- }
-
- private void writeFloatArray(float[] a, int l) throws IOException {
- for (int i = 0; i < l; i++) {
- writeFloat(a[i]);
- }
- }
-
- public void writeDoubleArray(double[] a) throws IOException {
- writeInt(a.length);
- writeDoubleArray(a, a.length);
- }
-
- private void writeDoubleArray(double[] a, int l) throws IOException {
- for (int i = 0; i < l; i++) {
- writeDouble(a[i]);
- }
- }
-
- private static final class XdrOutputStream extends OutputStream {
-
- private final OutputStream mOut;
-
- // Number of bytes written
- private int mCount;
-
- public XdrOutputStream(OutputStream out) {
- mOut = out;
- mCount = 0;
- }
-
- @Override
- public void write(int b) throws IOException {
- mOut.write(b);
- // https://docs.oracle.com/javase/7/docs/api/java/io/OutputStream.html#write(int):
- // > The byte to be written is the eight low-order bits of the argument b.
- // > The 24 high-order bits of b are ignored.
- mCount++;
- }
-
- @Override
- public void write(byte[] b) throws IOException {
- // https://docs.oracle.com/javase/7/docs/api/java/io/OutputStream.html#write(byte[]):
- // > The general contract for write(b) is that it should have exactly the same effect
- // > as the call write(b, 0, b.length).
- write(b, 0, b.length);
- }
-
- public void write(byte[] b, int offset, int length) throws IOException {
- mOut.write(b, offset, length);
- mCount += length;
- pad();
- }
-
- public void pad() throws IOException {
- int pad = 0;
- int mod = mCount % 4;
- if (mod > 0) {
- pad = 4-mod;
- }
- while (pad-- > 0) {
- write(0);
- }
- }
- }
-}
diff --git a/spec/output/generator_spec_java/struct.x/XdrElement.java b/spec/output/generator_spec_java/struct.x/XdrElement.java
deleted file mode 100644
index 453491ea2..000000000
--- a/spec/output/generator_spec_java/struct.x/XdrElement.java
+++ /dev/null
@@ -1,21 +0,0 @@
-package MyXDR;
-
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import org.stellar.sdk.Base64Factory;
-
-/** Common parent interface for all generated classes. */
-interface XdrElement {
- void encode(XdrDataOutputStream stream) throws IOException;
-
- default String toXdrBase64() throws IOException {
- return Base64Factory.getInstance().encodeToString(toXdrByteArray());
- }
-
- default byte[] toXdrByteArray() throws IOException {
- ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
- XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream);
- encode(xdrDataOutputStream);
- return byteArrayOutputStream.toByteArray();
- }
-}
diff --git a/spec/output/generator_spec_java/struct.x/XdrString.java b/spec/output/generator_spec_java/struct.x/XdrString.java
deleted file mode 100644
index a51eead77..000000000
--- a/spec/output/generator_spec_java/struct.x/XdrString.java
+++ /dev/null
@@ -1,62 +0,0 @@
-package MyXDR;
-
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import java.io.InvalidClassException;
-import java.nio.charset.StandardCharsets;
-import lombok.Value;
-import org.stellar.sdk.Base64Factory;
-
-@Value
-public class XdrString implements XdrElement {
- byte[] bytes;
-
- public XdrString(byte[] bytes) {
- this.bytes = bytes;
- }
-
- public XdrString(String text) {
- this.bytes = text.getBytes(StandardCharsets.UTF_8);
- }
-
- @Override
- public void encode(XdrDataOutputStream stream) throws IOException {
- stream.writeInt(this.bytes.length);
- stream.write(this.bytes, 0, this.bytes.length);
- }
-
- public static XdrString decode(XdrDataInputStream stream, int maxSize) throws IOException {
- int size = stream.readInt();
- if (size > maxSize) {
- throw new IllegalArgumentException("String length " + size + " exceeds max size " + maxSize);
- }
- byte[] bytes = new byte[size];
- stream.read(bytes);
- return new XdrString(bytes);
- }
-
- public static XdrString fromXdrBase64(String xdr, int maxSize) throws IOException {
- byte[] bytes = Base64Factory.getInstance().decode(xdr);
- return fromXdrByteArray(bytes, maxSize);
- }
-
- public static XdrString fromXdrBase64(String xdr) throws IOException {
- return fromXdrBase64(xdr, Integer.MAX_VALUE);
- }
-
- public static XdrString fromXdrByteArray(byte[] xdr, int maxSize) throws IOException {
- ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr);
- XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream);
- return decode(xdrDataInputStream, maxSize);
- }
-
- public static XdrString fromXdrByteArray(byte[] xdr) throws IOException {
- return fromXdrByteArray(xdr, Integer.MAX_VALUE);
- }
-
- @Override
- public String toString() {
- return new String(bytes, StandardCharsets.UTF_8);
- }
-}
diff --git a/spec/output/generator_spec_java/struct.x/XdrUnsignedHyperInteger.java b/spec/output/generator_spec_java/struct.x/XdrUnsignedHyperInteger.java
deleted file mode 100644
index 5d798cded..000000000
--- a/spec/output/generator_spec_java/struct.x/XdrUnsignedHyperInteger.java
+++ /dev/null
@@ -1,69 +0,0 @@
-package MyXDR;
-
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import java.math.BigInteger;
-import lombok.Value;
-import org.stellar.sdk.Base64Factory;
-
-/**
- * Represents XDR Unsigned Hyper Integer.
- *
- * @see XDR: External Data
- * Representation Standard
- */
-@Value
-public class XdrUnsignedHyperInteger implements XdrElement {
- public static final BigInteger MAX_VALUE = new BigInteger("18446744073709551615");
- public static final BigInteger MIN_VALUE = BigInteger.ZERO;
- BigInteger number;
-
- public XdrUnsignedHyperInteger(BigInteger number) {
- if (number.compareTo(MIN_VALUE) < 0 || number.compareTo(MAX_VALUE) > 0) {
- throw new IllegalArgumentException("number must be between 0 and 2^64 - 1 inclusive");
- }
- this.number = number;
- }
-
- public XdrUnsignedHyperInteger(Long number) {
- if (number < 0) {
- throw new IllegalArgumentException(
- "number must be greater than or equal to 0 if you want to construct it from Long");
- }
- this.number = BigInteger.valueOf(number);
- }
-
- @Override
- public void encode(XdrDataOutputStream stream) throws IOException {
- stream.write(getBytes());
- }
-
- public static XdrUnsignedHyperInteger decode(XdrDataInputStream stream) throws IOException {
- byte[] bytes = new byte[8];
- stream.readFully(bytes);
- BigInteger uint64 = new BigInteger(1, bytes);
- return new XdrUnsignedHyperInteger(uint64);
- }
-
- private byte[] getBytes() {
- byte[] bytes = number.toByteArray();
- byte[] paddedBytes = new byte[8];
-
- int numBytesToCopy = Math.min(bytes.length, 8);
- int copyStartIndex = bytes.length - numBytesToCopy;
- System.arraycopy(bytes, copyStartIndex, paddedBytes, 8 - numBytesToCopy, numBytesToCopy);
- return paddedBytes;
- }
-
- public static XdrUnsignedHyperInteger fromXdrBase64(String xdr) throws IOException {
- byte[] bytes = Base64Factory.getInstance().decode(xdr);
- return fromXdrByteArray(bytes);
- }
-
- public static XdrUnsignedHyperInteger fromXdrByteArray(byte[] xdr) throws IOException {
- ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr);
- XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream);
- return decode(xdrDataInputStream);
- }
-}
diff --git a/spec/output/generator_spec_java/struct.x/XdrUnsignedInteger.java b/spec/output/generator_spec_java/struct.x/XdrUnsignedInteger.java
deleted file mode 100644
index bea880aee..000000000
--- a/spec/output/generator_spec_java/struct.x/XdrUnsignedInteger.java
+++ /dev/null
@@ -1,57 +0,0 @@
-package MyXDR;
-
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import lombok.Value;
-import org.stellar.sdk.Base64Factory;
-
-/**
- * Represents XDR Unsigned Integer.
- *
- * @see XDR: External Data
- * Representation Standard
- */
-@Value
-public class XdrUnsignedInteger implements XdrElement {
- public static final long MAX_VALUE = (1L << 32) - 1;
- public static final long MIN_VALUE = 0;
- Long number;
-
- public XdrUnsignedInteger(Long number) {
- if (number < MIN_VALUE || number > MAX_VALUE) {
- throw new IllegalArgumentException("number must be between 0 and 2^32 - 1 inclusive");
- }
- this.number = number;
- }
-
- public XdrUnsignedInteger(Integer number) {
- if (number < 0) {
- throw new IllegalArgumentException(
- "number must be greater than or equal to 0 if you want to construct it from Integer");
- }
- this.number = number.longValue();
- }
-
- public static XdrUnsignedInteger decode(XdrDataInputStream stream) throws IOException {
- int intValue = stream.readInt();
- long uint32Value = Integer.toUnsignedLong(intValue);
- return new XdrUnsignedInteger(uint32Value);
- }
-
- @Override
- public void encode(XdrDataOutputStream stream) throws IOException {
- stream.writeInt(number.intValue());
- }
-
- public static XdrUnsignedInteger fromXdrBase64(String xdr) throws IOException {
- byte[] bytes = Base64Factory.getInstance().decode(xdr);
- return fromXdrByteArray(bytes);
- }
-
- public static XdrUnsignedInteger fromXdrByteArray(byte[] xdr) throws IOException {
- ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr);
- XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream);
- return decode(xdrDataInputStream);
- }
-}
diff --git a/spec/output/generator_spec_java/test.x/Color.java b/spec/output/generator_spec_java/test.x/Color.java
deleted file mode 100644
index 2199ca352..000000000
--- a/spec/output/generator_spec_java/test.x/Color.java
+++ /dev/null
@@ -1,61 +0,0 @@
-// Automatically generated by xdrgen
-// DO NOT EDIT or your changes may be overwritten
-
-package MyXDR;
-
-import java.io.IOException;
-
-import org.stellar.sdk.Base64Factory;
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-
-/**
- * Color's original definition in the XDR file is:
- *
- * enum Color {
- * RED,
- * BLUE = 5,
- * GREEN
- * };
- *
- */
-public enum Color implements XdrElement {
- RED(0),
- BLUE(5),
- GREEN(6);
-
- private final int value;
-
- Color(int value) {
- this.value = value;
- }
-
- public int getValue() {
- return value;
- }
-
- public static Color decode(XdrDataInputStream stream) throws IOException {
- int value = stream.readInt();
- switch (value) {
- case 0: return RED;
- case 5: return BLUE;
- case 6: return GREEN;
- default:
- throw new IllegalArgumentException("Unknown enum value: " + value);
- }
- }
-
- public void encode(XdrDataOutputStream stream) throws IOException {
- stream.writeInt(value);
- }
- public static Color fromXdrBase64(String xdr) throws IOException {
- byte[] bytes = Base64Factory.getInstance().decode(xdr);
- return fromXdrByteArray(bytes);
- }
-
- public static Color fromXdrByteArray(byte[] xdr) throws IOException {
- ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr);
- XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream);
- return decode(xdrDataInputStream);
- }
-}
diff --git a/spec/output/generator_spec_java/test.x/Constants.java b/spec/output/generator_spec_java/test.x/Constants.java
deleted file mode 100644
index 646061555..000000000
--- a/spec/output/generator_spec_java/test.x/Constants.java
+++ /dev/null
@@ -1,12 +0,0 @@
-// Automatically generated by xdrgen
-// DO NOT EDIT or your changes may be overwritten
-
-package MyXDR;
-
-import java.io.IOException;
-
-public final class Constants {
- private Constants() {}
- public static final int FOO = 1244;
- public static final int BAR = FOO;
-}
diff --git a/spec/output/generator_spec_java/test.x/HasStuff.java b/spec/output/generator_spec_java/test.x/HasStuff.java
deleted file mode 100644
index 2b98be3ec..000000000
--- a/spec/output/generator_spec_java/test.x/HasStuff.java
+++ /dev/null
@@ -1,49 +0,0 @@
-// Automatically generated by xdrgen
-// DO NOT EDIT or your changes may be overwritten
-
-package MyXDR;
-
-import java.io.IOException;
-
-import org.stellar.sdk.Base64Factory;
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import lombok.Data;
-import lombok.NoArgsConstructor;
-import lombok.AllArgsConstructor;
-import lombok.Builder;
-
-/**
- * HasStuff's original definition in the XDR file is:
- *
- * struct HasStuff
- * {
- * LotsOfMyStructs data;
- * };
- *
- */
-@Data
-@NoArgsConstructor
-@AllArgsConstructor
-@Builder(toBuilder = true)
-public class HasStuff implements XdrElement {
- private LotsOfMyStructs data;
- public void encode(XdrDataOutputStream stream) throws IOException{
- data.encode(stream);
- }
- public static HasStuff decode(XdrDataInputStream stream) throws IOException {
- HasStuff decodedHasStuff = new HasStuff();
- decodedHasStuff.data = LotsOfMyStructs.decode(stream);
- return decodedHasStuff;
- }
- public static HasStuff fromXdrBase64(String xdr) throws IOException {
- byte[] bytes = Base64Factory.getInstance().decode(xdr);
- return fromXdrByteArray(bytes);
- }
-
- public static HasStuff fromXdrByteArray(byte[] xdr) throws IOException {
- ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr);
- XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream);
- return decode(xdrDataInputStream);
- }
-}
diff --git a/spec/output/generator_spec_java/test.x/Hash.java b/spec/output/generator_spec_java/test.x/Hash.java
deleted file mode 100644
index 2546f2dcf..000000000
--- a/spec/output/generator_spec_java/test.x/Hash.java
+++ /dev/null
@@ -1,49 +0,0 @@
-// Automatically generated by xdrgen
-// DO NOT EDIT or your changes may be overwritten
-
-package MyXDR;
-
-import java.io.IOException;
-
-import org.stellar.sdk.Base64Factory;
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import lombok.Data;
-import lombok.NoArgsConstructor;
-import lombok.AllArgsConstructor;
-
-/**
- * Hash's original definition in the XDR file is:
- * - * typedef opaque Hash[32]; - *- */ -@Data -@NoArgsConstructor -@AllArgsConstructor -public class Hash implements XdrElement { - private byte[] Hash; - public void encode(XdrDataOutputStream stream) throws IOException { - int HashSize = Hash.length; - stream.write(getHash(), 0, HashSize); - } - - public static Hash decode(XdrDataInputStream stream) throws IOException { - Hash decodedHash = new Hash(); - int HashSize = 32; - decodedHash.Hash = new byte[HashSize]; - stream.read(decodedHash.Hash, 0, HashSize); - return decodedHash; - } - - public static Hash fromXdrBase64(String xdr) throws IOException { - byte[] bytes = Base64Factory.getInstance().decode(xdr); - return fromXdrByteArray(bytes); - } - - public static Hash fromXdrByteArray(byte[] xdr) throws IOException { - ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); - XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); - return decode(xdrDataInputStream); - } -} diff --git a/spec/output/generator_spec_java/test.x/Hashes1.java b/spec/output/generator_spec_java/test.x/Hashes1.java deleted file mode 100644 index bb181417c..000000000 --- a/spec/output/generator_spec_java/test.x/Hashes1.java +++ /dev/null @@ -1,53 +0,0 @@ -// Automatically generated by xdrgen -// DO NOT EDIT or your changes may be overwritten - -package MyXDR; - -import java.io.IOException; - -import org.stellar.sdk.Base64Factory; -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; -import lombok.Data; -import lombok.NoArgsConstructor; -import lombok.AllArgsConstructor; - -/** - * Hashes1's original definition in the XDR file is: - *
- * typedef Hash Hashes1[12]; - *- */ -@Data -@NoArgsConstructor -@AllArgsConstructor -public class Hashes1 implements XdrElement { - private Hash[] Hashes1; - public void encode(XdrDataOutputStream stream) throws IOException { - int Hashes1Size = getHashes1().length; - for (int i = 0; i < Hashes1Size; i++) { - Hashes1[i].encode(stream); - } - } - - public static Hashes1 decode(XdrDataInputStream stream) throws IOException { - Hashes1 decodedHashes1 = new Hashes1(); - int Hashes1Size = 12; - decodedHashes1.Hashes1 = new Hash[Hashes1Size]; - for (int i = 0; i < Hashes1Size; i++) { - decodedHashes1.Hashes1[i] = Hash.decode(stream); - } - return decodedHashes1; - } - - public static Hashes1 fromXdrBase64(String xdr) throws IOException { - byte[] bytes = Base64Factory.getInstance().decode(xdr); - return fromXdrByteArray(bytes); - } - - public static Hashes1 fromXdrByteArray(byte[] xdr) throws IOException { - ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); - XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); - return decode(xdrDataInputStream); - } -} diff --git a/spec/output/generator_spec_java/test.x/Hashes2.java b/spec/output/generator_spec_java/test.x/Hashes2.java deleted file mode 100644 index 009e6a06f..000000000 --- a/spec/output/generator_spec_java/test.x/Hashes2.java +++ /dev/null @@ -1,54 +0,0 @@ -// Automatically generated by xdrgen -// DO NOT EDIT or your changes may be overwritten - -package MyXDR; - -import java.io.IOException; - -import org.stellar.sdk.Base64Factory; -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; -import lombok.Data; -import lombok.NoArgsConstructor; -import lombok.AllArgsConstructor; - -/** - * Hashes2's original definition in the XDR file is: - *
- * typedef Hash Hashes2<12>; - *- */ -@Data -@NoArgsConstructor -@AllArgsConstructor -public class Hashes2 implements XdrElement { - private Hash[] Hashes2; - public void encode(XdrDataOutputStream stream) throws IOException { - int Hashes2Size = getHashes2().length; - stream.writeInt(Hashes2Size); - for (int i = 0; i < Hashes2Size; i++) { - Hashes2[i].encode(stream); - } - } - - public static Hashes2 decode(XdrDataInputStream stream) throws IOException { - Hashes2 decodedHashes2 = new Hashes2(); - int Hashes2Size = stream.readInt(); - decodedHashes2.Hashes2 = new Hash[Hashes2Size]; - for (int i = 0; i < Hashes2Size; i++) { - decodedHashes2.Hashes2[i] = Hash.decode(stream); - } - return decodedHashes2; - } - - public static Hashes2 fromXdrBase64(String xdr) throws IOException { - byte[] bytes = Base64Factory.getInstance().decode(xdr); - return fromXdrByteArray(bytes); - } - - public static Hashes2 fromXdrByteArray(byte[] xdr) throws IOException { - ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); - XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); - return decode(xdrDataInputStream); - } -} diff --git a/spec/output/generator_spec_java/test.x/Hashes3.java b/spec/output/generator_spec_java/test.x/Hashes3.java deleted file mode 100644 index c8c6c5cf4..000000000 --- a/spec/output/generator_spec_java/test.x/Hashes3.java +++ /dev/null @@ -1,54 +0,0 @@ -// Automatically generated by xdrgen -// DO NOT EDIT or your changes may be overwritten - -package MyXDR; - -import java.io.IOException; - -import org.stellar.sdk.Base64Factory; -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; -import lombok.Data; -import lombok.NoArgsConstructor; -import lombok.AllArgsConstructor; - -/** - * Hashes3's original definition in the XDR file is: - *
- * typedef Hash Hashes3<>; - *- */ -@Data -@NoArgsConstructor -@AllArgsConstructor -public class Hashes3 implements XdrElement { - private Hash[] Hashes3; - public void encode(XdrDataOutputStream stream) throws IOException { - int Hashes3Size = getHashes3().length; - stream.writeInt(Hashes3Size); - for (int i = 0; i < Hashes3Size; i++) { - Hashes3[i].encode(stream); - } - } - - public static Hashes3 decode(XdrDataInputStream stream) throws IOException { - Hashes3 decodedHashes3 = new Hashes3(); - int Hashes3Size = stream.readInt(); - decodedHashes3.Hashes3 = new Hash[Hashes3Size]; - for (int i = 0; i < Hashes3Size; i++) { - decodedHashes3.Hashes3[i] = Hash.decode(stream); - } - return decodedHashes3; - } - - public static Hashes3 fromXdrBase64(String xdr) throws IOException { - byte[] bytes = Base64Factory.getInstance().decode(xdr); - return fromXdrByteArray(bytes); - } - - public static Hashes3 fromXdrByteArray(byte[] xdr) throws IOException { - ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); - XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); - return decode(xdrDataInputStream); - } -} diff --git a/spec/output/generator_spec_java/test.x/Int1.java b/spec/output/generator_spec_java/test.x/Int1.java deleted file mode 100644 index 499189275..000000000 --- a/spec/output/generator_spec_java/test.x/Int1.java +++ /dev/null @@ -1,46 +0,0 @@ -// Automatically generated by xdrgen -// DO NOT EDIT or your changes may be overwritten - -package MyXDR; - -import java.io.IOException; - -import org.stellar.sdk.Base64Factory; -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; -import lombok.Data; -import lombok.NoArgsConstructor; -import lombok.AllArgsConstructor; - -/** - * Int1's original definition in the XDR file is: - *
- * typedef int int1; - *- */ -@Data -@NoArgsConstructor -@AllArgsConstructor -public class Int1 implements XdrElement { - private Integer int1; - public void encode(XdrDataOutputStream stream) throws IOException { - stream.writeInt(int1); - } - - public static Int1 decode(XdrDataInputStream stream) throws IOException { - Int1 decodedInt1 = new Int1(); - decodedInt1.int1 = stream.readInt(); - return decodedInt1; - } - - public static Int1 fromXdrBase64(String xdr) throws IOException { - byte[] bytes = Base64Factory.getInstance().decode(xdr); - return fromXdrByteArray(bytes); - } - - public static Int1 fromXdrByteArray(byte[] xdr) throws IOException { - ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); - XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); - return decode(xdrDataInputStream); - } -} diff --git a/spec/output/generator_spec_java/test.x/Int2.java b/spec/output/generator_spec_java/test.x/Int2.java deleted file mode 100644 index 8b600e54e..000000000 --- a/spec/output/generator_spec_java/test.x/Int2.java +++ /dev/null @@ -1,46 +0,0 @@ -// Automatically generated by xdrgen -// DO NOT EDIT or your changes may be overwritten - -package MyXDR; - -import java.io.IOException; - -import org.stellar.sdk.Base64Factory; -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; -import lombok.Data; -import lombok.NoArgsConstructor; -import lombok.AllArgsConstructor; - -/** - * Int2's original definition in the XDR file is: - *
- * typedef hyper int2; - *- */ -@Data -@NoArgsConstructor -@AllArgsConstructor -public class Int2 implements XdrElement { - private Long int2; - public void encode(XdrDataOutputStream stream) throws IOException { - stream.writeLong(int2); - } - - public static Int2 decode(XdrDataInputStream stream) throws IOException { - Int2 decodedInt2 = new Int2(); - decodedInt2.int2 = stream.readLong(); - return decodedInt2; - } - - public static Int2 fromXdrBase64(String xdr) throws IOException { - byte[] bytes = Base64Factory.getInstance().decode(xdr); - return fromXdrByteArray(bytes); - } - - public static Int2 fromXdrByteArray(byte[] xdr) throws IOException { - ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); - XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); - return decode(xdrDataInputStream); - } -} diff --git a/spec/output/generator_spec_java/test.x/Int3.java b/spec/output/generator_spec_java/test.x/Int3.java deleted file mode 100644 index 86e303c0b..000000000 --- a/spec/output/generator_spec_java/test.x/Int3.java +++ /dev/null @@ -1,46 +0,0 @@ -// Automatically generated by xdrgen -// DO NOT EDIT or your changes may be overwritten - -package MyXDR; - -import java.io.IOException; - -import org.stellar.sdk.Base64Factory; -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; -import lombok.Data; -import lombok.NoArgsConstructor; -import lombok.AllArgsConstructor; - -/** - * Int3's original definition in the XDR file is: - *
- * typedef unsigned int int3; - *- */ -@Data -@NoArgsConstructor -@AllArgsConstructor -public class Int3 implements XdrElement { - private XdrUnsignedInteger int3; - public void encode(XdrDataOutputStream stream) throws IOException { - int3.encode(stream); - } - - public static Int3 decode(XdrDataInputStream stream) throws IOException { - Int3 decodedInt3 = new Int3(); - decodedInt3.int3 = XdrUnsignedInteger.decode(stream); - return decodedInt3; - } - - public static Int3 fromXdrBase64(String xdr) throws IOException { - byte[] bytes = Base64Factory.getInstance().decode(xdr); - return fromXdrByteArray(bytes); - } - - public static Int3 fromXdrByteArray(byte[] xdr) throws IOException { - ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); - XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); - return decode(xdrDataInputStream); - } -} diff --git a/spec/output/generator_spec_java/test.x/Int4.java b/spec/output/generator_spec_java/test.x/Int4.java deleted file mode 100644 index 69c5a608b..000000000 --- a/spec/output/generator_spec_java/test.x/Int4.java +++ /dev/null @@ -1,46 +0,0 @@ -// Automatically generated by xdrgen -// DO NOT EDIT or your changes may be overwritten - -package MyXDR; - -import java.io.IOException; - -import org.stellar.sdk.Base64Factory; -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; -import lombok.Data; -import lombok.NoArgsConstructor; -import lombok.AllArgsConstructor; - -/** - * Int4's original definition in the XDR file is: - *
- * typedef unsigned hyper int4; - *- */ -@Data -@NoArgsConstructor -@AllArgsConstructor -public class Int4 implements XdrElement { - private XdrUnsignedHyperInteger int4; - public void encode(XdrDataOutputStream stream) throws IOException { - int4.encode(stream); - } - - public static Int4 decode(XdrDataInputStream stream) throws IOException { - Int4 decodedInt4 = new Int4(); - decodedInt4.int4 = XdrUnsignedHyperInteger.decode(stream); - return decodedInt4; - } - - public static Int4 fromXdrBase64(String xdr) throws IOException { - byte[] bytes = Base64Factory.getInstance().decode(xdr); - return fromXdrByteArray(bytes); - } - - public static Int4 fromXdrByteArray(byte[] xdr) throws IOException { - ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); - XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); - return decode(xdrDataInputStream); - } -} diff --git a/spec/output/generator_spec_java/test.x/LotsOfMyStructs.java b/spec/output/generator_spec_java/test.x/LotsOfMyStructs.java deleted file mode 100644 index eaa3fb0c1..000000000 --- a/spec/output/generator_spec_java/test.x/LotsOfMyStructs.java +++ /dev/null @@ -1,57 +0,0 @@ -// Automatically generated by xdrgen -// DO NOT EDIT or your changes may be overwritten - -package MyXDR; - -import java.io.IOException; - -import org.stellar.sdk.Base64Factory; -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; -import lombok.Data; -import lombok.NoArgsConstructor; -import lombok.AllArgsConstructor; -import lombok.Builder; - -/** - * LotsOfMyStructs's original definition in the XDR file is: - *
- * struct LotsOfMyStructs
- * {
- * MyStruct members<>;
- * };
- *
- */
-@Data
-@NoArgsConstructor
-@AllArgsConstructor
-@Builder(toBuilder = true)
-public class LotsOfMyStructs implements XdrElement {
- private MyStruct[] members;
- public void encode(XdrDataOutputStream stream) throws IOException{
- int membersSize = getMembers().length;
- stream.writeInt(membersSize);
- for (int i = 0; i < membersSize; i++) {
- members[i].encode(stream);
- }
- }
- public static LotsOfMyStructs decode(XdrDataInputStream stream) throws IOException {
- LotsOfMyStructs decodedLotsOfMyStructs = new LotsOfMyStructs();
- int membersSize = stream.readInt();
- decodedLotsOfMyStructs.members = new MyStruct[membersSize];
- for (int i = 0; i < membersSize; i++) {
- decodedLotsOfMyStructs.members[i] = MyStruct.decode(stream);
- }
- return decodedLotsOfMyStructs;
- }
- public static LotsOfMyStructs fromXdrBase64(String xdr) throws IOException {
- byte[] bytes = Base64Factory.getInstance().decode(xdr);
- return fromXdrByteArray(bytes);
- }
-
- public static LotsOfMyStructs fromXdrByteArray(byte[] xdr) throws IOException {
- ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr);
- XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream);
- return decode(xdrDataInputStream);
- }
-}
diff --git a/spec/output/generator_spec_java/test.x/MyStruct.java b/spec/output/generator_spec_java/test.x/MyStruct.java
deleted file mode 100644
index 44f18615c..000000000
--- a/spec/output/generator_spec_java/test.x/MyStruct.java
+++ /dev/null
@@ -1,73 +0,0 @@
-// Automatically generated by xdrgen
-// DO NOT EDIT or your changes may be overwritten
-
-package MyXDR;
-
-import java.io.IOException;
-
-import org.stellar.sdk.Base64Factory;
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import lombok.Data;
-import lombok.NoArgsConstructor;
-import lombok.AllArgsConstructor;
-import lombok.Builder;
-
-/**
- * MyStruct's original definition in the XDR file is:
- *
- * struct MyStruct
- * {
- * uint512 field1;
- * optHash1 field2;
- * int1 field3;
- * unsigned int field4;
- * float field5;
- * double field6;
- * bool field7;
- * };
- *
- */
-@Data
-@NoArgsConstructor
-@AllArgsConstructor
-@Builder(toBuilder = true)
-public class MyStruct implements XdrElement {
- private Uint512 field1;
- private OptHash1 field2;
- private Int1 field3;
- private XdrUnsignedInteger field4;
- private Float field5;
- private Double field6;
- private Boolean field7;
- public void encode(XdrDataOutputStream stream) throws IOException{
- field1.encode(stream);
- field2.encode(stream);
- field3.encode(stream);
- field4.encode(stream);
- stream.writeFloat(field5);
- stream.writeDouble(field6);
- stream.writeInt(field7 ? 1 : 0);
- }
- public static MyStruct decode(XdrDataInputStream stream) throws IOException {
- MyStruct decodedMyStruct = new MyStruct();
- decodedMyStruct.field1 = Uint512.decode(stream);
- decodedMyStruct.field2 = OptHash1.decode(stream);
- decodedMyStruct.field3 = Int1.decode(stream);
- decodedMyStruct.field4 = XdrUnsignedInteger.decode(stream);
- decodedMyStruct.field5 = stream.readFloat();
- decodedMyStruct.field6 = stream.readDouble();
- decodedMyStruct.field7 = stream.readInt() == 1 ? true : false;
- return decodedMyStruct;
- }
- public static MyStruct fromXdrBase64(String xdr) throws IOException {
- byte[] bytes = Base64Factory.getInstance().decode(xdr);
- return fromXdrByteArray(bytes);
- }
-
- public static MyStruct fromXdrByteArray(byte[] xdr) throws IOException {
- ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr);
- XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream);
- return decode(xdrDataInputStream);
- }
-}
diff --git a/spec/output/generator_spec_java/test.x/Nester.java b/spec/output/generator_spec_java/test.x/Nester.java
deleted file mode 100644
index bc8bcce59..000000000
--- a/spec/output/generator_spec_java/test.x/Nester.java
+++ /dev/null
@@ -1,208 +0,0 @@
-// Automatically generated by xdrgen
-// DO NOT EDIT or your changes may be overwritten
-
-package MyXDR;
-
-import java.io.IOException;
-
-import org.stellar.sdk.Base64Factory;
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import lombok.Data;
-import lombok.NoArgsConstructor;
-import lombok.AllArgsConstructor;
-import lombok.Builder;
-
-/**
- * Nester's original definition in the XDR file is:
- *
- * struct Nester
- * {
- * enum {
- * BLAH_1,
- * BLAH_2
- * } nestedEnum;
- *
- * struct {
- * int blah;
- * } nestedStruct;
- *
- * union switch (Color color) {
- * case RED:
- * void;
- * default:
- * int blah2;
- * } nestedUnion;
- *
- *
- * };
- *
- */
-@Data
-@NoArgsConstructor
-@AllArgsConstructor
-@Builder(toBuilder = true)
-public class Nester implements XdrElement {
- private NesterNestedEnum nestedEnum;
- private NesterNestedStruct nestedStruct;
- private NesterNestedUnion nestedUnion;
- public void encode(XdrDataOutputStream stream) throws IOException{
- nestedEnum.encode(stream);
- nestedStruct.encode(stream);
- nestedUnion.encode(stream);
- }
- public static Nester decode(XdrDataInputStream stream) throws IOException {
- Nester decodedNester = new Nester();
- decodedNester.nestedEnum = NesterNestedEnum.decode(stream);
- decodedNester.nestedStruct = NesterNestedStruct.decode(stream);
- decodedNester.nestedUnion = NesterNestedUnion.decode(stream);
- return decodedNester;
- }
- public static Nester fromXdrBase64(String xdr) throws IOException {
- byte[] bytes = Base64Factory.getInstance().decode(xdr);
- return fromXdrByteArray(bytes);
- }
-
- public static Nester fromXdrByteArray(byte[] xdr) throws IOException {
- ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr);
- XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream);
- return decode(xdrDataInputStream);
- }
-
- /**
- * NesterNestedEnum's original definition in the XDR file is:
- *
- * enum {
- * BLAH_1,
- * BLAH_2
- * }
- *
- */
- public static enum NesterNestedEnum implements XdrElement {
- BLAH_1(0),
- BLAH_2(1);
-
- private final int value;
-
- NestedEnum(int value) {
- this.value = value;
- }
-
- public int getValue() {
- return value;
- }
-
- public static NestedEnum decode(XdrDataInputStream stream) throws IOException {
- int value = stream.readInt();
- switch (value) {
- case 0: return BLAH_1;
- case 1: return BLAH_2;
- default:
- throw new IllegalArgumentException("Unknown enum value: " + value);
- }
- }
-
- public void encode(XdrDataOutputStream stream) throws IOException {
- stream.writeInt(value);
- }
- public static NestedEnum fromXdrBase64(String xdr) throws IOException {
- byte[] bytes = Base64Factory.getInstance().decode(xdr);
- return fromXdrByteArray(bytes);
- }
-
- public static NestedEnum fromXdrByteArray(byte[] xdr) throws IOException {
- ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr);
- XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream);
- return decode(xdrDataInputStream);
- }
-
- }
- /**
- * NesterNestedStruct's original definition in the XDR file is:
- *
- * struct {
- * int blah;
- * }
- *
- */
- @Data
- @NoArgsConstructor
- @AllArgsConstructor
- @Builder(toBuilder = true)
- public static class NesterNestedStruct implements XdrElement {
- private Integer blah;
- public void encode(XdrDataOutputStream stream) throws IOException{
- stream.writeInt(blah);
- }
- public static NesterNestedStruct decode(XdrDataInputStream stream) throws IOException {
- NesterNestedStruct decodedNesterNestedStruct = new NesterNestedStruct();
- decodedNesterNestedStruct.blah = stream.readInt();
- return decodedNesterNestedStruct;
- }
- public static NesterNestedStruct fromXdrBase64(String xdr) throws IOException {
- byte[] bytes = Base64Factory.getInstance().decode(xdr);
- return fromXdrByteArray(bytes);
- }
-
- public static NesterNestedStruct fromXdrByteArray(byte[] xdr) throws IOException {
- ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr);
- XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream);
- return decode(xdrDataInputStream);
- }
-
- }
- /**
- * NesterNestedUnion's original definition in the XDR file is:
- *
- * union switch (Color color) {
- * case RED:
- * void;
- * default:
- * int blah2;
- * }
- *
- */
- @Data
- @NoArgsConstructor
- @AllArgsConstructor
- @Builder(toBuilder = true)
- public static class NesterNestedUnion implements XdrElement {
- private Color discriminant;
- private Integer blah2;
-
- public void encode(XdrDataOutputStream stream) throws IOException {
- stream.writeInt(discriminant.getValue());
- switch (discriminant) {
- case RED:
- break;
- default:
- stream.writeInt(blah2);
- break;
- }
- }
- public static NesterNestedUnion decode(XdrDataInputStream stream) throws IOException {
- NesterNestedUnion decodedNesterNestedUnion = new NesterNestedUnion();
- Color discriminant = Color.decode(stream);
- decodedNesterNestedUnion.setDiscriminant(discriminant);
- switch (decodedNesterNestedUnion.getDiscriminant()) {
- case RED:
- break;
- default:
- decodedNesterNestedUnion.blah2 = stream.readInt();
- break;
- }
- return decodedNesterNestedUnion;
- }
- public static NesterNestedUnion fromXdrBase64(String xdr) throws IOException {
- byte[] bytes = Base64Factory.getInstance().decode(xdr);
- return fromXdrByteArray(bytes);
- }
-
- public static NesterNestedUnion fromXdrByteArray(byte[] xdr) throws IOException {
- ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr);
- XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream);
- return decode(xdrDataInputStream);
- }
-
- }
-}
diff --git a/spec/output/generator_spec_java/test.x/OptHash1.java b/spec/output/generator_spec_java/test.x/OptHash1.java
deleted file mode 100644
index 7d3f328b0..000000000
--- a/spec/output/generator_spec_java/test.x/OptHash1.java
+++ /dev/null
@@ -1,54 +0,0 @@
-// Automatically generated by xdrgen
-// DO NOT EDIT or your changes may be overwritten
-
-package MyXDR;
-
-import java.io.IOException;
-
-import org.stellar.sdk.Base64Factory;
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import lombok.Data;
-import lombok.NoArgsConstructor;
-import lombok.AllArgsConstructor;
-
-/**
- * OptHash1's original definition in the XDR file is:
- * - * typedef Hash *optHash1; - *- */ -@Data -@NoArgsConstructor -@AllArgsConstructor -public class OptHash1 implements XdrElement { - private Hash optHash1; - public void encode(XdrDataOutputStream stream) throws IOException { - if (optHash1 != null) { - stream.writeInt(1); - optHash1.encode(stream); - } else { - stream.writeInt(0); - } - } - - public static OptHash1 decode(XdrDataInputStream stream) throws IOException { - OptHash1 decodedOptHash1 = new OptHash1(); - int optHash1Present = stream.readInt(); - if (optHash1Present != 0) { - decodedOptHash1.optHash1 = Hash.decode(stream); - } - return decodedOptHash1; - } - - public static OptHash1 fromXdrBase64(String xdr) throws IOException { - byte[] bytes = Base64Factory.getInstance().decode(xdr); - return fromXdrByteArray(bytes); - } - - public static OptHash1 fromXdrByteArray(byte[] xdr) throws IOException { - ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); - XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); - return decode(xdrDataInputStream); - } -} diff --git a/spec/output/generator_spec_java/test.x/OptHash2.java b/spec/output/generator_spec_java/test.x/OptHash2.java deleted file mode 100644 index 65817c9a7..000000000 --- a/spec/output/generator_spec_java/test.x/OptHash2.java +++ /dev/null @@ -1,54 +0,0 @@ -// Automatically generated by xdrgen -// DO NOT EDIT or your changes may be overwritten - -package MyXDR; - -import java.io.IOException; - -import org.stellar.sdk.Base64Factory; -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; -import lombok.Data; -import lombok.NoArgsConstructor; -import lombok.AllArgsConstructor; - -/** - * OptHash2's original definition in the XDR file is: - *
- * typedef Hash* optHash2; - *- */ -@Data -@NoArgsConstructor -@AllArgsConstructor -public class OptHash2 implements XdrElement { - private Hash optHash2; - public void encode(XdrDataOutputStream stream) throws IOException { - if (optHash2 != null) { - stream.writeInt(1); - optHash2.encode(stream); - } else { - stream.writeInt(0); - } - } - - public static OptHash2 decode(XdrDataInputStream stream) throws IOException { - OptHash2 decodedOptHash2 = new OptHash2(); - int optHash2Present = stream.readInt(); - if (optHash2Present != 0) { - decodedOptHash2.optHash2 = Hash.decode(stream); - } - return decodedOptHash2; - } - - public static OptHash2 fromXdrBase64(String xdr) throws IOException { - byte[] bytes = Base64Factory.getInstance().decode(xdr); - return fromXdrByteArray(bytes); - } - - public static OptHash2 fromXdrByteArray(byte[] xdr) throws IOException { - ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); - XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); - return decode(xdrDataInputStream); - } -} diff --git a/spec/output/generator_spec_java/test.x/Str.java b/spec/output/generator_spec_java/test.x/Str.java deleted file mode 100644 index 9d79f0dbb..000000000 --- a/spec/output/generator_spec_java/test.x/Str.java +++ /dev/null @@ -1,46 +0,0 @@ -// Automatically generated by xdrgen -// DO NOT EDIT or your changes may be overwritten - -package MyXDR; - -import java.io.IOException; - -import org.stellar.sdk.Base64Factory; -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; -import lombok.Data; -import lombok.NoArgsConstructor; -import lombok.AllArgsConstructor; - -/** - * Str's original definition in the XDR file is: - *
- * typedef string str<64>; - *- */ -@Data -@NoArgsConstructor -@AllArgsConstructor -public class Str implements XdrElement { - private XdrString str; - public void encode(XdrDataOutputStream stream) throws IOException { - str.encode(stream); - } - - public static Str decode(XdrDataInputStream stream) throws IOException { - Str decodedStr = new Str(); - decodedStr.str = XdrString.decode(stream, 64); - return decodedStr; - } - - public static Str fromXdrBase64(String xdr) throws IOException { - byte[] bytes = Base64Factory.getInstance().decode(xdr); - return fromXdrByteArray(bytes); - } - - public static Str fromXdrByteArray(byte[] xdr) throws IOException { - ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); - XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); - return decode(xdrDataInputStream); - } -} diff --git a/spec/output/generator_spec_java/test.x/Str2.java b/spec/output/generator_spec_java/test.x/Str2.java deleted file mode 100644 index 28dc3a00f..000000000 --- a/spec/output/generator_spec_java/test.x/Str2.java +++ /dev/null @@ -1,46 +0,0 @@ -// Automatically generated by xdrgen -// DO NOT EDIT or your changes may be overwritten - -package MyXDR; - -import java.io.IOException; - -import org.stellar.sdk.Base64Factory; -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; -import lombok.Data; -import lombok.NoArgsConstructor; -import lombok.AllArgsConstructor; - -/** - * Str2's original definition in the XDR file is: - *
- * typedef string str2<>; - *- */ -@Data -@NoArgsConstructor -@AllArgsConstructor -public class Str2 implements XdrElement { - private XdrString str2; - public void encode(XdrDataOutputStream stream) throws IOException { - str2.encode(stream); - } - - public static Str2 decode(XdrDataInputStream stream) throws IOException { - Str2 decodedStr2 = new Str2(); - decodedStr2.str2 = XdrString.decode(stream, Integer.MAX_VALUE); - return decodedStr2; - } - - public static Str2 fromXdrBase64(String xdr) throws IOException { - byte[] bytes = Base64Factory.getInstance().decode(xdr); - return fromXdrByteArray(bytes); - } - - public static Str2 fromXdrByteArray(byte[] xdr) throws IOException { - ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); - XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); - return decode(xdrDataInputStream); - } -} diff --git a/spec/output/generator_spec_java/test.x/Uint512.java b/spec/output/generator_spec_java/test.x/Uint512.java deleted file mode 100644 index 1eaa83cf1..000000000 --- a/spec/output/generator_spec_java/test.x/Uint512.java +++ /dev/null @@ -1,49 +0,0 @@ -// Automatically generated by xdrgen -// DO NOT EDIT or your changes may be overwritten - -package MyXDR; - -import java.io.IOException; - -import org.stellar.sdk.Base64Factory; -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; -import lombok.Data; -import lombok.NoArgsConstructor; -import lombok.AllArgsConstructor; - -/** - * Uint512's original definition in the XDR file is: - *
- * typedef opaque uint512[64]; - *- */ -@Data -@NoArgsConstructor -@AllArgsConstructor -public class Uint512 implements XdrElement { - private byte[] uint512; - public void encode(XdrDataOutputStream stream) throws IOException { - int uint512Size = uint512.length; - stream.write(getUint512(), 0, uint512Size); - } - - public static Uint512 decode(XdrDataInputStream stream) throws IOException { - Uint512 decodedUint512 = new Uint512(); - int uint512Size = 64; - decodedUint512.uint512 = new byte[uint512Size]; - stream.read(decodedUint512.uint512, 0, uint512Size); - return decodedUint512; - } - - public static Uint512 fromXdrBase64(String xdr) throws IOException { - byte[] bytes = Base64Factory.getInstance().decode(xdr); - return fromXdrByteArray(bytes); - } - - public static Uint512 fromXdrByteArray(byte[] xdr) throws IOException { - ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); - XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); - return decode(xdrDataInputStream); - } -} diff --git a/spec/output/generator_spec_java/test.x/Uint513.java b/spec/output/generator_spec_java/test.x/Uint513.java deleted file mode 100644 index 3bc636f5f..000000000 --- a/spec/output/generator_spec_java/test.x/Uint513.java +++ /dev/null @@ -1,50 +0,0 @@ -// Automatically generated by xdrgen -// DO NOT EDIT or your changes may be overwritten - -package MyXDR; - -import java.io.IOException; - -import org.stellar.sdk.Base64Factory; -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; -import lombok.Data; -import lombok.NoArgsConstructor; -import lombok.AllArgsConstructor; - -/** - * Uint513's original definition in the XDR file is: - *
- * typedef opaque uint513<64>; - *- */ -@Data -@NoArgsConstructor -@AllArgsConstructor -public class Uint513 implements XdrElement { - private byte[] uint513; - public void encode(XdrDataOutputStream stream) throws IOException { - int uint513Size = uint513.length; - stream.writeInt(uint513Size); - stream.write(getUint513(), 0, uint513Size); - } - - public static Uint513 decode(XdrDataInputStream stream) throws IOException { - Uint513 decodedUint513 = new Uint513(); - int uint513Size = stream.readInt(); - decodedUint513.uint513 = new byte[uint513Size]; - stream.read(decodedUint513.uint513, 0, uint513Size); - return decodedUint513; - } - - public static Uint513 fromXdrBase64(String xdr) throws IOException { - byte[] bytes = Base64Factory.getInstance().decode(xdr); - return fromXdrByteArray(bytes); - } - - public static Uint513 fromXdrByteArray(byte[] xdr) throws IOException { - ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); - XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); - return decode(xdrDataInputStream); - } -} diff --git a/spec/output/generator_spec_java/test.x/Uint514.java b/spec/output/generator_spec_java/test.x/Uint514.java deleted file mode 100644 index a8b500329..000000000 --- a/spec/output/generator_spec_java/test.x/Uint514.java +++ /dev/null @@ -1,50 +0,0 @@ -// Automatically generated by xdrgen -// DO NOT EDIT or your changes may be overwritten - -package MyXDR; - -import java.io.IOException; - -import org.stellar.sdk.Base64Factory; -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; -import lombok.Data; -import lombok.NoArgsConstructor; -import lombok.AllArgsConstructor; - -/** - * Uint514's original definition in the XDR file is: - *
- * typedef opaque uint514<>; - *- */ -@Data -@NoArgsConstructor -@AllArgsConstructor -public class Uint514 implements XdrElement { - private byte[] uint514; - public void encode(XdrDataOutputStream stream) throws IOException { - int uint514Size = uint514.length; - stream.writeInt(uint514Size); - stream.write(getUint514(), 0, uint514Size); - } - - public static Uint514 decode(XdrDataInputStream stream) throws IOException { - Uint514 decodedUint514 = new Uint514(); - int uint514Size = stream.readInt(); - decodedUint514.uint514 = new byte[uint514Size]; - stream.read(decodedUint514.uint514, 0, uint514Size); - return decodedUint514; - } - - public static Uint514 fromXdrBase64(String xdr) throws IOException { - byte[] bytes = Base64Factory.getInstance().decode(xdr); - return fromXdrByteArray(bytes); - } - - public static Uint514 fromXdrByteArray(byte[] xdr) throws IOException { - ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); - XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); - return decode(xdrDataInputStream); - } -} diff --git a/spec/output/generator_spec_java/test.x/XdrDataInputStream.java b/spec/output/generator_spec_java/test.x/XdrDataInputStream.java deleted file mode 100644 index 6d6592026..000000000 --- a/spec/output/generator_spec_java/test.x/XdrDataInputStream.java +++ /dev/null @@ -1,122 +0,0 @@ -package MyXDR; - -import java.io.DataInputStream; -import java.io.IOException; -import java.io.InputStream; -import java.nio.charset.Charset; - -public class XdrDataInputStream extends DataInputStream { - - // The underlying input stream - private final XdrInputStream mIn; - - /** - * Creates a XdrDataInputStream that uses the specified - * underlying InputStream. - * - * @param in the specified input stream - */ - public XdrDataInputStream(InputStream in) { - super(new XdrInputStream(in)); - mIn = (XdrInputStream) super.in; - } - - public int[] readIntArray() throws IOException { - int l = readInt(); - return readIntArray(l); - } - - private int[] readIntArray(int l) throws IOException { - int[] arr = new int[l]; - for (int i = 0; i < l; i++) { - arr[i] = readInt(); - } - return arr; - } - - public float[] readFloatArray() throws IOException { - int l = readInt(); - return readFloatArray(l); - } - - private float[] readFloatArray(int l) throws IOException { - float[] arr = new float[l]; - for (int i = 0; i < l; i++) { - arr[i] = readFloat(); - } - return arr; - } - - public double[] readDoubleArray() throws IOException { - int l = readInt(); - return readDoubleArray(l); - } - - private double[] readDoubleArray(int l) throws IOException { - double[] arr = new double[l]; - for (int i = 0; i < l; i++) { - arr[i] = readDouble(); - } - return arr; - } - - @Override - public int read() throws IOException { - return super.read(); - } - - /** - * Need to provide a custom impl of InputStream as DataInputStream's read methods - * are final and we need to keep track of the count for padding purposes. - */ - private static final class XdrInputStream extends InputStream { - - // The underlying input stream - private final InputStream mIn; - - // The amount of bytes read so far. - private int mCount; - - public XdrInputStream(InputStream in) { - mIn = in; - mCount = 0; - } - - @Override - public int read() throws IOException { - int read = mIn.read(); - if (read >= 0) { - mCount++; - } - return read; - } - - @Override - public int read(byte[] b) throws IOException { - return read(b, 0, b.length); - } - - @Override - public int read(byte[] b, int off, int len) throws IOException { - int read = mIn.read(b, off, len); - mCount += read; - pad(); - return read; - } - - public void pad() throws IOException { - int pad = 0; - int mod = mCount % 4; - if (mod > 0) { - pad = 4-mod; - } - - while (pad-- > 0) { - int b = read(); - if (b != 0) { - throw new IOException("non-zero padding"); - } - } - } - } -} diff --git a/spec/output/generator_spec_java/test.x/XdrDataOutputStream.java b/spec/output/generator_spec_java/test.x/XdrDataOutputStream.java deleted file mode 100644 index 729aec05b..000000000 --- a/spec/output/generator_spec_java/test.x/XdrDataOutputStream.java +++ /dev/null @@ -1,96 +0,0 @@ -package MyXDR; - -import java.io.DataOutputStream; -import java.io.IOException; -import java.io.OutputStream; -import java.nio.charset.Charset; - -public class XdrDataOutputStream extends DataOutputStream { - - private final XdrOutputStream mOut; - - public XdrDataOutputStream(OutputStream out) { - super(new XdrOutputStream(out)); - mOut = (XdrOutputStream) super.out; - } - - public void writeIntArray(int[] a) throws IOException { - writeInt(a.length); - writeIntArray(a, a.length); - } - - private void writeIntArray(int[] a, int l) throws IOException { - for (int i = 0; i < l; i++) { - writeInt(a[i]); - } - } - - public void writeFloatArray(float[] a) throws IOException { - writeInt(a.length); - writeFloatArray(a, a.length); - } - - private void writeFloatArray(float[] a, int l) throws IOException { - for (int i = 0; i < l; i++) { - writeFloat(a[i]); - } - } - - public void writeDoubleArray(double[] a) throws IOException { - writeInt(a.length); - writeDoubleArray(a, a.length); - } - - private void writeDoubleArray(double[] a, int l) throws IOException { - for (int i = 0; i < l; i++) { - writeDouble(a[i]); - } - } - - private static final class XdrOutputStream extends OutputStream { - - private final OutputStream mOut; - - // Number of bytes written - private int mCount; - - public XdrOutputStream(OutputStream out) { - mOut = out; - mCount = 0; - } - - @Override - public void write(int b) throws IOException { - mOut.write(b); - // https://docs.oracle.com/javase/7/docs/api/java/io/OutputStream.html#write(int): - // > The byte to be written is the eight low-order bits of the argument b. - // > The 24 high-order bits of b are ignored. - mCount++; - } - - @Override - public void write(byte[] b) throws IOException { - // https://docs.oracle.com/javase/7/docs/api/java/io/OutputStream.html#write(byte[]): - // > The general contract for write(b) is that it should have exactly the same effect - // > as the call write(b, 0, b.length). - write(b, 0, b.length); - } - - public void write(byte[] b, int offset, int length) throws IOException { - mOut.write(b, offset, length); - mCount += length; - pad(); - } - - public void pad() throws IOException { - int pad = 0; - int mod = mCount % 4; - if (mod > 0) { - pad = 4-mod; - } - while (pad-- > 0) { - write(0); - } - } - } -} diff --git a/spec/output/generator_spec_java/test.x/XdrElement.java b/spec/output/generator_spec_java/test.x/XdrElement.java deleted file mode 100644 index 453491ea2..000000000 --- a/spec/output/generator_spec_java/test.x/XdrElement.java +++ /dev/null @@ -1,21 +0,0 @@ -package MyXDR; - -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import org.stellar.sdk.Base64Factory; - -/** Common parent interface for all generated classes. */ -interface XdrElement { - void encode(XdrDataOutputStream stream) throws IOException; - - default String toXdrBase64() throws IOException { - return Base64Factory.getInstance().encodeToString(toXdrByteArray()); - } - - default byte[] toXdrByteArray() throws IOException { - ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); - XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); - encode(xdrDataOutputStream); - return byteArrayOutputStream.toByteArray(); - } -} diff --git a/spec/output/generator_spec_java/test.x/XdrString.java b/spec/output/generator_spec_java/test.x/XdrString.java deleted file mode 100644 index a51eead77..000000000 --- a/spec/output/generator_spec_java/test.x/XdrString.java +++ /dev/null @@ -1,62 +0,0 @@ -package MyXDR; - -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.io.InvalidClassException; -import java.nio.charset.StandardCharsets; -import lombok.Value; -import org.stellar.sdk.Base64Factory; - -@Value -public class XdrString implements XdrElement { - byte[] bytes; - - public XdrString(byte[] bytes) { - this.bytes = bytes; - } - - public XdrString(String text) { - this.bytes = text.getBytes(StandardCharsets.UTF_8); - } - - @Override - public void encode(XdrDataOutputStream stream) throws IOException { - stream.writeInt(this.bytes.length); - stream.write(this.bytes, 0, this.bytes.length); - } - - public static XdrString decode(XdrDataInputStream stream, int maxSize) throws IOException { - int size = stream.readInt(); - if (size > maxSize) { - throw new IllegalArgumentException("String length " + size + " exceeds max size " + maxSize); - } - byte[] bytes = new byte[size]; - stream.read(bytes); - return new XdrString(bytes); - } - - public static XdrString fromXdrBase64(String xdr, int maxSize) throws IOException { - byte[] bytes = Base64Factory.getInstance().decode(xdr); - return fromXdrByteArray(bytes, maxSize); - } - - public static XdrString fromXdrBase64(String xdr) throws IOException { - return fromXdrBase64(xdr, Integer.MAX_VALUE); - } - - public static XdrString fromXdrByteArray(byte[] xdr, int maxSize) throws IOException { - ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); - XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); - return decode(xdrDataInputStream, maxSize); - } - - public static XdrString fromXdrByteArray(byte[] xdr) throws IOException { - return fromXdrByteArray(xdr, Integer.MAX_VALUE); - } - - @Override - public String toString() { - return new String(bytes, StandardCharsets.UTF_8); - } -} diff --git a/spec/output/generator_spec_java/test.x/XdrUnsignedHyperInteger.java b/spec/output/generator_spec_java/test.x/XdrUnsignedHyperInteger.java deleted file mode 100644 index 5d798cded..000000000 --- a/spec/output/generator_spec_java/test.x/XdrUnsignedHyperInteger.java +++ /dev/null @@ -1,69 +0,0 @@ -package MyXDR; - -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.math.BigInteger; -import lombok.Value; -import org.stellar.sdk.Base64Factory; - -/** - * Represents XDR Unsigned Hyper Integer. - * - * @see XDR: External Data - * Representation Standard - */ -@Value -public class XdrUnsignedHyperInteger implements XdrElement { - public static final BigInteger MAX_VALUE = new BigInteger("18446744073709551615"); - public static final BigInteger MIN_VALUE = BigInteger.ZERO; - BigInteger number; - - public XdrUnsignedHyperInteger(BigInteger number) { - if (number.compareTo(MIN_VALUE) < 0 || number.compareTo(MAX_VALUE) > 0) { - throw new IllegalArgumentException("number must be between 0 and 2^64 - 1 inclusive"); - } - this.number = number; - } - - public XdrUnsignedHyperInteger(Long number) { - if (number < 0) { - throw new IllegalArgumentException( - "number must be greater than or equal to 0 if you want to construct it from Long"); - } - this.number = BigInteger.valueOf(number); - } - - @Override - public void encode(XdrDataOutputStream stream) throws IOException { - stream.write(getBytes()); - } - - public static XdrUnsignedHyperInteger decode(XdrDataInputStream stream) throws IOException { - byte[] bytes = new byte[8]; - stream.readFully(bytes); - BigInteger uint64 = new BigInteger(1, bytes); - return new XdrUnsignedHyperInteger(uint64); - } - - private byte[] getBytes() { - byte[] bytes = number.toByteArray(); - byte[] paddedBytes = new byte[8]; - - int numBytesToCopy = Math.min(bytes.length, 8); - int copyStartIndex = bytes.length - numBytesToCopy; - System.arraycopy(bytes, copyStartIndex, paddedBytes, 8 - numBytesToCopy, numBytesToCopy); - return paddedBytes; - } - - public static XdrUnsignedHyperInteger fromXdrBase64(String xdr) throws IOException { - byte[] bytes = Base64Factory.getInstance().decode(xdr); - return fromXdrByteArray(bytes); - } - - public static XdrUnsignedHyperInteger fromXdrByteArray(byte[] xdr) throws IOException { - ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); - XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); - return decode(xdrDataInputStream); - } -} diff --git a/spec/output/generator_spec_java/test.x/XdrUnsignedInteger.java b/spec/output/generator_spec_java/test.x/XdrUnsignedInteger.java deleted file mode 100644 index bea880aee..000000000 --- a/spec/output/generator_spec_java/test.x/XdrUnsignedInteger.java +++ /dev/null @@ -1,57 +0,0 @@ -package MyXDR; - -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import lombok.Value; -import org.stellar.sdk.Base64Factory; - -/** - * Represents XDR Unsigned Integer. - * - * @see XDR: External Data - * Representation Standard - */ -@Value -public class XdrUnsignedInteger implements XdrElement { - public static final long MAX_VALUE = (1L << 32) - 1; - public static final long MIN_VALUE = 0; - Long number; - - public XdrUnsignedInteger(Long number) { - if (number < MIN_VALUE || number > MAX_VALUE) { - throw new IllegalArgumentException("number must be between 0 and 2^32 - 1 inclusive"); - } - this.number = number; - } - - public XdrUnsignedInteger(Integer number) { - if (number < 0) { - throw new IllegalArgumentException( - "number must be greater than or equal to 0 if you want to construct it from Integer"); - } - this.number = number.longValue(); - } - - public static XdrUnsignedInteger decode(XdrDataInputStream stream) throws IOException { - int intValue = stream.readInt(); - long uint32Value = Integer.toUnsignedLong(intValue); - return new XdrUnsignedInteger(uint32Value); - } - - @Override - public void encode(XdrDataOutputStream stream) throws IOException { - stream.writeInt(number.intValue()); - } - - public static XdrUnsignedInteger fromXdrBase64(String xdr) throws IOException { - byte[] bytes = Base64Factory.getInstance().decode(xdr); - return fromXdrByteArray(bytes); - } - - public static XdrUnsignedInteger fromXdrByteArray(byte[] xdr) throws IOException { - ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); - XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); - return decode(xdrDataInputStream); - } -} diff --git a/spec/output/generator_spec_java/union.x/Constants.java b/spec/output/generator_spec_java/union.x/Constants.java deleted file mode 100644 index d7d9f4cfc..000000000 --- a/spec/output/generator_spec_java/union.x/Constants.java +++ /dev/null @@ -1,10 +0,0 @@ -// Automatically generated by xdrgen -// DO NOT EDIT or your changes may be overwritten - -package MyXDR; - -import java.io.IOException; - -public final class Constants { - private Constants() {} -} diff --git a/spec/output/generator_spec_java/union.x/Error.java b/spec/output/generator_spec_java/union.x/Error.java deleted file mode 100644 index 197d97721..000000000 --- a/spec/output/generator_spec_java/union.x/Error.java +++ /dev/null @@ -1,46 +0,0 @@ -// Automatically generated by xdrgen -// DO NOT EDIT or your changes may be overwritten - -package MyXDR; - -import java.io.IOException; - -import org.stellar.sdk.Base64Factory; -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; -import lombok.Data; -import lombok.NoArgsConstructor; -import lombok.AllArgsConstructor; - -/** - * Error's original definition in the XDR file is: - *
- * typedef int Error; - *- */ -@Data -@NoArgsConstructor -@AllArgsConstructor -public class Error implements XdrElement { - private Integer Error; - public void encode(XdrDataOutputStream stream) throws IOException { - stream.writeInt(Error); - } - - public static Error decode(XdrDataInputStream stream) throws IOException { - Error decodedError = new Error(); - decodedError.Error = stream.readInt(); - return decodedError; - } - - public static Error fromXdrBase64(String xdr) throws IOException { - byte[] bytes = Base64Factory.getInstance().decode(xdr); - return fromXdrByteArray(bytes); - } - - public static Error fromXdrByteArray(byte[] xdr) throws IOException { - ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); - XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); - return decode(xdrDataInputStream); - } -} diff --git a/spec/output/generator_spec_java/union.x/IntUnion.java b/spec/output/generator_spec_java/union.x/IntUnion.java deleted file mode 100644 index f08e1a7e5..000000000 --- a/spec/output/generator_spec_java/union.x/IntUnion.java +++ /dev/null @@ -1,81 +0,0 @@ -// Automatically generated by xdrgen -// DO NOT EDIT or your changes may be overwritten - -package MyXDR; - -import java.io.IOException; - -import org.stellar.sdk.Base64Factory; -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; -import lombok.Data; -import lombok.NoArgsConstructor; -import lombok.AllArgsConstructor; -import lombok.Builder; - -/** - * IntUnion's original definition in the XDR file is: - *
- * union IntUnion switch (int type)
- * {
- * case 0:
- * Error error;
- * case 1:
- * Multi things<>;
- *
- * };
- *
- */
-@Data
-@NoArgsConstructor
-@AllArgsConstructor
-@Builder(toBuilder = true)
-public class IntUnion implements XdrElement {
- private Integer discriminant;
- private Error error;
- private Multi[] things;
-
- public void encode(XdrDataOutputStream stream) throws IOException {
- stream.writeInt(discriminant);
- switch (discriminant) {
- case 0:
- error.encode(stream);
- break;
- case 1:
- int thingsSize = getThings().length;
- stream.writeInt(thingsSize);
- for (int i = 0; i < thingsSize; i++) {
- things[i].encode(stream);
- }
- break;
- }
- }
- public static IntUnion decode(XdrDataInputStream stream) throws IOException {
- IntUnion decodedIntUnion = new IntUnion();
- Integer discriminant = stream.readInt();
- decodedIntUnion.setDiscriminant(discriminant);
- switch (decodedIntUnion.getDiscriminant()) {
- case 0:
- decodedIntUnion.error = Error.decode(stream);
- break;
- case 1:
- int thingsSize = stream.readInt();
- decodedIntUnion.things = new Multi[thingsSize];
- for (int i = 0; i < thingsSize; i++) {
- decodedIntUnion.things[i] = Multi.decode(stream);
- }
- break;
- }
- return decodedIntUnion;
- }
- public static IntUnion fromXdrBase64(String xdr) throws IOException {
- byte[] bytes = Base64Factory.getInstance().decode(xdr);
- return fromXdrByteArray(bytes);
- }
-
- public static IntUnion fromXdrByteArray(byte[] xdr) throws IOException {
- ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr);
- XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream);
- return decode(xdrDataInputStream);
- }
-}
diff --git a/spec/output/generator_spec_java/union.x/IntUnion2.java b/spec/output/generator_spec_java/union.x/IntUnion2.java
deleted file mode 100644
index 71ad3f774..000000000
--- a/spec/output/generator_spec_java/union.x/IntUnion2.java
+++ /dev/null
@@ -1,46 +0,0 @@
-// Automatically generated by xdrgen
-// DO NOT EDIT or your changes may be overwritten
-
-package MyXDR;
-
-import java.io.IOException;
-
-import org.stellar.sdk.Base64Factory;
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import lombok.Data;
-import lombok.NoArgsConstructor;
-import lombok.AllArgsConstructor;
-
-/**
- * IntUnion2's original definition in the XDR file is:
- * - * typedef IntUnion IntUnion2; - *- */ -@Data -@NoArgsConstructor -@AllArgsConstructor -public class IntUnion2 implements XdrElement { - private IntUnion IntUnion2; - public void encode(XdrDataOutputStream stream) throws IOException { - IntUnion2.encode(stream); - } - - public static IntUnion2 decode(XdrDataInputStream stream) throws IOException { - IntUnion2 decodedIntUnion2 = new IntUnion2(); - decodedIntUnion2.IntUnion2 = IntUnion.decode(stream); - return decodedIntUnion2; - } - - public static IntUnion2 fromXdrBase64(String xdr) throws IOException { - byte[] bytes = Base64Factory.getInstance().decode(xdr); - return fromXdrByteArray(bytes); - } - - public static IntUnion2 fromXdrByteArray(byte[] xdr) throws IOException { - ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); - XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); - return decode(xdrDataInputStream); - } -} diff --git a/spec/output/generator_spec_java/union.x/Multi.java b/spec/output/generator_spec_java/union.x/Multi.java deleted file mode 100644 index 18ca8ece1..000000000 --- a/spec/output/generator_spec_java/union.x/Multi.java +++ /dev/null @@ -1,46 +0,0 @@ -// Automatically generated by xdrgen -// DO NOT EDIT or your changes may be overwritten - -package MyXDR; - -import java.io.IOException; - -import org.stellar.sdk.Base64Factory; -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; -import lombok.Data; -import lombok.NoArgsConstructor; -import lombok.AllArgsConstructor; - -/** - * Multi's original definition in the XDR file is: - *
- * typedef int Multi; - *- */ -@Data -@NoArgsConstructor -@AllArgsConstructor -public class Multi implements XdrElement { - private Integer Multi; - public void encode(XdrDataOutputStream stream) throws IOException { - stream.writeInt(Multi); - } - - public static Multi decode(XdrDataInputStream stream) throws IOException { - Multi decodedMulti = new Multi(); - decodedMulti.Multi = stream.readInt(); - return decodedMulti; - } - - public static Multi fromXdrBase64(String xdr) throws IOException { - byte[] bytes = Base64Factory.getInstance().decode(xdr); - return fromXdrByteArray(bytes); - } - - public static Multi fromXdrByteArray(byte[] xdr) throws IOException { - ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr); - XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream); - return decode(xdrDataInputStream); - } -} diff --git a/spec/output/generator_spec_java/union.x/MyUnion.java b/spec/output/generator_spec_java/union.x/MyUnion.java deleted file mode 100644 index fc125f853..000000000 --- a/spec/output/generator_spec_java/union.x/MyUnion.java +++ /dev/null @@ -1,82 +0,0 @@ -// Automatically generated by xdrgen -// DO NOT EDIT or your changes may be overwritten - -package MyXDR; - -import java.io.IOException; - -import org.stellar.sdk.Base64Factory; -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; -import lombok.Data; -import lombok.NoArgsConstructor; -import lombok.AllArgsConstructor; -import lombok.Builder; - -/** - * MyUnion's original definition in the XDR file is: - *
- * union MyUnion switch (UnionKey type)
- * {
- * case ERROR:
- * Error error;
- * case MULTI:
- * Multi things<>;
- *
- *
- * };
- *
- */
-@Data
-@NoArgsConstructor
-@AllArgsConstructor
-@Builder(toBuilder = true)
-public class MyUnion implements XdrElement {
- private UnionKey discriminant;
- private Error error;
- private Multi[] things;
-
- public void encode(XdrDataOutputStream stream) throws IOException {
- stream.writeInt(discriminant.getValue());
- switch (discriminant) {
- case ERROR:
- error.encode(stream);
- break;
- case MULTI:
- int thingsSize = getThings().length;
- stream.writeInt(thingsSize);
- for (int i = 0; i < thingsSize; i++) {
- things[i].encode(stream);
- }
- break;
- }
- }
- public static MyUnion decode(XdrDataInputStream stream) throws IOException {
- MyUnion decodedMyUnion = new MyUnion();
- UnionKey discriminant = UnionKey.decode(stream);
- decodedMyUnion.setDiscriminant(discriminant);
- switch (decodedMyUnion.getDiscriminant()) {
- case ERROR:
- decodedMyUnion.error = Error.decode(stream);
- break;
- case MULTI:
- int thingsSize = stream.readInt();
- decodedMyUnion.things = new Multi[thingsSize];
- for (int i = 0; i < thingsSize; i++) {
- decodedMyUnion.things[i] = Multi.decode(stream);
- }
- break;
- }
- return decodedMyUnion;
- }
- public static MyUnion fromXdrBase64(String xdr) throws IOException {
- byte[] bytes = Base64Factory.getInstance().decode(xdr);
- return fromXdrByteArray(bytes);
- }
-
- public static MyUnion fromXdrByteArray(byte[] xdr) throws IOException {
- ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr);
- XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream);
- return decode(xdrDataInputStream);
- }
-}
diff --git a/spec/output/generator_spec_java/union.x/UnionKey.java b/spec/output/generator_spec_java/union.x/UnionKey.java
deleted file mode 100644
index 504e811cc..000000000
--- a/spec/output/generator_spec_java/union.x/UnionKey.java
+++ /dev/null
@@ -1,58 +0,0 @@
-// Automatically generated by xdrgen
-// DO NOT EDIT or your changes may be overwritten
-
-package MyXDR;
-
-import java.io.IOException;
-
-import org.stellar.sdk.Base64Factory;
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-
-/**
- * UnionKey's original definition in the XDR file is:
- *
- * enum UnionKey {
- * ERROR,
- * MULTI
- * };
- *
- */
-public enum UnionKey implements XdrElement {
- ERROR(0),
- MULTI(1);
-
- private final int value;
-
- UnionKey(int value) {
- this.value = value;
- }
-
- public int getValue() {
- return value;
- }
-
- public static UnionKey decode(XdrDataInputStream stream) throws IOException {
- int value = stream.readInt();
- switch (value) {
- case 0: return ERROR;
- case 1: return MULTI;
- default:
- throw new IllegalArgumentException("Unknown enum value: " + value);
- }
- }
-
- public void encode(XdrDataOutputStream stream) throws IOException {
- stream.writeInt(value);
- }
- public static UnionKey fromXdrBase64(String xdr) throws IOException {
- byte[] bytes = Base64Factory.getInstance().decode(xdr);
- return fromXdrByteArray(bytes);
- }
-
- public static UnionKey fromXdrByteArray(byte[] xdr) throws IOException {
- ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr);
- XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream);
- return decode(xdrDataInputStream);
- }
-}
diff --git a/spec/output/generator_spec_java/union.x/XdrDataInputStream.java b/spec/output/generator_spec_java/union.x/XdrDataInputStream.java
deleted file mode 100644
index 6d6592026..000000000
--- a/spec/output/generator_spec_java/union.x/XdrDataInputStream.java
+++ /dev/null
@@ -1,122 +0,0 @@
-package MyXDR;
-
-import java.io.DataInputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.nio.charset.Charset;
-
-public class XdrDataInputStream extends DataInputStream {
-
- // The underlying input stream
- private final XdrInputStream mIn;
-
- /**
- * Creates a XdrDataInputStream that uses the specified
- * underlying InputStream.
- *
- * @param in the specified input stream
- */
- public XdrDataInputStream(InputStream in) {
- super(new XdrInputStream(in));
- mIn = (XdrInputStream) super.in;
- }
-
- public int[] readIntArray() throws IOException {
- int l = readInt();
- return readIntArray(l);
- }
-
- private int[] readIntArray(int l) throws IOException {
- int[] arr = new int[l];
- for (int i = 0; i < l; i++) {
- arr[i] = readInt();
- }
- return arr;
- }
-
- public float[] readFloatArray() throws IOException {
- int l = readInt();
- return readFloatArray(l);
- }
-
- private float[] readFloatArray(int l) throws IOException {
- float[] arr = new float[l];
- for (int i = 0; i < l; i++) {
- arr[i] = readFloat();
- }
- return arr;
- }
-
- public double[] readDoubleArray() throws IOException {
- int l = readInt();
- return readDoubleArray(l);
- }
-
- private double[] readDoubleArray(int l) throws IOException {
- double[] arr = new double[l];
- for (int i = 0; i < l; i++) {
- arr[i] = readDouble();
- }
- return arr;
- }
-
- @Override
- public int read() throws IOException {
- return super.read();
- }
-
- /**
- * Need to provide a custom impl of InputStream as DataInputStream's read methods
- * are final and we need to keep track of the count for padding purposes.
- */
- private static final class XdrInputStream extends InputStream {
-
- // The underlying input stream
- private final InputStream mIn;
-
- // The amount of bytes read so far.
- private int mCount;
-
- public XdrInputStream(InputStream in) {
- mIn = in;
- mCount = 0;
- }
-
- @Override
- public int read() throws IOException {
- int read = mIn.read();
- if (read >= 0) {
- mCount++;
- }
- return read;
- }
-
- @Override
- public int read(byte[] b) throws IOException {
- return read(b, 0, b.length);
- }
-
- @Override
- public int read(byte[] b, int off, int len) throws IOException {
- int read = mIn.read(b, off, len);
- mCount += read;
- pad();
- return read;
- }
-
- public void pad() throws IOException {
- int pad = 0;
- int mod = mCount % 4;
- if (mod > 0) {
- pad = 4-mod;
- }
-
- while (pad-- > 0) {
- int b = read();
- if (b != 0) {
- throw new IOException("non-zero padding");
- }
- }
- }
- }
-}
diff --git a/spec/output/generator_spec_java/union.x/XdrDataOutputStream.java b/spec/output/generator_spec_java/union.x/XdrDataOutputStream.java
deleted file mode 100644
index 729aec05b..000000000
--- a/spec/output/generator_spec_java/union.x/XdrDataOutputStream.java
+++ /dev/null
@@ -1,96 +0,0 @@
-package MyXDR;
-
-import java.io.DataOutputStream;
-import java.io.IOException;
-import java.io.OutputStream;
-import java.nio.charset.Charset;
-
-public class XdrDataOutputStream extends DataOutputStream {
-
- private final XdrOutputStream mOut;
-
- public XdrDataOutputStream(OutputStream out) {
- super(new XdrOutputStream(out));
- mOut = (XdrOutputStream) super.out;
- }
-
- public void writeIntArray(int[] a) throws IOException {
- writeInt(a.length);
- writeIntArray(a, a.length);
- }
-
- private void writeIntArray(int[] a, int l) throws IOException {
- for (int i = 0; i < l; i++) {
- writeInt(a[i]);
- }
- }
-
- public void writeFloatArray(float[] a) throws IOException {
- writeInt(a.length);
- writeFloatArray(a, a.length);
- }
-
- private void writeFloatArray(float[] a, int l) throws IOException {
- for (int i = 0; i < l; i++) {
- writeFloat(a[i]);
- }
- }
-
- public void writeDoubleArray(double[] a) throws IOException {
- writeInt(a.length);
- writeDoubleArray(a, a.length);
- }
-
- private void writeDoubleArray(double[] a, int l) throws IOException {
- for (int i = 0; i < l; i++) {
- writeDouble(a[i]);
- }
- }
-
- private static final class XdrOutputStream extends OutputStream {
-
- private final OutputStream mOut;
-
- // Number of bytes written
- private int mCount;
-
- public XdrOutputStream(OutputStream out) {
- mOut = out;
- mCount = 0;
- }
-
- @Override
- public void write(int b) throws IOException {
- mOut.write(b);
- // https://docs.oracle.com/javase/7/docs/api/java/io/OutputStream.html#write(int):
- // > The byte to be written is the eight low-order bits of the argument b.
- // > The 24 high-order bits of b are ignored.
- mCount++;
- }
-
- @Override
- public void write(byte[] b) throws IOException {
- // https://docs.oracle.com/javase/7/docs/api/java/io/OutputStream.html#write(byte[]):
- // > The general contract for write(b) is that it should have exactly the same effect
- // > as the call write(b, 0, b.length).
- write(b, 0, b.length);
- }
-
- public void write(byte[] b, int offset, int length) throws IOException {
- mOut.write(b, offset, length);
- mCount += length;
- pad();
- }
-
- public void pad() throws IOException {
- int pad = 0;
- int mod = mCount % 4;
- if (mod > 0) {
- pad = 4-mod;
- }
- while (pad-- > 0) {
- write(0);
- }
- }
- }
-}
diff --git a/spec/output/generator_spec_java/union.x/XdrElement.java b/spec/output/generator_spec_java/union.x/XdrElement.java
deleted file mode 100644
index 453491ea2..000000000
--- a/spec/output/generator_spec_java/union.x/XdrElement.java
+++ /dev/null
@@ -1,21 +0,0 @@
-package MyXDR;
-
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import org.stellar.sdk.Base64Factory;
-
-/** Common parent interface for all generated classes. */
-interface XdrElement {
- void encode(XdrDataOutputStream stream) throws IOException;
-
- default String toXdrBase64() throws IOException {
- return Base64Factory.getInstance().encodeToString(toXdrByteArray());
- }
-
- default byte[] toXdrByteArray() throws IOException {
- ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
- XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream);
- encode(xdrDataOutputStream);
- return byteArrayOutputStream.toByteArray();
- }
-}
diff --git a/spec/output/generator_spec_java/union.x/XdrString.java b/spec/output/generator_spec_java/union.x/XdrString.java
deleted file mode 100644
index a51eead77..000000000
--- a/spec/output/generator_spec_java/union.x/XdrString.java
+++ /dev/null
@@ -1,62 +0,0 @@
-package MyXDR;
-
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import java.io.InvalidClassException;
-import java.nio.charset.StandardCharsets;
-import lombok.Value;
-import org.stellar.sdk.Base64Factory;
-
-@Value
-public class XdrString implements XdrElement {
- byte[] bytes;
-
- public XdrString(byte[] bytes) {
- this.bytes = bytes;
- }
-
- public XdrString(String text) {
- this.bytes = text.getBytes(StandardCharsets.UTF_8);
- }
-
- @Override
- public void encode(XdrDataOutputStream stream) throws IOException {
- stream.writeInt(this.bytes.length);
- stream.write(this.bytes, 0, this.bytes.length);
- }
-
- public static XdrString decode(XdrDataInputStream stream, int maxSize) throws IOException {
- int size = stream.readInt();
- if (size > maxSize) {
- throw new IllegalArgumentException("String length " + size + " exceeds max size " + maxSize);
- }
- byte[] bytes = new byte[size];
- stream.read(bytes);
- return new XdrString(bytes);
- }
-
- public static XdrString fromXdrBase64(String xdr, int maxSize) throws IOException {
- byte[] bytes = Base64Factory.getInstance().decode(xdr);
- return fromXdrByteArray(bytes, maxSize);
- }
-
- public static XdrString fromXdrBase64(String xdr) throws IOException {
- return fromXdrBase64(xdr, Integer.MAX_VALUE);
- }
-
- public static XdrString fromXdrByteArray(byte[] xdr, int maxSize) throws IOException {
- ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr);
- XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream);
- return decode(xdrDataInputStream, maxSize);
- }
-
- public static XdrString fromXdrByteArray(byte[] xdr) throws IOException {
- return fromXdrByteArray(xdr, Integer.MAX_VALUE);
- }
-
- @Override
- public String toString() {
- return new String(bytes, StandardCharsets.UTF_8);
- }
-}
diff --git a/spec/output/generator_spec_java/union.x/XdrUnsignedHyperInteger.java b/spec/output/generator_spec_java/union.x/XdrUnsignedHyperInteger.java
deleted file mode 100644
index 5d798cded..000000000
--- a/spec/output/generator_spec_java/union.x/XdrUnsignedHyperInteger.java
+++ /dev/null
@@ -1,69 +0,0 @@
-package MyXDR;
-
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import java.math.BigInteger;
-import lombok.Value;
-import org.stellar.sdk.Base64Factory;
-
-/**
- * Represents XDR Unsigned Hyper Integer.
- *
- * @see XDR: External Data
- * Representation Standard
- */
-@Value
-public class XdrUnsignedHyperInteger implements XdrElement {
- public static final BigInteger MAX_VALUE = new BigInteger("18446744073709551615");
- public static final BigInteger MIN_VALUE = BigInteger.ZERO;
- BigInteger number;
-
- public XdrUnsignedHyperInteger(BigInteger number) {
- if (number.compareTo(MIN_VALUE) < 0 || number.compareTo(MAX_VALUE) > 0) {
- throw new IllegalArgumentException("number must be between 0 and 2^64 - 1 inclusive");
- }
- this.number = number;
- }
-
- public XdrUnsignedHyperInteger(Long number) {
- if (number < 0) {
- throw new IllegalArgumentException(
- "number must be greater than or equal to 0 if you want to construct it from Long");
- }
- this.number = BigInteger.valueOf(number);
- }
-
- @Override
- public void encode(XdrDataOutputStream stream) throws IOException {
- stream.write(getBytes());
- }
-
- public static XdrUnsignedHyperInteger decode(XdrDataInputStream stream) throws IOException {
- byte[] bytes = new byte[8];
- stream.readFully(bytes);
- BigInteger uint64 = new BigInteger(1, bytes);
- return new XdrUnsignedHyperInteger(uint64);
- }
-
- private byte[] getBytes() {
- byte[] bytes = number.toByteArray();
- byte[] paddedBytes = new byte[8];
-
- int numBytesToCopy = Math.min(bytes.length, 8);
- int copyStartIndex = bytes.length - numBytesToCopy;
- System.arraycopy(bytes, copyStartIndex, paddedBytes, 8 - numBytesToCopy, numBytesToCopy);
- return paddedBytes;
- }
-
- public static XdrUnsignedHyperInteger fromXdrBase64(String xdr) throws IOException {
- byte[] bytes = Base64Factory.getInstance().decode(xdr);
- return fromXdrByteArray(bytes);
- }
-
- public static XdrUnsignedHyperInteger fromXdrByteArray(byte[] xdr) throws IOException {
- ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr);
- XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream);
- return decode(xdrDataInputStream);
- }
-}
diff --git a/spec/output/generator_spec_java/union.x/XdrUnsignedInteger.java b/spec/output/generator_spec_java/union.x/XdrUnsignedInteger.java
deleted file mode 100644
index bea880aee..000000000
--- a/spec/output/generator_spec_java/union.x/XdrUnsignedInteger.java
+++ /dev/null
@@ -1,57 +0,0 @@
-package MyXDR;
-
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import lombok.Value;
-import org.stellar.sdk.Base64Factory;
-
-/**
- * Represents XDR Unsigned Integer.
- *
- * @see XDR: External Data
- * Representation Standard
- */
-@Value
-public class XdrUnsignedInteger implements XdrElement {
- public static final long MAX_VALUE = (1L << 32) - 1;
- public static final long MIN_VALUE = 0;
- Long number;
-
- public XdrUnsignedInteger(Long number) {
- if (number < MIN_VALUE || number > MAX_VALUE) {
- throw new IllegalArgumentException("number must be between 0 and 2^32 - 1 inclusive");
- }
- this.number = number;
- }
-
- public XdrUnsignedInteger(Integer number) {
- if (number < 0) {
- throw new IllegalArgumentException(
- "number must be greater than or equal to 0 if you want to construct it from Integer");
- }
- this.number = number.longValue();
- }
-
- public static XdrUnsignedInteger decode(XdrDataInputStream stream) throws IOException {
- int intValue = stream.readInt();
- long uint32Value = Integer.toUnsignedLong(intValue);
- return new XdrUnsignedInteger(uint32Value);
- }
-
- @Override
- public void encode(XdrDataOutputStream stream) throws IOException {
- stream.writeInt(number.intValue());
- }
-
- public static XdrUnsignedInteger fromXdrBase64(String xdr) throws IOException {
- byte[] bytes = Base64Factory.getInstance().decode(xdr);
- return fromXdrByteArray(bytes);
- }
-
- public static XdrUnsignedInteger fromXdrByteArray(byte[] xdr) throws IOException {
- ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr);
- XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream);
- return decode(xdrDataInputStream);
- }
-}
diff --git a/spec/output/generator_spec_python/block_comments.x/__init__.py b/spec/output/generator_spec_python/block_comments.x/__init__.py
deleted file mode 100644
index fc7fc5c15..000000000
--- a/spec/output/generator_spec_python/block_comments.x/__init__.py
+++ /dev/null
@@ -1,5 +0,0 @@
-# Automatically generated by xdrgen
-# DO NOT EDIT or your changes may be overwritten
-from .base import *
-from .constants import *
-from .account_flags import AccountFlags
diff --git a/spec/output/generator_spec_python/block_comments.x/account_flags.py b/spec/output/generator_spec_python/block_comments.x/account_flags.py
deleted file mode 100644
index 2073c5b6e..000000000
--- a/spec/output/generator_spec_python/block_comments.x/account_flags.py
+++ /dev/null
@@ -1,47 +0,0 @@
-# This is an automatically generated file.
-# DO NOT EDIT or your changes may be overwritten
-from __future__ import annotations
-
-import base64
-from enum import IntEnum
-from typing import List, Optional, TYPE_CHECKING
-from xdrlib3 import Packer, Unpacker
-from .base import Integer, UnsignedInteger, Float, Double, Hyper, UnsignedHyper, Boolean, String, Opaque
-from .constants import *
-
-__all__ = ['AccountFlags']
-class AccountFlags(IntEnum):
- """
- XDR Source Code::
-
- enum AccountFlags
- { // masks for each flag
- AUTH_REQUIRED_FLAG = 0x1
- };
- """
- AUTH_REQUIRED_FLAG = 1
- def pack(self, packer: Packer) -> None:
- packer.pack_int(self.value)
-
- @classmethod
- def unpack(cls, unpacker: Unpacker) -> AccountFlags:
- value = unpacker.unpack_int()
- return cls(value)
- def to_xdr_bytes(self) -> bytes:
- packer = Packer()
- self.pack(packer)
- return packer.get_buffer()
-
- @classmethod
- def from_xdr_bytes(cls, xdr: bytes) -> AccountFlags:
- unpacker = Unpacker(xdr)
- return cls.unpack(unpacker)
-
- def to_xdr(self) -> str:
- xdr_bytes = self.to_xdr_bytes()
- return base64.b64encode(xdr_bytes).decode()
-
- @classmethod
- def from_xdr(cls, xdr: str) -> AccountFlags:
- xdr_bytes = base64.b64decode(xdr.encode())
- return cls.from_xdr_bytes(xdr_bytes)
diff --git a/spec/output/generator_spec_python/block_comments.x/base.py b/spec/output/generator_spec_python/block_comments.x/base.py
deleted file mode 100644
index 65179b8f3..000000000
--- a/spec/output/generator_spec_python/block_comments.x/base.py
+++ /dev/null
@@ -1,252 +0,0 @@
-from xdrlib3 import Packer, Unpacker
-
-__all__ = [
- "Integer",
- "UnsignedInteger",
- "Float",
- "Double",
- "Hyper",
- "UnsignedHyper",
- "Boolean",
- "String",
- "Opaque",
-]
-
-
-class Integer:
- def __init__(self, value: int) -> None:
- self.value = value
-
- def pack(self, packer: Packer) -> None:
- packer.pack_int(self.value)
-
- @staticmethod
- def unpack(unpacker: Unpacker) -> int:
- return unpacker.unpack_int()
-
- def __hash__(self):
- return hash(self.value)
-
- def __eq__(self, other: object) -> bool:
- if not isinstance(other, self.__class__):
- return NotImplemented
- return self.value == other.value
-
- def __str__(self):
- return f"