mirror of
https://github.com/google/flatbuffers.git
synced 2026-06-26 21:02:17 +00:00
fixed mutating inline values (#5942)
Co-authored-by: Kamil Rojewski <kamil.rojewski@gmail.com>
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -126,3 +126,4 @@ Cargo.lock
|
|||||||
grpc/google/
|
grpc/google/
|
||||||
**/Package.resolved
|
**/Package.resolved
|
||||||
.clangd/**
|
.clangd/**
|
||||||
|
package-lock.json
|
||||||
|
|||||||
@@ -1625,19 +1625,25 @@ class JsTsGenerator : public BaseGenerator {
|
|||||||
" = function(value) {\n";
|
" = function(value) {\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
code += " var offset = " + GenBBAccess() + ".__offset(this.bb_pos, " +
|
if (struct_def.fixed) {
|
||||||
NumToString(field.value.offset) + ");\n\n";
|
code += " " + GenBBAccess() + ".write" +
|
||||||
code += " if (offset === 0) {\n";
|
MakeCamel(GenType(field.value.type)) +
|
||||||
code += " return false;\n";
|
"(this.bb_pos + " + NumToString(field.value.offset) + ", ";
|
||||||
code += " }\n\n";
|
} else {
|
||||||
|
code += " var offset = " + GenBBAccess() + ".__offset(this.bb_pos, " +
|
||||||
|
NumToString(field.value.offset) + ");\n\n";
|
||||||
|
code += " if (offset === 0) {\n";
|
||||||
|
code += " return false;\n";
|
||||||
|
code += " }\n\n";
|
||||||
|
|
||||||
// special case for bools, which are treated as uint8
|
// special case for bools, which are treated as uint8
|
||||||
code += " " + GenBBAccess() + ".write" +
|
code += " " + GenBBAccess() + ".write" +
|
||||||
MakeCamel(GenType(field.value.type)) +
|
MakeCamel(GenType(field.value.type)) +
|
||||||
"(this.bb_pos + offset, ";
|
"(this.bb_pos + offset, ";
|
||||||
if (field.value.type.base_type == BASE_TYPE_BOOL &&
|
if (field.value.type.base_type == BASE_TYPE_BOOL &&
|
||||||
lang_.language == IDLOptions::kTs) {
|
lang_.language == IDLOptions::kTs) {
|
||||||
code += "+";
|
code += "+";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
code += "value);\n";
|
code += "value);\n";
|
||||||
|
|||||||
@@ -322,13 +322,7 @@ MyGame.Example.Test.prototype.a = function() {
|
|||||||
* @returns {boolean}
|
* @returns {boolean}
|
||||||
*/
|
*/
|
||||||
MyGame.Example.Test.prototype.mutate_a = function(value) {
|
MyGame.Example.Test.prototype.mutate_a = function(value) {
|
||||||
var offset = this.bb.__offset(this.bb_pos, 0);
|
this.bb.writeInt16(this.bb_pos + 0, value);
|
||||||
|
|
||||||
if (offset === 0) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
this.bb.writeInt16(this.bb_pos + offset, value);
|
|
||||||
return true;
|
return true;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -344,13 +338,7 @@ MyGame.Example.Test.prototype.b = function() {
|
|||||||
* @returns {boolean}
|
* @returns {boolean}
|
||||||
*/
|
*/
|
||||||
MyGame.Example.Test.prototype.mutate_b = function(value) {
|
MyGame.Example.Test.prototype.mutate_b = function(value) {
|
||||||
var offset = this.bb.__offset(this.bb_pos, 2);
|
this.bb.writeInt8(this.bb_pos + 2, value);
|
||||||
|
|
||||||
if (offset === 0) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
this.bb.writeInt8(this.bb_pos + offset, value);
|
|
||||||
return true;
|
return true;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -509,13 +497,7 @@ MyGame.Example.Vec3.prototype.x = function() {
|
|||||||
* @returns {boolean}
|
* @returns {boolean}
|
||||||
*/
|
*/
|
||||||
MyGame.Example.Vec3.prototype.mutate_x = function(value) {
|
MyGame.Example.Vec3.prototype.mutate_x = function(value) {
|
||||||
var offset = this.bb.__offset(this.bb_pos, 0);
|
this.bb.writeFloat32(this.bb_pos + 0, value);
|
||||||
|
|
||||||
if (offset === 0) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
this.bb.writeFloat32(this.bb_pos + offset, value);
|
|
||||||
return true;
|
return true;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -531,13 +513,7 @@ MyGame.Example.Vec3.prototype.y = function() {
|
|||||||
* @returns {boolean}
|
* @returns {boolean}
|
||||||
*/
|
*/
|
||||||
MyGame.Example.Vec3.prototype.mutate_y = function(value) {
|
MyGame.Example.Vec3.prototype.mutate_y = function(value) {
|
||||||
var offset = this.bb.__offset(this.bb_pos, 4);
|
this.bb.writeFloat32(this.bb_pos + 4, value);
|
||||||
|
|
||||||
if (offset === 0) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
this.bb.writeFloat32(this.bb_pos + offset, value);
|
|
||||||
return true;
|
return true;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -553,13 +529,7 @@ MyGame.Example.Vec3.prototype.z = function() {
|
|||||||
* @returns {boolean}
|
* @returns {boolean}
|
||||||
*/
|
*/
|
||||||
MyGame.Example.Vec3.prototype.mutate_z = function(value) {
|
MyGame.Example.Vec3.prototype.mutate_z = function(value) {
|
||||||
var offset = this.bb.__offset(this.bb_pos, 8);
|
this.bb.writeFloat32(this.bb_pos + 8, value);
|
||||||
|
|
||||||
if (offset === 0) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
this.bb.writeFloat32(this.bb_pos + offset, value);
|
|
||||||
return true;
|
return true;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -575,13 +545,7 @@ MyGame.Example.Vec3.prototype.test1 = function() {
|
|||||||
* @returns {boolean}
|
* @returns {boolean}
|
||||||
*/
|
*/
|
||||||
MyGame.Example.Vec3.prototype.mutate_test1 = function(value) {
|
MyGame.Example.Vec3.prototype.mutate_test1 = function(value) {
|
||||||
var offset = this.bb.__offset(this.bb_pos, 16);
|
this.bb.writeFloat64(this.bb_pos + 16, value);
|
||||||
|
|
||||||
if (offset === 0) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
this.bb.writeFloat64(this.bb_pos + offset, value);
|
|
||||||
return true;
|
return true;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -597,13 +561,7 @@ MyGame.Example.Vec3.prototype.test2 = function() {
|
|||||||
* @returns {boolean}
|
* @returns {boolean}
|
||||||
*/
|
*/
|
||||||
MyGame.Example.Vec3.prototype.mutate_test2 = function(value) {
|
MyGame.Example.Vec3.prototype.mutate_test2 = function(value) {
|
||||||
var offset = this.bb.__offset(this.bb_pos, 24);
|
this.bb.writeUint8(this.bb_pos + 24, value);
|
||||||
|
|
||||||
if (offset === 0) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
this.bb.writeUint8(this.bb_pos + offset, value);
|
|
||||||
return true;
|
return true;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -681,13 +639,7 @@ MyGame.Example.Ability.prototype.id = function() {
|
|||||||
* @returns {boolean}
|
* @returns {boolean}
|
||||||
*/
|
*/
|
||||||
MyGame.Example.Ability.prototype.mutate_id = function(value) {
|
MyGame.Example.Ability.prototype.mutate_id = function(value) {
|
||||||
var offset = this.bb.__offset(this.bb_pos, 0);
|
this.bb.writeUint32(this.bb_pos + 0, value);
|
||||||
|
|
||||||
if (offset === 0) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
this.bb.writeUint32(this.bb_pos + offset, value);
|
|
||||||
return true;
|
return true;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -703,13 +655,7 @@ MyGame.Example.Ability.prototype.distance = function() {
|
|||||||
* @returns {boolean}
|
* @returns {boolean}
|
||||||
*/
|
*/
|
||||||
MyGame.Example.Ability.prototype.mutate_distance = function(value) {
|
MyGame.Example.Ability.prototype.mutate_distance = function(value) {
|
||||||
var offset = this.bb.__offset(this.bb_pos, 4);
|
this.bb.writeUint32(this.bb_pos + 4, value);
|
||||||
|
|
||||||
if (offset === 0) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
this.bb.writeUint32(this.bb_pos + offset, value);
|
|
||||||
return true;
|
return true;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -356,13 +356,7 @@ a():number {
|
|||||||
* @returns boolean
|
* @returns boolean
|
||||||
*/
|
*/
|
||||||
mutate_a(value:number):boolean {
|
mutate_a(value:number):boolean {
|
||||||
var offset = this.bb!.__offset(this.bb_pos, 0);
|
this.bb!.writeInt16(this.bb_pos + 0, value);
|
||||||
|
|
||||||
if (offset === 0) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
this.bb!.writeInt16(this.bb_pos + offset, value);
|
|
||||||
return true;
|
return true;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -378,13 +372,7 @@ b():number {
|
|||||||
* @returns boolean
|
* @returns boolean
|
||||||
*/
|
*/
|
||||||
mutate_b(value:number):boolean {
|
mutate_b(value:number):boolean {
|
||||||
var offset = this.bb!.__offset(this.bb_pos, 2);
|
this.bb!.writeInt8(this.bb_pos + 2, value);
|
||||||
|
|
||||||
if (offset === 0) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
this.bb!.writeInt8(this.bb_pos + offset, value);
|
|
||||||
return true;
|
return true;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -604,13 +592,7 @@ x():number {
|
|||||||
* @returns boolean
|
* @returns boolean
|
||||||
*/
|
*/
|
||||||
mutate_x(value:number):boolean {
|
mutate_x(value:number):boolean {
|
||||||
var offset = this.bb!.__offset(this.bb_pos, 0);
|
this.bb!.writeFloat32(this.bb_pos + 0, value);
|
||||||
|
|
||||||
if (offset === 0) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
this.bb!.writeFloat32(this.bb_pos + offset, value);
|
|
||||||
return true;
|
return true;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -626,13 +608,7 @@ y():number {
|
|||||||
* @returns boolean
|
* @returns boolean
|
||||||
*/
|
*/
|
||||||
mutate_y(value:number):boolean {
|
mutate_y(value:number):boolean {
|
||||||
var offset = this.bb!.__offset(this.bb_pos, 4);
|
this.bb!.writeFloat32(this.bb_pos + 4, value);
|
||||||
|
|
||||||
if (offset === 0) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
this.bb!.writeFloat32(this.bb_pos + offset, value);
|
|
||||||
return true;
|
return true;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -648,13 +624,7 @@ z():number {
|
|||||||
* @returns boolean
|
* @returns boolean
|
||||||
*/
|
*/
|
||||||
mutate_z(value:number):boolean {
|
mutate_z(value:number):boolean {
|
||||||
var offset = this.bb!.__offset(this.bb_pos, 8);
|
this.bb!.writeFloat32(this.bb_pos + 8, value);
|
||||||
|
|
||||||
if (offset === 0) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
this.bb!.writeFloat32(this.bb_pos + offset, value);
|
|
||||||
return true;
|
return true;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -670,13 +640,7 @@ test1():number {
|
|||||||
* @returns boolean
|
* @returns boolean
|
||||||
*/
|
*/
|
||||||
mutate_test1(value:number):boolean {
|
mutate_test1(value:number):boolean {
|
||||||
var offset = this.bb!.__offset(this.bb_pos, 16);
|
this.bb!.writeFloat64(this.bb_pos + 16, value);
|
||||||
|
|
||||||
if (offset === 0) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
this.bb!.writeFloat64(this.bb_pos + offset, value);
|
|
||||||
return true;
|
return true;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -692,13 +656,7 @@ test2():MyGame.Example.Color {
|
|||||||
* @returns boolean
|
* @returns boolean
|
||||||
*/
|
*/
|
||||||
mutate_test2(value:MyGame.Example.Color):boolean {
|
mutate_test2(value:MyGame.Example.Color):boolean {
|
||||||
var offset = this.bb!.__offset(this.bb_pos, 24);
|
this.bb!.writeUint8(this.bb_pos + 24, value);
|
||||||
|
|
||||||
if (offset === 0) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
this.bb!.writeUint8(this.bb_pos + offset, value);
|
|
||||||
return true;
|
return true;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -833,13 +791,7 @@ id():number {
|
|||||||
* @returns boolean
|
* @returns boolean
|
||||||
*/
|
*/
|
||||||
mutate_id(value:number):boolean {
|
mutate_id(value:number):boolean {
|
||||||
var offset = this.bb!.__offset(this.bb_pos, 0);
|
this.bb!.writeUint32(this.bb_pos + 0, value);
|
||||||
|
|
||||||
if (offset === 0) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
this.bb!.writeUint32(this.bb_pos + offset, value);
|
|
||||||
return true;
|
return true;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -855,13 +807,7 @@ distance():number {
|
|||||||
* @returns boolean
|
* @returns boolean
|
||||||
*/
|
*/
|
||||||
mutate_distance(value:number):boolean {
|
mutate_distance(value:number):boolean {
|
||||||
var offset = this.bb!.__offset(this.bb_pos, 4);
|
this.bb!.writeUint32(this.bb_pos + 4, value);
|
||||||
|
|
||||||
if (offset === 0) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
this.bb!.writeUint32(this.bb_pos + offset, value);
|
|
||||||
return true;
|
return true;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -171,13 +171,7 @@ NamespaceA.NamespaceB.StructInNestedNS.prototype.a = function() {
|
|||||||
* @returns {boolean}
|
* @returns {boolean}
|
||||||
*/
|
*/
|
||||||
NamespaceA.NamespaceB.StructInNestedNS.prototype.mutate_a = function(value) {
|
NamespaceA.NamespaceB.StructInNestedNS.prototype.mutate_a = function(value) {
|
||||||
var offset = this.bb.__offset(this.bb_pos, 0);
|
this.bb.writeInt32(this.bb_pos + 0, value);
|
||||||
|
|
||||||
if (offset === 0) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
this.bb.writeInt32(this.bb_pos + offset, value);
|
|
||||||
return true;
|
return true;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -193,13 +187,7 @@ NamespaceA.NamespaceB.StructInNestedNS.prototype.b = function() {
|
|||||||
* @returns {boolean}
|
* @returns {boolean}
|
||||||
*/
|
*/
|
||||||
NamespaceA.NamespaceB.StructInNestedNS.prototype.mutate_b = function(value) {
|
NamespaceA.NamespaceB.StructInNestedNS.prototype.mutate_b = function(value) {
|
||||||
var offset = this.bb.__offset(this.bb_pos, 4);
|
this.bb.writeInt32(this.bb_pos + 4, value);
|
||||||
|
|
||||||
if (offset === 0) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
this.bb.writeInt32(this.bb_pos + offset, value);
|
|
||||||
return true;
|
return true;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -170,13 +170,7 @@ a():number {
|
|||||||
* @returns boolean
|
* @returns boolean
|
||||||
*/
|
*/
|
||||||
mutate_a(value:number):boolean {
|
mutate_a(value:number):boolean {
|
||||||
var offset = this.bb!.__offset(this.bb_pos, 0);
|
this.bb!.writeInt32(this.bb_pos + 0, value);
|
||||||
|
|
||||||
if (offset === 0) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
this.bb!.writeInt32(this.bb_pos + offset, value);
|
|
||||||
return true;
|
return true;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -192,13 +186,7 @@ b():number {
|
|||||||
* @returns boolean
|
* @returns boolean
|
||||||
*/
|
*/
|
||||||
mutate_b(value:number):boolean {
|
mutate_b(value:number):boolean {
|
||||||
var offset = this.bb!.__offset(this.bb_pos, 4);
|
this.bb!.writeInt32(this.bb_pos + 4, value);
|
||||||
|
|
||||||
if (offset === 0) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
this.bb!.writeInt32(this.bb_pos + offset, value);
|
|
||||||
return true;
|
return true;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -167,13 +167,7 @@ Rapunzel.prototype.hairLength = function() {
|
|||||||
* @returns {boolean}
|
* @returns {boolean}
|
||||||
*/
|
*/
|
||||||
Rapunzel.prototype.mutate_hair_length = function(value) {
|
Rapunzel.prototype.mutate_hair_length = function(value) {
|
||||||
var offset = this.bb.__offset(this.bb_pos, 0);
|
this.bb.writeInt32(this.bb_pos + 0, value);
|
||||||
|
|
||||||
if (offset === 0) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
this.bb.writeInt32(this.bb_pos + offset, value);
|
|
||||||
return true;
|
return true;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -226,13 +220,7 @@ BookReader.prototype.booksRead = function() {
|
|||||||
* @returns {boolean}
|
* @returns {boolean}
|
||||||
*/
|
*/
|
||||||
BookReader.prototype.mutate_books_read = function(value) {
|
BookReader.prototype.mutate_books_read = function(value) {
|
||||||
var offset = this.bb.__offset(this.bb_pos, 0);
|
this.bb.writeInt32(this.bb_pos + 0, value);
|
||||||
|
|
||||||
if (offset === 0) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
this.bb.writeInt32(this.bb_pos + offset, value);
|
|
||||||
return true;
|
return true;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -202,13 +202,7 @@ hairLength():number {
|
|||||||
* @returns boolean
|
* @returns boolean
|
||||||
*/
|
*/
|
||||||
mutate_hair_length(value:number):boolean {
|
mutate_hair_length(value:number):boolean {
|
||||||
var offset = this.bb!.__offset(this.bb_pos, 0);
|
this.bb!.writeInt32(this.bb_pos + 0, value);
|
||||||
|
|
||||||
if (offset === 0) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
this.bb!.writeInt32(this.bb_pos + offset, value);
|
|
||||||
return true;
|
return true;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -290,13 +284,7 @@ booksRead():number {
|
|||||||
* @returns boolean
|
* @returns boolean
|
||||||
*/
|
*/
|
||||||
mutate_books_read(value:number):boolean {
|
mutate_books_read(value:number):boolean {
|
||||||
var offset = this.bb!.__offset(this.bb_pos, 0);
|
this.bb!.writeInt32(this.bb_pos + 0, value);
|
||||||
|
|
||||||
if (offset === 0) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
this.bb!.writeInt32(this.bb_pos + offset, value);
|
|
||||||
return true;
|
return true;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user