Skip to content

Conversation

@mthmulders
Copy link

Given a small input file, sample.tt:

const MY_CONSTANT = 42;
typedef long MyLongs[MY_CONSTANT];
struct MyStructure {
     MyLongs myLongs;
};

Invoking Treetop with: bundle exec xdrgen sample.tt -o generated -l java -n generated, it generates this Java source file:

// Automatically generated by xdrgen 
// DO NOT EDIT or your changes may be overwritten

package generated;


import java.io.IOException;

// === xdr source ============================================================

//  typedef long MyLongs[MY_CONSTANT];

//  ===========================================================================
public class MyLongs  {
  private Long[] MyLongs;
  public Long[] getMyLongs() {
    return this.MyLongs;
  }
  public void setMyLongs(Long[] value) {
    this.MyLongs = value;
  }
  public static void encode(XdrDataOutputStream stream, MyLongs  encodedMyLongs) throws IOException {
  int MyLongssize = encodedMyLongs.getMyLongs().length;
  for (int i = 0; i < MyLongssize; i++) {
    stream.writeLong(encodedMyLongs.MyLongs[i]);
  }
  }
  public static MyLongs decode(XdrDataInputStream stream) throws IOException {
    MyLongs decodedMyLongs = new MyLongs();
  int MyLongssize = MY_CONSTANT;
  decodedMyLongs.MyLongs = new Long[MyLongssize];
  for (int i = 0; i < MyLongssize; i++) {
    decodedMyLongs.MyLongs[i] = stream.readLong();
  }
    return decodedMyLongs;
  }
}

Apart from the fact that this code does not compile (#33) it also has some strange indentation choices in its encode and decode methods. This PR fixes that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant