@iotize/tap
Version:
IoTize Device client for Javascript
27 lines (26 loc) • 891 B
TypeScript
import { EncoderDecoder } from '@iotize/common/converter/api';
export declare const BYTE_SWAP_ORDER_REGEX: RegExp;
export declare class ByteSwapConverter implements EncoderDecoder<Uint8Array, Uint8Array> {
order: string;
constructor(order: string);
encode(input: Uint8Array): Uint8Array;
decode(input: Uint8Array): Uint8Array;
}
/**
* Swap byte position
* B0 represents the first byte from the right
* BN represents the N byte from the right
*
* This function is symetric
*
* Example:
* ```typescript
* const input = Uint8Array.from([1,2,3,4]);
* expect(swapBytes(input, 'B2_B3_B0_B1')).to.be.deep.eq(Uint8Array.from([2,1,4,3]));
* ```
*
* @param input array
* @param order string that defined how to swap bytes
* @return a new array with byte swap
*/
export declare function swapBytes(input: Uint8Array, order: string): Uint8Array;