Implemented the file identifier functionality for Java.

Also fixed flatc not outputting these identifiers for files
compiled on the command-line.

Bug: 16983987
Change-Id: I8b714cfea3a8e144fa52133f62b2f7eda6eb044a
Tested: on Linux
This commit is contained in:
Wouter van Oortmerssen
2014-09-04 16:31:44 -07:00
parent 96592d5dbb
commit 09a2999c66
16 changed files with 113 additions and 17 deletions

View File

@@ -21,12 +21,10 @@ import java.nio.ByteBuffer;
import java.nio.charset.Charset;
// All tables in the generated code derive from this class, and add their own accessors.
public class Table {
public class Table extends Constants {
protected int bb_pos;
protected ByteBuffer bb;
final int SIZEOF_INT = 4;
// Look up a field in the vtable, return an offset into the object, or 0 if the field is not
// present.
protected int __offset(int vtable_offset) {
@@ -75,4 +73,14 @@ public class Table {
t.bb = bb;
return t;
}
protected static boolean __has_identifier(ByteBuffer bb, int offset, String ident) {
if (ident.length() != FILE_IDENTIFIER_LENGTH)
throw new AssertionError("FlatBuffers: file identifier must be length " +
FILE_IDENTIFIER_LENGTH);
for (int i = 0; i < FILE_IDENTIFIER_LENGTH; i++) {
if (ident.charAt(i) != (char)bb.get(offset + SIZEOF_INT + i)) return false;
}
return true;
}
}