How to use the @xviz/io.XVIZ_FORMAT.BINARY_GLB function in @xviz/io

To help you get started, we’ve selected a few @xviz/io examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github uber / xviz / test / modules / io / writers / xviz-format-writer.spec.js View on Github external
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
      // different identifier, (eg: 1-frame.json vs 1.frame.glb)
      for (const [key, val] of sink.entries()) {
        // Cover Arrays, Strings, ArrayBuffers
github uber / xviz / modules / server / src / middlewares / xviz-websocket-sender.js View on Github external
_getFormatOptions(msg) {
    // default should be pass-thru of original data
    if (!this.format) {
      // If no format is specified, we send the 'natural' format
      // but it must be a string or arraybuffer, not an OBJECT

      // Test to determine if msg is either string or arraybuffer
      if (
        msg.format === XVIZ_FORMAT.OBJECT ||
        (!msg.hasMessage() && typeof msg.buffer !== 'string' && !msg.buffer.byteLength)
      ) {
        return XVIZ_FORMAT.BINARY_GLB;
      }

      // return the format set to the current data format
      return msg.format;
    }

    return this.format;
  }
github uber / xviz / modules / server / src / middlewares / xviz-websocket-sender.js View on Github external
this.socket = socket;
    this.sink = new WebsocketSink(socket, options);

    // TODO: options register:
    // - compress
    // - formatter

    this.options = options;

    // This is the actual format we use to send data and can change
    // based on the message.
    this.format = options.format;

    if (this.format === XVIZ_FORMAT.OBJECT) {
      // We can not output OBJECT on a websocket
      this.format = XVIZ_FORMAT.BINARY_GLB;
    }

    this.writer = null;
    // If format is undefined we want to send the 'natural' format of
    // the data (as long as it's not an OBJECT).
    // Keep track of current 'writer' format
    this.writerFormat = null;

    this._syncFormatWithWriter(this.format);
  }
github uber / xviz / test / modules / io / writers / xviz-format-writer.spec.js View on Github external
tape('XVIZFormatWriter#message writing', t => {
  const xvizObj = new XVIZData(TestXVIZSnapshot);
  const sink = new MemorySourceSink();

  const formatWriter = new XVIZFormatWriter(sink, {format: XVIZ_FORMAT.BINARY_GLB});

  formatWriter.writeMessage(0, xvizObj);
  formatWriter.writeMessage(1, xvizObj);
  formatWriter.writeMessage(2, xvizObj);

  const expectedKeys = ['2-frame.glb', '3-frame.glb', '4-frame.glb'];
  for (const key of expectedKeys) {
    t.ok(sink.has(key), `entry ${key} was present`);
  }

  t.not(sink.has('1-frame.glb'), 'entry 1-frame.glb was not present');

  t.end();
});
github uber / xviz / test / modules / io / common / xviz-data.spec.js View on Github external
format: XVIZ_FORMAT.JSON_STRING
  },
  {
    data: `   ${TestXVIZSnapshotString}   `,
    description: 'XVIZ String with whitespace head and tail',
    format: XVIZ_FORMAT.JSON_STRING
  },
  {
    data: TestXVIZSnapshotBuffer,
    description: 'XVIZ String Buffer',
    format: XVIZ_FORMAT.JSON_BUFFER
  },
  {
    data: TestXVIZSnapshotGLB,
    description: 'XVIZ Binary Buffer',
    format: XVIZ_FORMAT.BINARY_GLB
  },
  {
    data: Buffer.from(TestXVIZSnapshotBuffer),
    description: 'XVIZ String NodeBuffer',
    format: XVIZ_FORMAT.JSON_BUFFER,
    nodeOnly: true
  },
  {
    data: Buffer.from(TestXVIZSnapshotGLB),
    description: 'XVIZ Binary NodeBuffer',
    format: 'BINARY_GLB',
    nodeOnly: true
  }
];

tape('XVIZData#constructor', t => {
github uber / xviz / test / modules / io / common / xviz-data.spec.js View on Github external
tape('XVIZData#type', t => {
  const testCases = [
    {
      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}`