Commit 34cb163e authored by Mark Henderson's avatar Mark Henderson Committed by Wouter van Oortmerssen

Adding JS function to get the File Identifier (#4715)

* Adding JS  function to get the File Identifier

* Update flatbuffers.js
parent a66f9e76
......@@ -1040,6 +1040,26 @@ flatbuffers.ByteBuffer.prototype.writeFloat64 = function(offset, value) {
this.writeInt32(offset + 4, flatbuffers.int32[flatbuffers.isLittleEndian ? 1 : 0]);
};
/**
* Return the file identifier. Behavior is undefined for FlatBuffers whose
* schema does not include a file_identifier (likely points at padding or the
* start of a the root vtable).
* @returns {string}
*/
flatbuffers.ByteBuffer.prototype.getBufferIdentifier = function() {
if (this.bytes_.length < this.position_ + flatbuffers.SIZEOF_INT +
flatbuffers.FILE_IDENTIFIER_LENGTH) {
throw new Error(
'FlatBuffers: ByteBuffer is too short to contain an identifier.');
}
var result = "";
for (var i = 0; i < flatbuffers.FILE_IDENTIFIER_LENGTH; i++) {
result += String.fromCharCode(
this.readInt8(this.position_ + flatbuffers.SIZEOF_INT + i));
}
return result;
};
/**
* Look up a field in the vtable, return an offset into the object, or 0 if the
* field is not present.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment