From e9b50ce6f1c47204cea503907aa24ad5b570287e Mon Sep 17 00:00:00 2001 From: Guillermo Rodriguez Date: Mon, 22 Apr 2024 18:48:38 -0300 Subject: [PATCH] Add bytes from Array to serializer & fix old proto spec comment --- package.json | 2 +- src/protocol.ts | 13 ++++++++----- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/package.json b/package.json index dda0724..f707a49 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@guilledk/arrowbatch-nodejs", - "version": "1.0.0-rc3", + "version": "1.0.0-rc4", "description": "Arrow Batch Storage protocol", "main": "./build/index.js", "type": "module", diff --git a/src/protocol.ts b/src/protocol.ts index 8f904c8..818307f 100644 --- a/src/protocol.ts +++ b/src/protocol.ts @@ -41,7 +41,7 @@ export class ArrowBatchProtocol { * * file map: * - * global header: version constant + batch size (uint64) + total batch count (uint64) + * global header: version constant * * batch #0 header: batch header constant + batch byte size (uint64) + compression (uint8) * arrow random access file bytes... @@ -256,10 +256,11 @@ const validationFunctions = { return false; }, - bytes: (value: any) => { + bytes: (value: any) => { return typeof value === 'string' || value instanceof Uint8Array || - value instanceof Buffer; + value instanceof Buffer || + (Array.isArray(value) && value.every(num => typeof num === 'number' && num >= 0 && num <= 255)); }, string: (value: any) => typeof value === 'string', checksum160: (value: any) => { @@ -329,9 +330,11 @@ const encodeFunctions = { value = value.substring(2); typedValue = Buffer.from(value, 'hex'); valByteLength /= 2; - - } else if (value instanceof Uint8Array) + } else if (value instanceof Uint8Array) { typedValue = Buffer.from(value); + } else if (Array.isArray(value)) { + typedValue = Buffer.from(value); + } if (fieldInfo.length && valByteLength != fieldInfo.length) throw new Error(