Skip to content

Commit f487b14

Browse files
committed
Change XYSeries xValues to bigint array
Store xValues as bigint to avoid lossy conversion to number. Signed-off-by: Patrick Tasse <patrick.tasse@ericsson.com>
1 parent 22bdc11 commit f487b14

File tree

3 files changed

+10
-4
lines changed

3 files changed

+10
-4
lines changed

tsp-typescript-client/src/models/xy.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import { array, assertNumber, createNormalizer } from '../protocol/serialization';
1+
import { array, assertNumber, createNormalizer, toBigInt } from '../protocol/serialization';
22

33
export const XYSeries = createNormalizer<XYSeries>({
44
seriesId: assertNumber,
5-
xValues: array(Number), // lossy conversion if too big
5+
xValues: array(toBigInt),
66
yValues: array(assertNumber),
77
tags: array(assertNumber),
88
});
@@ -34,7 +34,7 @@ export interface XYSeries {
3434
/**
3535
* Series' X values
3636
*/
37-
xValues: number[];
37+
xValues: bigint[];
3838

3939
/**
4040
* Series' Y values

tsp-typescript-client/src/protocol/serialization.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,3 +200,9 @@ export const assertNumber: Normalizer<number> =
200200
}
201201
return input;
202202
};
203+
204+
export const toBigInt: Normalizer<bigint> =
205+
function toBigInt(value: number | bigint): bigint {
206+
return BigInt(value);
207+
};
208+

tsp-typescript-client/src/protocol/tsp-client.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ describe('TspClient Deserialization', () => {
245245
expect(serie.xValues).toHaveLength(3);
246246
expect(serie.yValues).toHaveLength(3);
247247
for (const xValue of serie.xValues) {
248-
expect(typeof xValue).toEqual('number');
248+
expect(typeof xValue).toEqual('bigint');
249249
}
250250
for (const yValue of serie.yValues) {
251251
expect(typeof yValue).toEqual('number');

0 commit comments

Comments
 (0)