Exemplo n.º 1
0
        /// <summary>
        /// Un mask the payload.
        /// </summary>
        public void Unmask()
        {
            if (_mask == Mask.Unmask)
            {
                return;
            }

            _mask = Mask.Unmask;
            _payloadData.Mask(_maskingKey);
            _maskingKey = new byte[0];
        }
Exemplo n.º 2
0
        /// <summary>
        /// Web socket frame structure.
        /// </summary>
        /// <param name="fin">The state of the data.</param>
        /// <param name="opcode">Represents the frame type of the WebSocket frame as defined in section 11.8 of the WebSocket protocol spec.</param>
        /// <param name="payloadData">The payload.</param>
        /// <param name="compressed">True to compress the data.</param>
        /// <param name="mask">True if masked.</param>
        public Frame(Fin fin, OpCodeFrame opcode, Payload payloadData, bool compressed, bool mask)
        {
            _fin    = fin;
            _rsv1   = IsDataEx(opcode) && compressed ? Rsv.On : Rsv.Off;
            _rsv2   = Rsv.Off;
            _rsv3   = Rsv.Off;
            _opcode = opcode;

            var len = payloadData.Length;

            if (len < 126)
            {
                _payloadLength    = (byte)len;
                _extPayloadLength = new byte[0];
            }
            else if (len < 0x010000)
            {
                _payloadLength    = (byte)126;
                _extPayloadLength = ((ushort)len).InternalToByteArray(Nequeo.Custom.ByteOrder.Big);
            }
            else
            {
                _payloadLength    = (byte)127;
                _extPayloadLength = len.InternalToByteArray(Nequeo.Custom.ByteOrder.Big);
            }

            if (mask)
            {
                _mask       = Mask.Mask;
                _maskingKey = CreateMaskingKey();
                payloadData.Mask(_maskingKey);
            }
            else
            {
                _mask       = Mask.Unmask;
                _maskingKey = new byte[0];
            }

            _payloadData = payloadData;
        }