(payload)
| 64 | } |
| 65 | |
| 66 | function encodeFrameHybi17(payload) { |
| 67 | const dataLength = payload.length; |
| 68 | |
| 69 | let singleByteLength; |
| 70 | let additionalLength; |
| 71 | if (dataLength > kMaxTwoBytePayloadLength) { |
| 72 | singleByteLength = kEightBytePayloadLengthField; |
| 73 | additionalLength = Buffer.alloc(8); |
| 74 | let remaining = dataLength; |
| 75 | for (let i = 0; i < 8; ++i) { |
| 76 | additionalLength[7 - i] = remaining & 0xFF; |
| 77 | remaining >>= 8; |
| 78 | } |
| 79 | } else if (dataLength > kMaxSingleBytePayloadLength) { |
| 80 | singleByteLength = kTwoBytePayloadLengthField; |
| 81 | additionalLength = Buffer.alloc(2); |
| 82 | additionalLength[0] = (dataLength & 0xFF00) >> 8; |
| 83 | additionalLength[1] = dataLength & 0xFF; |
| 84 | } else { |
| 85 | additionalLength = new FastBuffer(); |
| 86 | singleByteLength = dataLength; |
| 87 | } |
| 88 | |
| 89 | const header = Buffer.from([ |
| 90 | kFinalBit | kOpCodeText, |
| 91 | kMaskBit | singleByteLength, |
| 92 | ]); |
| 93 | |
| 94 | const mask = Buffer.alloc(4); |
| 95 | const masked = Buffer.alloc(dataLength); |
| 96 | for (let i = 0; i < dataLength; ++i) { |
| 97 | masked[i] = payload[i] ^ mask[i % kMaskingKeyWidthInBytes]; |
| 98 | } |
| 99 | |
| 100 | return Buffer.concat([header, additionalLength, mask, masked]); |
| 101 | } |
| 102 | |
| 103 | function decodeFrameHybi17(data) { |
| 104 | const dataAvailable = data.length; |
no test coverage detected
searching dependent graphs…