(
segment: string | ArrayBuffer,
appendMissingNULLonIncoming: boolean = false,
)
| 81 | } |
| 82 | |
| 83 | public parseChunk( |
| 84 | segment: string | ArrayBuffer, |
| 85 | appendMissingNULLonIncoming: boolean = false, |
| 86 | ) { |
| 87 | let chunk: Uint8Array; |
| 88 | |
| 89 | if (typeof segment === 'string') { |
| 90 | chunk = this._encoder.encode(segment); |
| 91 | } else { |
| 92 | chunk = new Uint8Array(segment); |
| 93 | } |
| 94 | |
| 95 | // See https://github.com/stomp-js/stompjs/issues/89 |
| 96 | // Remove when underlying issue is fixed. |
| 97 | // |
| 98 | // Send a NULL byte, if the last byte of a Text frame was not NULL.F |
| 99 | if (appendMissingNULLonIncoming && chunk[chunk.length - 1] !== 0) { |
| 100 | const chunkWithNull = new Uint8Array(chunk.length + 1); |
| 101 | chunkWithNull.set(chunk, 0); |
| 102 | chunkWithNull[chunk.length] = 0; |
| 103 | chunk = chunkWithNull; |
| 104 | } |
| 105 | |
| 106 | // tslint:disable-next-line:prefer-for-of |
| 107 | for (let i = 0; i < chunk.length; i++) { |
| 108 | const byte = chunk[i]; |
| 109 | this._onByte(byte); |
| 110 | } |
| 111 | } |
| 112 | |
| 113 | // The following implements a simple Rec Descent Parser. |
| 114 | // The grammar is simple and just one byte tells what should be the next state |
no outgoing calls