Esempio n. 1
0
 public void finish(int root_table, String file_identifier) {
   prep(minalign, Constants.SIZEOF_INT + Constants.FILE_IDENTIFIER_LENGTH);
   if (file_identifier.length() != Constants.FILE_IDENTIFIER_LENGTH)
     throw new AssertionError(
         "FlatBuffers: file identifier must be length " + Constants.FILE_IDENTIFIER_LENGTH);
   for (int i = Constants.FILE_IDENTIFIER_LENGTH - 1; i >= 0; i--) {
     addByte((byte) file_identifier.charAt(i));
   }
   finish(root_table);
 }
Esempio n. 2
0
 public void finish(int root_table) {
   prep(minalign, Constants.SIZEOF_INT);
   addOffset(root_table);
   bb.position(space);
 }
Esempio n. 3
0
 /**
  * Adds on offset, relative to where it will be written.
  *
  * @param off The offset to add
  */
 public void addOffset(int off) {
   prep(Constants.SIZEOF_INT, 0); // Ensure alignment is already done.
   assert off <= offset();
   off = offset() - off + Constants.SIZEOF_INT;
   putInt(off);
 }
Esempio n. 4
0
 /**
  * Start a new array/vector of objects. Users usually will not call this directly. The {@code
  * FlatBuffers} compiler will create a start/end method for vector types in generated code.
  *
  * <p>The expected sequence of calls is:
  *
  * <ol>
  *   <li>Start the array using this method.
  *   <li>Call {@link #addOffset(int)} {@code num_elems} number of times to set the offset of each
  *       element in the array.
  *   <li>Call {@link #endVector()} to retrieve the offset of the array.
  * </ol>
  *
  * <p>For example, to create an array of strings, do:
  *
  * <pre>{@code
  * // Need 10 strings
  * FlatBufferBuilder builder = new FlatBufferBuilder(existingBuffer);
  * int[] offsets = new int[10];
  *
  * for (int i = 0; i < 10; i++) {
  *   offsets[i] = fbb.createString(" " + i);
  * }
  *
  * // Have the strings in the buffer, but don't have a vector.
  * // Add a vector that references the newly created strings:
  * builder.startVector(4, offsets.length, 4);
  *
  * // Add each string to the newly created vector
  * // The strings are added in reverse order since the buffer
  * // is filled in back to front
  * for (int i = offsets.length - 1; i >= 0; i--) {
  *   builder.addOffset(offsets[i]);
  * }
  *
  * // Finish off the vector
  * int offsetOfTheVector = fbb.endVector();
  * }</pre>
  *
  * @param elem_size The size of each element in the array
  * @param num_elems The number of elements in the array
  * @param alignment The alignment of the array
  */
 public void startVector(int elem_size, int num_elems, int alignment) {
   notNested();
   vector_num_elems = num_elems;
   prep(Constants.SIZEOF_INT, elem_size * num_elems);
   prep(alignment, elem_size * num_elems); // Just in case alignment > int.
 }
Esempio n. 5
0
 public void addFloat(float x) {
   prep(4, 0);
   putFloat(x);
 }
Esempio n. 6
0
 public void addDouble(double x) {
   prep(8, 0);
   putDouble(x);
 }
Esempio n. 7
0
 public void addLong(long x) {
   prep(8, 0);
   putLong(x);
 }
Esempio n. 8
0
 public void addInt(int x) {
   prep(4, 0);
   putInt(x);
 }
Esempio n. 9
0
 public void addShort(short x) {
   prep(2, 0);
   putShort(x);
 }
Esempio n. 10
0
 public void addByte(byte x) {
   prep(1, 0);
   putByte(x);
 }
Esempio n. 11
0
 // Adds a scalar to the buffer, properly aligned, and the buffer grown
 // if needed.
 public void addBoolean(boolean x) {
   prep(1, 0);
   putBoolean(x);
 }