Document default endianess

This commit is contained in:
Simon Warta 2020-09-30 14:03:56 +02:00
parent 0f3ef46aa1
commit 5d73e64b17
2 changed files with 24 additions and 0 deletions

View File

@ -25,6 +25,12 @@ export class Uint32 implements Integer, WithByteConverters {
return Uint32.fromBytes(bytes);
}
/**
* Creates a Uint32 from a fixed length byte array.
*
* @param bytes a list of exactly 4 bytes
* @param endianess defaults to big endian
*/
public static fromBytes(bytes: ArrayLike<number>, endianess: "be" | "le" = "be"): Uint32 {
if (bytes.length !== 4) {
throw new Error("Invalid input length. Expected 4 bytes.");
@ -168,6 +174,12 @@ export class Uint64 implements Integer, WithByteConverters {
return Uint64.fromBytes(bytes);
}
/**
* Creates a Uint64 from a fixed length byte array.
*
* @param bytes a list of exactly 8 bytes
* @param endianess defaults to big endian
*/
public static fromBytes(bytes: ArrayLike<number>, endianess: "be" | "le" = "be"): Uint64 {
if (bytes.length !== 8) {
throw new Error("Invalid input length. Expected 8 bytes.");

View File

@ -10,6 +10,12 @@ interface WithByteConverters {
export declare class Uint32 implements Integer, WithByteConverters {
/** @deprecated use Uint32.fromBytes */
static fromBigEndianBytes(bytes: ArrayLike<number>): Uint32;
/**
* Creates a Uint32 from a fixed length byte array.
*
* @param bytes a list of exactly 4 bytes
* @param endianess defaults to big endian
*/
static fromBytes(bytes: ArrayLike<number>, endianess?: "be" | "le"): Uint32;
static fromString(str: string): Uint32;
protected readonly data: number;
@ -36,6 +42,12 @@ export declare class Uint53 implements Integer {
export declare class Uint64 implements Integer, WithByteConverters {
/** @deprecated use Uint64.fromBytes */
static fromBytesBigEndian(bytes: ArrayLike<number>): Uint64;
/**
* Creates a Uint64 from a fixed length byte array.
*
* @param bytes a list of exactly 8 bytes
* @param endianess defaults to big endian
*/
static fromBytes(bytes: ArrayLike<number>, endianess?: "be" | "le"): Uint64;
static fromString(str: string): Uint64;
static fromNumber(input: number): Uint64;