Add pair to/fromJson (#123)

This commit is contained in:
Jaco Greeff
2018-05-08 12:46:04 +02:00
committed by GitHub
parent 46706bc950
commit f8e07bada9
26 changed files with 282 additions and 161 deletions
+6 -2
View File
@@ -16,7 +16,7 @@
u8aFixLength('0x12', 16) // => 0x0012
u8aFixLength('0x1234', 8) // => 0x12
*/
module.exports = function u8aFixLength (value: Uint8Array, bitLength: number = -1): Uint8Array {
module.exports = function u8aFixLength (value: Uint8Array, bitLength: number = -1, atStart?: boolean = false): Uint8Array {
const byteLength = Math.ceil(bitLength / 8);
if (bitLength === -1 || value.length === byteLength) {
@@ -29,7 +29,11 @@ module.exports = function u8aFixLength (value: Uint8Array, bitLength: number = -
const result = new Uint8Array(byteLength);
result.set(value, byteLength - value.length);
if (atStart) {
result.set(value, 0);
} else {
result.set(value, byteLength - value.length);
}
return result;
};