diff options
author | Mark Henderson <mehe@google.com> | 2018-04-23 12:54:20 -0700 |
---|---|---|
committer | Wouter van Oortmerssen <aardappel@gmail.com> | 2018-04-23 12:54:20 -0700 |
commit | 34cb163e389e928db08ed2bd0e16ee0ac53ab1ce (patch) | |
tree | a1e99517624fe0fbcc05813c585a18ffc2afdedb /js | |
parent | a66f9e769bc427fc580a58b2c6dbf259de8a24a5 (diff) | |
download | flatbuffers-34cb163e389e928db08ed2bd0e16ee0ac53ab1ce.tar.gz flatbuffers-34cb163e389e928db08ed2bd0e16ee0ac53ab1ce.tar.bz2 flatbuffers-34cb163e389e928db08ed2bd0e16ee0ac53ab1ce.zip |
Adding JS function to get the File Identifier (#4715)
* Adding JS function to get the File Identifier
* Update flatbuffers.js
Diffstat (limited to 'js')
-rw-r--r-- | js/flatbuffers.js | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/js/flatbuffers.js b/js/flatbuffers.js index 4c2bf52d..580020a4 100644 --- a/js/flatbuffers.js +++ b/js/flatbuffers.js @@ -1041,6 +1041,26 @@ flatbuffers.ByteBuffer.prototype.writeFloat64 = function(offset, value) { }; /** + * 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. * |