fix(core): serialize longs from port to worker (part 2)
This commit is contained in:
parent
69eda9decb
commit
56e928197d
1 changed files with 10 additions and 4 deletions
|
@ -76,20 +76,26 @@ export function serializeResult<T>(result: T): SerializedResult<T> {
|
||||||
|
|
||||||
if (result && typeof result === 'object') {
|
if (result && typeof result === 'object') {
|
||||||
// replace Long instances with a special object
|
// replace Long instances with a special object
|
||||||
|
const newResult: Record<string, unknown> = {}
|
||||||
|
|
||||||
for (const [key, value] of Object.entries(result)) {
|
for (const [key, value] of Object.entries(result)) {
|
||||||
if (Long.isLong(value)) {
|
if (Long.isLong(value)) {
|
||||||
// eslint-disable-next-line
|
// eslint-disable-next-line
|
||||||
;(result as any)[key] = {
|
newResult[key] = {
|
||||||
__type: 'long',
|
__type: 'long',
|
||||||
low: value.low,
|
low: value.low,
|
||||||
high: value.high,
|
high: value.high,
|
||||||
unsigned: value.unsigned,
|
unsigned: value.unsigned,
|
||||||
}
|
}
|
||||||
} else {
|
} else if (typeof value === 'object') {
|
||||||
// eslint-disable-next-line
|
// 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>
|
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') {
|
if (value && typeof value === 'object' && (value as Record<string, string>).__type === 'long') {
|
||||||
// eslint-disable-next-line
|
// eslint-disable-next-line
|
||||||
;(result as any)[key] = Long.fromValue(value as unknown as Long)
|
;(result as any)[key] = Long.fromValue(value as unknown as Long)
|
||||||
} else {
|
} else if (typeof value === 'object') {
|
||||||
// eslint-disable-next-line
|
// eslint-disable-next-line
|
||||||
;(result as any)[key] = deserializeResult(value as SerializedResult<unknown>)
|
;(result as any)[key] = deserializeResult(value as SerializedResult<unknown>)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue