Skip to content

toObject with large long type is returning a wrong value #690

@yoni-tock

Description

@yoni-tock

protobuf.js version: 6.6.3

Calling .toObject with the Number option for longs is returning a value that's incorrect, at least for very large Longs (in our case, an epoch). Strangely, the result is different than calling toNumber on the specific field. Calling proto.toObject({ longs: Number }) is resulting in a different value than proto.longValue.toNumber().

The relevant shape of the object is:

const proto = {
  innerProto: {
    timestampMs: {
      low: -2114947712,
      high: 346,
      unsigned: true,
    },
  },
};

// Calling toObject we get the following
const converted = proto.toObject({ longs: Number });
console.log(converted.innerProto.timestampMs); // 1483943736704
// vesus...
console.log(proto.innerProto.timestampMs.toNumber()); // 1488238704000

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