@defichain/jellyfish-buffer
Advanced tools
Comparing version 0.52.0 to 0.54.0
@@ -53,2 +53,14 @@ import BigNumber from 'bignumber.js'; | ||
/** | ||
* The length of the array is set with VarUInt in the first sequence of 1 - 9 bytes. | ||
* Mainly created to handle array of primitive type as varUIntArray<T> always expect data to be object. | ||
* | ||
* @param arrayGetter to read array of ComposableBuffer Object from to buffer | ||
* @param arraySetter to set array of ComposableBuffer Object from buffer | ||
* @param writeBuffer to write single data into SmartBuffer | ||
* @param readBuffer to read single data from SmartBuffer | ||
* | ||
* @see array if length is not given but known | ||
*/ | ||
static varUIntArrayRaw<T>(arrayGetter: () => T[], arraySetter: (data: T[]) => void, writeBuffer: (data: T, buffer: SmartBuffer) => void, readBuffer: (buffer: SmartBuffer) => T): BufferComposer; | ||
/** | ||
* The length of the array must be known and given to the composer, use varUIntArray if length is set as VarUInt. | ||
@@ -55,0 +67,0 @@ * |
@@ -100,2 +100,30 @@ "use strict"; | ||
/** | ||
* The length of the array is set with VarUInt in the first sequence of 1 - 9 bytes. | ||
* Mainly created to handle array of primitive type as varUIntArray<T> always expect data to be object. | ||
* | ||
* @param arrayGetter to read array of ComposableBuffer Object from to buffer | ||
* @param arraySetter to set array of ComposableBuffer Object from buffer | ||
* @param writeBuffer to write single data into SmartBuffer | ||
* @param readBuffer to read single data from SmartBuffer | ||
* | ||
* @see array if length is not given but known | ||
*/ | ||
static varUIntArrayRaw(arrayGetter, arraySetter, writeBuffer, readBuffer) { | ||
return { | ||
fromBuffer: (buffer) => { | ||
const length = varuint_1.readVarUInt(buffer); | ||
const array = []; | ||
for (let i = 0; i < length; i++) { | ||
array.push(readBuffer(buffer)); | ||
} | ||
arraySetter(array); | ||
}, | ||
toBuffer: (buffer) => { | ||
const array = arrayGetter(); | ||
varuint_1.writeVarUInt(array.length, buffer); | ||
array.forEach(data => writeBuffer(data, buffer)); | ||
} | ||
}; | ||
} | ||
/** | ||
* The length of the array must be known and given to the composer, use varUIntArray if length is set as VarUInt. | ||
@@ -102,0 +130,0 @@ * |
{ | ||
"private": false, | ||
"name": "@defichain/jellyfish-buffer", | ||
"version": "0.52.0", | ||
"version": "0.54.0", | ||
"description": "A collection of TypeScript + JavaScript tools and libraries for DeFi Blockchain developers to build decentralized finance for Bitcoin", | ||
@@ -29,4 +29,4 @@ "keywords": [ | ||
"peerDependencies": { | ||
"defichain": "0.52.0" | ||
"defichain": "0.54.0" | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
64055
1030