Skip to content

Commit

Permalink
Add bytes from Array<number> to serializer & fix old proto spec comment
Browse files Browse the repository at this point in the history
  • Loading branch information
guilledk committed Apr 22, 2024
1 parent bbd66ed commit e9b50ce
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
13 changes: 8 additions & 5 deletions src/protocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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...
Expand Down Expand Up @@ -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) => {
Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit e9b50ce

Please sign in to comment.