fix(core): serialize longs from port to worker (part 2)

This commit is contained in:
alina 🌸 2024-07-17 20:46:35 +03:00
parent 69eda9decb
commit 56e928197d
Signed by: teidesu
SSH key fingerprint: SHA256:uNeCpw6aTSU4aIObXLvHfLkDa82HWH9EiOj9AXOIRpI

View file

@ -76,20 +76,26 @@ export function serializeResult<T>(result: T): SerializedResult<T> {
if (result && typeof result === 'object') {
// replace Long instances with a special object
const newResult: Record<string, unknown> = {}
for (const [key, value] of Object.entries(result)) {
if (Long.isLong(value)) {
// eslint-disable-next-line
;(result as any)[key] = {
newResult[key] = {
__type: 'long',
low: value.low,
high: value.high,
unsigned: value.unsigned,
}
} else {
} else if (typeof value === 'object') {
// eslint-disable-next-line
;(result as any)[key] = serializeResult(value)
newResult[key] = serializeResult(value)
} else {
newResult[key] = value
}
}
return newResult as unknown as SerializedResult<T>
}
return result as unknown as SerializedResult<T>
@ -114,7 +120,7 @@ export function deserializeResult<T>(result: SerializedResult<T>): T {
if (value && typeof value === 'object' && (value as Record<string, string>).__type === 'long') {
// eslint-disable-next-line
;(result as any)[key] = Long.fromValue(value as unknown as Long)
} else {
} else if (typeof value === 'object') {
// eslint-disable-next-line
;(result as any)[key] = deserializeResult(value as SerializedResult<unknown>)
}