title: JNA how do I go from a C int* to a JNA struct
body: <p>I have the following C code that I am trying to map into java:</p>
  
  <pre><code>int32 Query( void* qryBuffer, 
              uint32_t qryLength)
  {
    static int8_t  sendBuffer[MAX_REQUEST_SIZE];
    message*  queryMessage;
  ...
    queryMessage = (message*)sendBuffer;
  
    memcpy( &amp;sendBuffer[0], &amp;qryLength, sizeof(qryLength) );
    memcpy( &amp;sendBuffer[sizeof(qryLength)], qryBuffer, qryLength );
  ...
    query_ex(queryMessage);
  }
  
  typedef struct
  {                               
      uint32      length_u;       
  } message;
  </code></pre>
  
  <p>The JNA equivalent is for the message struct is:</p>
  
  <pre><code>public static class message extends Structure {
      public int length_u;
      public message() {
          super();
      }
      protected List getFieldOrder() {
          return Arrays.asList("length_u");
      }
      public message(int length_u) {
          super();
          this.length_u = length_u;
      }
      public static class ByReference extends omni_message implements Structure.ByReference {
      };
      public static class ByValue extends omni_message implements Structure.ByValue {
      };
  };
  </code></pre>
  
  <p>I know what they are doing in the C code, but I cannot figure out how to do this on the Java side.
   I need to have the Java message class contain the length and the array of the parameters that were passed in</p>
  
  <p>Please help!</p>
  
  <p>Update:
  I have created my own copy of the message struct that holds the byte[]:</p>
  
  <pre><code>    public static class messageEx extends Structure {
          public byte[] buffer;
  ...
      }
  </code></pre>
  
  <p>I am going to try and pass this struct in as oppose to the other one, but I cannot test until tomorrow.</p>
  
  <pre><code>int size = struct.size();
  byte[] buffer = new byte[size];
  ByteBuffer bb = ByteBuffer.wrap(buffer);
  bb.putInt(size);
  bb.put(struct.getPointer().getByteArray(0, size));
  messageEx msg = new messageEx(buffer);
  query_ex(msg); // call to native world
  </code></pre>