コード例 #1
0
ファイル: FlatBufferBuilder.java プロジェクト: 0101RGB/CREPAS
 /**
  * Start encoding a new object in the buffer. Users will not usually need to call this directly.
  * The {@code FlatBuffers} compiler will generate helper methods that call this method internally.
  *
  * <p>For example, using the "Monster" code found on the <a
  * href="http://google.github.io/flatbuffers/md__java_usage.html">landing page</a>. An object of
  * type {@code Monster} can be created using the following code:
  *
  * <pre>{@code
  * int testArrayOfString = Monster.createTestarrayofstringVector(fbb, new int[] {
  *   fbb.createString("test1"),
  *   fbb.createString("test2")
  * });
  *
  * Monster.startMonster(fbb);
  * Monster.addPos(fbb, Vec3.createVec3(fbb, 1.0f, 2.0f, 3.0f, 3.0,
  *   Color.Green, (short)5, (byte)6));
  * Monster.addHp(fbb, (short)80);
  * Monster.addName(fbb, str);
  * Monster.addInventory(fbb, inv);
  * Monster.addTestType(fbb, (byte)Any.Monster);
  * Monster.addTest(fbb, mon2);
  * Monster.addTest4(fbb, test4);
  * Monster.addTestarrayofstring(fbb, testArrayOfString);
  * int mon = Monster.endMonster(fbb);
  * }</pre>
  *
  * <p>Here:
  *
  * <ul>
  *   <li>The call to {@code Monster#startMonster(FlatBufferBuilder)} will call this method with
  *       the right number of fields set.
  *   <li>{@code Monster#endMonster(FlatBufferBuilder)} will ensure {@link #endObject()} is called.
  * </ul>
  *
  * <p>It's not recommended to call this method directly. If it's called manually, you must ensure
  * to audit all calls to it whenever fields are added or removed from your schema. This is
  * automatically done by the code generated by the {@code FlatBuffers} compiler.
  *
  * @param numfields The number of fields found in this object.
  */
 public void startObject(int numfields) {
   notNested();
   if (vtable == null || vtable.length < numfields) vtable = new int[numfields];
   vtable_in_use = numfields;
   Arrays.fill(vtable, 0, vtable_in_use, 0);
   nested = true;
   object_start = offset();
 }
コード例 #2
0
ファイル: FlatBufferBuilder.java プロジェクト: 0101RGB/CREPAS
 /**
  * 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.
 }