Skip to content

problem when use Float32Array in object's property #76

@shinyoshiaki

Description

@shinyoshiaki

Problem

Problem happen when use Float32Array in object's property.

indicate minimum jest test below

import { encode, decode } from "@msgpack/msgpack";

test("issue", () => {
  const f32 = new Float32Array([1.1, 1.2, 1.3]);
  const uint8 = new Uint8Array(f32.buffer);
  expect(new Float32Array(uint8.buffer)).toEqual(f32); //success

  const data = encode({ audio: uint8 });
  const { audio } = decode(data) as { audio: Uint8Array };

  expect(uint8).toEqual(audio); //success

  expect(uint8.buffer).toEqual(audio.buffer); //success

  const fail = new Float32Array(audio.buffer);
  expect(fail).toEqual(f32); //fail

  const success = new Float32Array(new Uint8Array(Object.values(audio)).buffer);
  expect(success).toEqual(f32); //success
});

this test fail in

 const fail = new Float32Array(audio.buffer);
 expect(fail).toEqual(f32); //fail

Enviroment

Node.js : 11.15.0
TypeScript : 3.5.2
Test Framework : Jest

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions