Created
November 20, 2022 18:48
-
-
Save yakovenkodenis/c6b36af4bf51aa9bfe1c4fc4bf7e75f0 to your computer and use it in GitHub Desktop.
frame first byte
This file contains hidden or 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
| parseFrame(buffer) { | |
| const firstByte = buffer.readUInt8(0); | |
| const opCode = firstByte & 0b00001111; // get last 4 bits of a byte | |
| if (opCode === this.OPCODES.close) { | |
| this.emit('close'); | |
| return null; | |
| } else if (opCode !== this.OPCODES.text) { | |
| return; | |
| } | |
| // second byte processing next... | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment