-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Updated an example and how endianness is handled.
- Loading branch information
Showing
7 changed files
with
34 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,4 @@ | ||
export { ISerialInput, ISerialOutput, IMeasurer } from './types'; | ||
export { Endianness, ISerialInput, ISerialOutput, IMeasurer } from './types'; | ||
export { BufferWriter } from './bufferWriter'; | ||
export { BufferReader } from './bufferReader'; | ||
export { Measurer } from './measurer'; | ||
export { isBigEndian } from '../util'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,13 @@ | ||
/** | ||
* @returns {Boolean} true if system is big endian | ||
*/ | ||
export function isBigEndian(): boolean { | ||
const array = new Uint8Array(4); | ||
const view = new Uint32Array(array.buffer); | ||
function isSystemBigEndian(): boolean { | ||
const array = new Uint8Array(4); | ||
const view = new Uint32Array(array.buffer); | ||
|
||
return !((view[0] = 1) & array[0]); | ||
} | ||
return !((view[0] = 1) & array[0]); | ||
} | ||
|
||
export function getSystemEndianness() { | ||
return isSystemBigEndian() ? 'big' : 'little'; | ||
} |