private string getReasonFrom(PayloadData data) { if (data.Length <= 2) { return(String.Empty); } var buffer = data.ToByteArray().SubArray(2, (int)(data.Length - 2)); return(Encoding.UTF8.GetString(buffer)); }
public async Task <byte[]> ToByteArray() { using (var buff = new MemoryStream()) { var header = (int)_fin; header = (header << 1) + (int)_rsv1; header = (header << 1) + (int)_rsv2; header = (header << 1) + (int)_rsv3; header = (header << 4) + (int)_opcode; header = (header << 1) + (int)_mask; header = (header << 7) + _payloadLength; await buff.WriteAsync(((ushort)header).InternalToByteArray(ByteOrder.Big), 0, 2).ConfigureAwait(false); if (_payloadLength > 125) { await buff.WriteAsync(_extPayloadLength, 0, _extPayloadLength.Length).ConfigureAwait(false); } if (_mask == Mask.Mask) { await buff.WriteAsync(_maskingKey, 0, _maskingKey.Length).ConfigureAwait(false); } if (_payloadLength > 0) { var payload = _payloadData.ToByteArray(); if (_payloadLength < 127) { await buff.WriteAsync(payload, 0, payload.Length).ConfigureAwait(false); } else { await buff.WriteBytes(payload).ConfigureAwait(false); } } buff.Close(); return(buff.ToArray()); } }
public byte[] ToByteArray() { using (var buff = new MemoryStream()) { var header = (int)_fin; header = (header << 1) + (int)_rsv1; header = (header << 1) + (int)_rsv2; header = (header << 1) + (int)_rsv3; header = (header << 4) + (int)_opcode; header = (header << 1) + (int)_mask; header = (header << 7) + (int)_payloadLength; buff.Write(((ushort)header).InternalToByteArray(ByteOrder.Big), 0, 2); if (_payloadLength > 125) { buff.Write(_extPayloadLength, 0, _extPayloadLength.Length); } if (_mask == Mask.Mask) { buff.Write(_maskingKey, 0, _maskingKey.Length); } if (_payloadLength > 0) { var payload = _payloadData.ToByteArray(); if (_payloadLength < 127) { buff.Write(payload, 0, payload.Length); } else { buff.WriteBytes(payload); } } buff.Close(); return(buff.ToArray()); } }
public byte[] ToByteArray() { //Discarded unreachable code: IL_00f0 using (MemoryStream memoryStream = new MemoryStream()) { int fin = (int)_fin; fin = (fin << 1) + (int)_rsv1; fin = (fin << 1) + (int)_rsv2; fin = (fin << 1) + (int)_rsv3; fin = (fin << 4) + (int)_opcode; fin = (fin << 1) + (int)_mask; fin = (fin << 7) + _payloadLength; memoryStream.Write(((ushort)fin).InternalToByteArray(ByteOrder.Big), 0, 2); if (_payloadLength > 125) { memoryStream.Write(_extPayloadLength, 0, _extPayloadLength.Length); } if (_mask == Mask.Mask) { memoryStream.Write(_maskingKey, 0, _maskingKey.Length); } if (_payloadLength > 0) { byte[] array = _payloadData.ToByteArray(); if (_payloadLength < 127) { memoryStream.Write(array, 0, array.Length); } else { memoryStream.WriteBytes(array); } } memoryStream.Close(); return(memoryStream.ToArray()); } }
private ushort getCodeFrom(PayloadData data) { return(data.Length >= 2 ? data.ToByteArray().SubArray(0, 2).To <ushort>(ByteOrder.BIG) : (ushort)CloseStatusCode.NO_STATUS_CODE); }