flatbuffers
flatbuffers copied to clipboard
[TS] fix incorrect reverse order when writting array of structs
When writting array of structs to flatbuffer in TS, structs will be written in reverse order.
Example code:
struct Vec3 {
x: float;
y: float;
z: float;
}
table Pos {
vecs: [Vec3];
}
import { Pos, PosT } from './pos'
import { Vec3T } from './vec3'
import * as flatbuffers from 'flatbuffers'
let origin = new PosT();
origin.vecs = [
new Vec3T(1, 2, 3),
new Vec3T(4, 5, 6)
];
console.log('origin:', origin);
let builder = new flatbuffers.Builder();
builder.finish(origin.pack(builder));
let decoded = Pos.getRootAsPos(builder.dataBuffer()).unpack();
console.log('decoded:', decoded);
Will output:
origin: PosT {
vecs: [ Vec3T { x: 1, y: 2, z: 3 }, Vec3T { x: 4, y: 5, z: 6 } ]
}
decoded: PosT {
vecs: [ Vec3T { x: 4, y: 5, z: 6 }, Vec3T { x: 1, y: 2, z: 3 } ]
}
Because createObjectOffsetList
writes data in reverse order, and many generated codes depend on it. So we need to reverse createStructOffsetList
’s input to make the structs order correct.
@dbaileychess @bjornharrtell
Sorry for the delay. Can we get a test for it?
Sorry for the delay. Can we get a test for it?
Ok, I will add a test later.
Sorry for the delay. Can we get a test for it?
Done. 😄
Sorry for the delay! Thanks.