mirror of
https://github.com/asphyxia-core/core.git
synced 2026-12-04 22:49:12 -06:00
Merge pull request #2 from asphyxia-core/dannylin0711-patch-1
Update KBinJSON.ts
This commit is contained in:
@@ -505,6 +505,16 @@ function nodeToBinary(
|
||||
binaryType = 'u8';
|
||||
}
|
||||
|
||||
// Normalize missing or malformed content so kencode doesn't crash.
|
||||
if (value === null || value === undefined) {
|
||||
// If node is flagged as array (via __count), default to an empty array.
|
||||
// Otherwise default to a single zero value for numeric types.
|
||||
value = isArray ? [] : [0];
|
||||
} else if (!Array.isArray(value)) {
|
||||
// Ensure numeric/binary values are arrays for the writer APIs.
|
||||
value = [value as number | bigint];
|
||||
}
|
||||
|
||||
if (isArray) {
|
||||
dataBuf.writeArray(binaryType as BinaryLengthType, value as (number | bigint)[]);
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user