private void processFragments(WsFrame first) { bool compressed = first.IsCompressed; if (compressed && _perFrameCompress) first.Decompress(_compression); var buffer = new List<byte>(first.PayloadData.ToByteArray()); Func<WsFrame, bool> processContinuation = contFrame => { if (!contFrame.IsContinuation) return false; if (contFrame.IsCompressed) contFrame.Decompress(_compression); buffer.AddRange(contFrame.PayloadData.ToByteArray()); return true; }; while (true) { var frame = readFrame(); if (processAbnormal(frame)) return; if (!frame.IsFinal) { // MORE & CONT if (processContinuation(frame)) continue; } else { // FINAL & CONT if (processContinuation(frame)) break; // FINAL & PING if (processPing(frame)) continue; // FINAL & PONG if (processPong(frame)) continue; // FINAL & CLOSE if (processClose(frame)) return; } // ? processIncorrectFrame(); return; } var data = compressed && !_perFrameCompress ? buffer.ToArray().Decompress(_compression) : buffer.ToArray(); onMessage(new MessageEventArgs(first.Opcode, new PayloadData(data))); }
private bool processData(WsFrame frame) { if (!frame.IsData) return false; if (frame.IsCompressed && _compression == CompressionMethod.NONE) return false; if (frame.IsCompressed) frame.Decompress(_compression); onMessage(new MessageEventArgs(frame.Opcode, frame.PayloadData)); return true; }