Add pair to/fromJson (#123)
This commit is contained in:
@@ -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;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user