From cf0d7829a67de8a1f1d926a4bd11ef831e0e3e2c Mon Sep 17 00:00:00 2001 From: benssson Date: Wed, 26 Oct 2016 18:29:36 +0100 Subject: [PATCH 1/5] Fixed javascript helper for typed arrays of scalars not taking into (#4068) account underlying buffer's byte offset. --- src/idl_gen_js.cpp | 2 +- tests/monster_test.bfbs | Bin 3320 -> 3320 bytes tests/monster_test_generated.js | 6 +++--- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/idl_gen_js.cpp b/src/idl_gen_js.cpp index fec578029..23fd52c57 100644 --- a/src/idl_gen_js.cpp +++ b/src/idl_gen_js.cpp @@ -581,7 +581,7 @@ void GenStruct(const Parser &parser, StructDef &struct_def, std::string *code_pt code += object_name + ".prototype." + MakeCamel(field.name, false); code += "Array = function() {\n" + offset_prefix; code += "new " + GenType(vectorType) + "Array(this.bb.bytes().buffer, " - "this.bb.__vector(this.bb_pos + offset), " + "this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), " "this.bb.__vector_len(this.bb_pos + offset)) : null;\n};\n\n"; } } diff --git a/tests/monster_test.bfbs b/tests/monster_test.bfbs index 41d9edb1c43c2965eddd178a73fa1c7c08409a7c..66d3ee8f215a67b4978d70df9bdb2e6d344e89b8 100644 GIT binary patch delta 53 zcmew%`9pF62af{-1A`9`vjFjA6%G>#4j?0~C^I!LC8rX|Wcc>`|9>FGv^j!f0Sf>~ CpACNi delta 52 zcmew%`9pF6hYAk^1A_z*%K$M45T_Morsk#OR05d{hkpP652TnT^Kh7Kj^J3p0suN8 B4C4R* diff --git a/tests/monster_test_generated.js b/tests/monster_test_generated.js index 774882d7c..6789ebb42 100644 --- a/tests/monster_test_generated.js +++ b/tests/monster_test_generated.js @@ -693,7 +693,7 @@ MyGame.Example.Monster.prototype.inventoryLength = function() { */ MyGame.Example.Monster.prototype.inventoryArray = function() { var offset = this.bb.__offset(this.bb_pos, 14); - return offset ? new Uint8Array(this.bb.bytes().buffer, this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; + return offset ? new Uint8Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; }; /** @@ -839,7 +839,7 @@ MyGame.Example.Monster.prototype.testnestedflatbufferLength = function() { */ MyGame.Example.Monster.prototype.testnestedflatbufferArray = function() { var offset = this.bb.__offset(this.bb_pos, 30); - return offset ? new Uint8Array(this.bb.bytes().buffer, this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; + return offset ? new Uint8Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; }; /** @@ -1080,7 +1080,7 @@ MyGame.Example.Monster.prototype.testarrayofboolsLength = function() { */ MyGame.Example.Monster.prototype.testarrayofboolsArray = function() { var offset = this.bb.__offset(this.bb_pos, 52); - return offset ? new Int8Array(this.bb.bytes().buffer, this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; + return offset ? new Int8Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; }; /** From 76ae10df42513d3026c51f86961e90ee5a3c3387 Mon Sep 17 00:00:00 2001 From: The Gitter Badger Date: Wed, 2 Nov 2016 16:05:31 -0500 Subject: [PATCH 2/5] Add Gitter badge (#4075) --- readme.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/readme.md b/readme.md index 38bf355dd..8d05c314d 100755 --- a/readme.md +++ b/readme.md @@ -1,5 +1,7 @@ ![logo](http://google.github.io/flatbuffers/fpl_logo_small.png) FlatBuffers =========== + +[![Join the chat at https://gitter.im/google/flatbuffers](https://badges.gitter.im/google/flatbuffers.svg)](https://gitter.im/google/flatbuffers?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) [![Build Status](https://travis-ci.org/google/flatbuffers.svg?branch=master)](https://travis-ci.org/google/flatbuffers) [![Build status](https://ci.appveyor.com/api/projects/status/yg5idd2fnusv1n10?svg=true)](https://ci.appveyor.com/project/gwvo/flatbuffers) **FlatBuffers** is an efficient cross platform serialization library for games and From d298adc4e6f840191d556dddccaa76868bbca3c3 Mon Sep 17 00:00:00 2001 From: Michael Paulson Date: Mon, 7 Nov 2016 10:27:26 -0800 Subject: [PATCH 3/5] chore(lint) (#4079) * chore(lint) I accidentally let 2 pieces of lint in with my generated code. * fix(generate-code): I did not generate all the required code for tests. --- .gitignore | 1 + src/idl_gen_js.cpp | 4 +- tests/monster_test.bfbs | Bin 3320 -> 3384 bytes tests/monster_test_generated.js | 104 +++++++++--------- .../namespace_test1_generated.js | 12 +- .../namespace_test2_generated.js | 4 +- 6 files changed, 63 insertions(+), 62 deletions(-) diff --git a/.gitignore b/.gitignore index 79c70d0cd..9dfabefad 100755 --- a/.gitignore +++ b/.gitignore @@ -65,3 +65,4 @@ build/VS2010/FlatBuffers.sdf build/VS2010/FlatBuffers.opensdf build/VS2010/ipch/**/*.ipch *.so +Testing/Temporary diff --git a/src/idl_gen_js.cpp b/src/idl_gen_js.cpp index 23fd52c57..32c660c90 100644 --- a/src/idl_gen_js.cpp +++ b/src/idl_gen_js.cpp @@ -557,13 +557,13 @@ void GenStruct(const Parser &parser, StructDef &struct_def, std::string *code_pt "@returns {boolean}"); code += object_name + ".prototype.mutate_" + field.name + " = function(value) {\n"; - code += " var offset = this.bb.__offset(this.bb_pos, " + NumToString(field.value.offset) + ")\n\n"; + code += " var offset = this.bb.__offset(this.bb_pos, " + NumToString(field.value.offset) + ");\n\n"; code += " if (offset === 0) {\n"; code += " return false;\n"; code += " }\n\n"; code += " this.bb.write" + MakeCamel(GenType(field.value.type)) + "(this.bb_pos + offset, value);\n"; code += " return true;\n"; - code += "}\n\n"; + code += "};\n\n"; } // Emit vector helpers diff --git a/tests/monster_test.bfbs b/tests/monster_test.bfbs index 66d3ee8f215a67b4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)%|FRd-hXEQ{DjaJz|PPHYZW z{Ef1U=cgLW6v}Pnr5kF*F;42(MSs@Ju#c;IBx<(rLca@>l341{e%@PmJ-<}hfX7kg zyPlEEc@oj_O>U#%JBXe!W~>n3R@2yA1~Dc&##yT8L{yz)V<9hB@}){%wS&T*Q&^E~ zCGUEf0!t|`b&MTJoYQDya2||9_E4Xr?vamuSk<)=FL8KH$?qDc`g{lbP8HYxaqPDxjq7~?Zga=znfH%C z>ssFP96W@I+PqQD2G#ROdiEf1mNAZRjqV+A+MEDU?<}aLo{Mn1?PnnIyqmWFSQqBR zE?XD&AM?(-*wwiAoI|`V_U7vQKVa?zznH0S?AB{YTVYU}8q!~N)-vSUKh6dFJ%At0 zqJJTE!*stfo>kCebq}PI6Gdm$C>TaP=97L=$5HoNPaHiNLL3 n?e~5 Date: Wed, 9 Nov 2016 17:38:48 -0500 Subject: [PATCH 4/5] Making flatbuffers JSON parsing deal with unexpected null values when unknown JSON is allowed. (#4083) --- src/idl_parser.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/idl_parser.cpp b/src/idl_parser.cpp index f69ae4c07..0dc739240 100644 --- a/src/idl_parser.cpp +++ b/src/idl_parser.cpp @@ -1758,6 +1758,9 @@ CheckedError Parser::SkipAnyJsonValue() { case kTokenFloatConstant: EXPECT(kTokenFloatConstant); break; + case kTokenNull: + EXPECT(kTokenNull); + break; default: return Error(std::string("Unexpected token:") + std::string(1, static_cast(token_))); } From dbecdf209de88ed0910ba602d326d33b5aefed93 Mon Sep 17 00:00:00 2001 From: Antoine Descamps Date: Wed, 16 Nov 2016 18:54:57 +0100 Subject: [PATCH 5/5] [PHP] Use mb_detect_encoding when available (#3952) I've faced an issue where I want to serialize UTF-8 emojis and FlatBufferBuilder::is_utf8 would return false on them. I was not able to add the corresponding hexadecimal code because I don't understand how the whole thing works but what i've done is using the `mb_detect_encoding` function which handles correctly all supposed UTF-8 characters. --- php/FlatbufferBuilder.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/php/FlatbufferBuilder.php b/php/FlatbufferBuilder.php index 6f0ee4831..5c18bf46a 100644 --- a/php/FlatbufferBuilder.php +++ b/php/FlatbufferBuilder.php @@ -593,6 +593,10 @@ class FlatbufferBuilder protected function is_utf8($bytes) { + if (function_exists('mb_detect_encoding')) { + return (bool) mb_detect_encoding($bytes, 'UTF-8', true); + } + $len = strlen($bytes); if ($len < 1) { /* NOTE: always return 1 when passed string is null */