Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
tape('XVIZFormatWriter#full matrix', t => {
const dataSources = [
TestXVIZSnapshot,
TestXVIZSnapshotString,
TestXVIZSnapshotBuffer,
TestXVIZSnapshotGLB
];
for (const source of dataSources) {
const xvizObj = new XVIZData(source);
for (const format of [
XVIZ_FORMAT.BINARY_GLB,
XVIZ_FORMAT.JSON_BUFFER,
XVIZ_FORMAT.JSON_STRING
]) {
const sink = new MemorySourceSink();
t.comment(`-- TestCase ${xvizObj.format} to ${format}`);
// Convert the data to the requested format
// data is state_update and this will default to a message sequence of 0
const formatWriter = new XVIZFormatWriter(sink, {format});
formatWriter.writeMessage(0, xvizObj);
// We don't really care about the key as each writer will have
async xvizFrame(iterator) {
const {
valid,
data: {start, end}
} = iterator.next();
if (!valid) {
return null;
}
// Read Frame by keyTopic/stream
const frame = await this.bag.readFrameByTime(start, end);
return new XVIZData(frame);
}
}
middlewareDispatch(name, msg) {
const arrayLength = this.middlewares.length;
for (let i = 0; i < arrayLength; i++) {
const middleware = this.middlewares[i];
const handler = middleware[name];
if (handler) {
let args = [];
// Support JS objects
if (msg && !(msg instanceof XVIZData)) {
msg = new XVIZData(msg);
}
args = [msg];
const nextMiddleware = handler.apply(middleware, args);
if (nextMiddleware === false) {
break;
}
}
}
}
}
{
description: 'Binary Metadata',
data: MinimalBinaryMetadata,
format: XVIZ_FORMAT.BINARY_GLB,
type: 'metadata'
},
{
description: 'Binary StateUpdate',
data: MinimalBinaryStateUpdate,
format: XVIZ_FORMAT.BINARY_GLB,
type: 'state_update'
}
];
for (const test of testCases) {
const xvizObj = new XVIZData(test.data);
t.equal(
xvizObj.format,
test.format,
`${test.description} matches expected format ${test.format}`
);
t.equal(xvizObj.type, test.type, `${test.description} matches expected type ${test.type}`);
const msg = xvizObj.message();
t.equal(msg.type, test.type, `${test.description} matches expected message type ${test.type}`);
}
t.end();
});
_readMessage(message) {
const data = this.reader.readMessage(message);
if (data) {
return new XVIZData(data);
}
return undefined;
}
_readMetadata() {
const data = this.reader.readMetadata();
if (data) {
return new XVIZData(data);
}
return undefined;
}
}
xvizMetadata() {
return new XVIZData(this.metadata);
}
xvizMetadata() {
if (!this.metadata) {
this._getMetadata();
}
if (this.metadata) {
return new XVIZData(this.metadata);
}
return null;
}