Skip to content

Commit

Permalink
fix compilation problem with one stellar type (#42)
Browse files Browse the repository at this point in the history
it was crashing on this 'union AuthenticatedMessage switch (uint32 v)'

The discriminator for this is not an int. This fixes it but in a code base specific way. Not sure how to isolate this properly. But at least it addresses the problem.
  • Loading branch information
jillesvangurp authored and bartekn committed Dec 14, 2018
1 parent c56e3ff commit 1be840e
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions lib/xdrgen/generators/java.rb
Original file line number Diff line number Diff line change
Expand Up @@ -228,14 +228,22 @@ def render_union(union, out)
end

out.puts "public static void encode(XdrDataOutputStream stream, #{name union} encoded#{name union}) throws IOException {"
out.puts('//' + union.discriminant.type.class.to_s)
out.puts("//" + type_string(union.discriminant.type))
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}());"
elsif type_string(union.discriminant.type) == "Uint32"
# ugly workaround for compile error after generating source for AuthenticatedMessage in stellar-core
out.puts "stream.writeInt(encoded#{name union}.getDiscriminant().getUint32());"
else
out.puts "stream.writeInt(encoded#{name union}.getDiscriminant().getValue());"
end
out.puts "switch (encoded#{name union}.getDiscriminant()) {"
if type_string(union.discriminant.type) == "Uint32"
# ugly workaround for compile error after generating source for AuthenticatedMessage in stellar-core
out.puts "switch (encoded#{name union}.getDiscriminant().getUint32()) {"
else
out.puts "switch (encoded#{name union}.getDiscriminant()) {"
end
union.arms.each do |arm|
case arm
when AST::Definitions::UnionDefaultArm ;
Expand All @@ -262,7 +270,13 @@ def render_union(union, out)
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()) {"

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()) {"
else
out.puts "switch (decoded#{name union}.getDiscriminant()) {"
end

union.arms.each do |arm|
case arm
Expand Down

0 comments on commit 1be840e

Please sign in to comment.