@iov/encoding
Advanced tools
Comparing version 0.17.8 to 1.0.0-alpha.0
@@ -39,3 +39,3 @@ "use strict"; | ||
// on SIGNED int32 in JavaScript and we don't want to risk surprises | ||
return [ | ||
return new Uint8Array([ | ||
Math.floor(this.data / Math.pow(2, 24)) & 0xff, | ||
@@ -45,4 +45,14 @@ Math.floor(this.data / Math.pow(2, 16)) & 0xff, | ||
Math.floor(this.data / Math.pow(2, 0)) & 0xff, | ||
]; | ||
]); | ||
} | ||
toBytesLittleEndian() { | ||
// Use division instead of shifting since bitwise operators are defined | ||
// on SIGNED int32 in JavaScript and we don't want to risk surprises | ||
return new Uint8Array([ | ||
Math.floor(this.data / Math.pow(2, 0)) & 0xff, | ||
Math.floor(this.data / Math.pow(2, 8)) & 0xff, | ||
Math.floor(this.data / Math.pow(2, 16)) & 0xff, | ||
Math.floor(this.data / Math.pow(2, 24)) & 0xff, | ||
]); | ||
} | ||
toNumber() { | ||
@@ -151,6 +161,6 @@ return this.data; | ||
toBytesBigEndian() { | ||
return this.data.toArray("be", 8); | ||
return this.data.toArrayLike(Uint8Array, "be", 8); | ||
} | ||
toBytesLittleEndian() { | ||
return this.data.toArray("le", 8); | ||
return this.data.toArrayLike(Uint8Array, "le", 8); | ||
} | ||
@@ -157,0 +167,0 @@ toString() { |
{ | ||
"name": "@iov/encoding", | ||
"version": "0.17.8", | ||
"version": "1.0.0-alpha.0", | ||
"description": "Encoding helpers for IOV projects", | ||
@@ -48,3 +48,3 @@ "author": "IOV SAS <admin@iov.one>", | ||
}, | ||
"gitHead": "722c7ed3539806384a1b02c6d6777aadd9eeb6b4" | ||
"gitHead": "8f11360f00cd3069f46ef5109e20d5c17e05a3e1" | ||
} |
@@ -0,1 +1,2 @@ | ||
/** Internal interface to ensure all integer types can be used equally */ | ||
interface Integer { | ||
@@ -5,7 +6,12 @@ readonly toNumber: () => number; | ||
} | ||
export declare class Uint32 implements Integer { | ||
interface WithByteConverters { | ||
readonly toBytesBigEndian: () => Uint8Array; | ||
readonly toBytesLittleEndian: () => Uint8Array; | ||
} | ||
export declare class Uint32 implements Integer, WithByteConverters { | ||
static fromBigEndianBytes(bytes: ArrayLike<number>): Uint32; | ||
protected readonly data: number; | ||
constructor(input: number); | ||
toBytesBigEndian(): readonly number[]; | ||
toBytesBigEndian(): Uint8Array; | ||
toBytesLittleEndian(): Uint8Array; | ||
toNumber(): number; | ||
@@ -28,3 +34,3 @@ toString(): string; | ||
} | ||
export declare class Uint64 implements Integer { | ||
export declare class Uint64 implements Integer, WithByteConverters { | ||
static fromBytesBigEndian(bytes: ArrayLike<number>): Uint64; | ||
@@ -35,4 +41,4 @@ static fromString(str: string): Uint64; | ||
private constructor(); | ||
toBytesBigEndian(): readonly number[]; | ||
toBytesLittleEndian(): readonly number[]; | ||
toBytesBigEndian(): Uint8Array; | ||
toBytesLittleEndian(): Uint8Array; | ||
toString(): string; | ||
@@ -39,0 +45,0 @@ toNumber(): number; |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
61782
798