BKSystem.IO.BitStream.ToByteArray C# (CSharp) Метод

ToByteArray() публичный Метод

Added [20051124].
public ToByteArray ( ) : byte[]
Результат byte[]
        public virtual byte[] ToByteArray()
        {
            // Write this stream's internal buffer to a new byte buffer
            long lCurrentPos = this.Position;
            this.Position = 0;

            byte [] abytBits = new byte [this.Length8];
            this.Read(abytBits, 0, (int)this.Length8);

            if(this.Position != lCurrentPos)
                this.Position = lCurrentPos;

            return abytBits;
        }

Usage Example

Пример #1
0
    public void TransmitStream(BKSystem.IO.BitStream data, int player)
    {
        if (m_clients[player] != null && m_clients[player].Connected)
        {
            // Pad the data by 1 bit ???
            data.Write(0);

            // Send how large the data is in the first 32 bits
            byte[] sendData   = data.ToByteArray();
            int    sendLength = IPAddress.HostToNetworkOrder(sendData.Length);
            byte[] lengthData = BitConverter.GetBytes(sendLength);

            // Choose the stream to use
            NetworkStream stream;

            stream = m_clients[player].GetStream();

            stream.Flush();

            stream.Write(lengthData, 0, lengthData.Length);
            //Debug.Log("Sending " + sendData.Length + " bytes to player " + player);

            // Then send the data
            stream.Write(sendData, 0, sendData.Length);
        }
        else
        {
            Debug.LogWarning("Attempting to transmit data while disconnected");
        }
    }
All Usage Examples Of BKSystem.IO.BitStream::ToByteArray