add warning for message type when ArrayBuffer is expected

This commit is contained in:
Kevin Jahns
2017-07-31 01:13:52 +02:00
parent f31ec9a8b8
commit aa6edcfd9b
3 changed files with 16 additions and 2 deletions

View File

@@ -66,7 +66,13 @@ export class BinaryEncoder {
export class BinaryDecoder {
constructor (buffer) {
this.uint8arr = new Uint8Array(buffer)
if (buffer instanceof ArrayBuffer) {
this.uint8arr = new Uint8Array(buffer)
} else if (buffer instanceof Uint8Array) {
this.uint8arr = buffer
} else {
throw new Error('Expected an ArrayBuffer or Uint8Array!')
}
this.pos = 0
}
skip8 () {