Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix decode in render_union in java #25

Merged
merged 1 commit into from
Feb 7, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
17 changes: 12 additions & 5 deletions lib/xdrgen/generators/java.rb
Expand Up @@ -230,6 +230,8 @@ def render_union(union, out)
out.puts "public static void encode(XdrDataOutputStream stream, #{name union} encoded#{name union}) throws IOException {"
if union.discriminant.type.is_a?(AST::Typespecs::Int)
out.puts "stream.writeInt(encoded#{name union}.getDiscriminant().intValue());"
# elsif [discriminant is AST::Definitions::Typedef]
# out.puts "stream.writeInt(encoded#{name union}.getDiscriminant().get#{name union.discriminant.type}());"
else
out.puts "stream.writeInt(encoded#{name union}.getDiscriminant().getValue());"
end
Expand All @@ -252,11 +254,16 @@ def render_union(union, out)
end
out.puts "}\n}"

out.puts <<-EOS.strip_heredoc
public static #{name union} decode(XdrDataInputStream stream) throws IOException {
#{name union} decoded#{name union} = new #{name union}();
switch (decoded#{name union}.getDiscriminant()) {
EOS
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);"
out.puts "switch (decoded#{name union}.getDiscriminant()) {"

union.arms.each do |arm|
case arm
when AST::Definitions::UnionDefaultArm ;
Expand Down