Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
writeMessage(messageIndex, xvizMessage) {
this._checkValid();
this._saveTimestamp(xvizMessage, messageIndex);
if (this.options.envelope) {
xvizMessage = XVIZEnvelope.StateUpdate(xvizMessage);
}
// Limit precision to save space
const numberRounder = (k, value) => {
if (typeof value === 'number') {
return Number(value.toFixed(this.options.precision));
}
return value;
};
const jsonXVIZMessage = xvizConvertJson(xvizMessage);
const msg = JSON.stringify(jsonXVIZMessage, numberRounder);
this.writeToSink(`${messageName(messageIndex)}.json`, msg);
}
async xvizMessage(iterator) {
const {
valid,
data: {start, end}
} = iterator.next();
if (!valid) {
return null;
}
const dataset = await this.bag.readMessages(start, end);
const msg = await this.ros2xviz.buildMessage(dataset);
if (msg) {
return new XVIZData(XVIZEnvelope.StateUpdate(msg));
}
return null;
}
}
writeMessage(messageIndex, xvizMessage) {
this._checkValid();
this._saveTimestamp(xvizMessage, messageIndex);
if (this.options.envelope) {
xvizMessage = XVIZEnvelope.StateUpdate(xvizMessage);
}
const glbFileBuffer = encodeBinaryXVIZ(xvizMessage, this.encodingOptions);
this.sink.writeSync(`${messageName(messageIndex)}.glb`, toBuffer(glbFileBuffer), {flag: 'w'});
}
writeFrame(xvizDirectory, frameIndex, xvizFrame) {
if (this.wroteFrameIndex !== null) {
throw new Error(
`writeFrame() was called after writeFrameIndex(). The index was written with last frame of ${frameName(
this.wroteFrameIndex - 1
)}`
);
}
this._saveTimestamp(xvizFrame, frameIndex);
if (this.options.envelope) {
xvizFrame = XVIZEnvelope.StateUpdate(xvizFrame);
}
if (this.options.binary) {
const options = {
flattenArrays: true
};
if (this.options.DracoWriter) {
options.DracoWriter = this.options.DracoWriter;
}
if (this.options.DracoLoader) {
options.DracoLoader = this.options.DracoLoader;
}
writeBinaryXVIZtoFile(this.sink, xvizDirectory, frameName(frameIndex), xvizFrame, options);
}