Lidgren.Network.NetBuffer.ReadByte C# (CSharp) Method

ReadByte() public method

Reads a byte and returns true or false for success
public ReadByte ( byte &result ) : bool
result byte
return bool
        public bool ReadByte(out byte result)
        {
            if (m_bitLength - m_readPosition < 8)
            {
                result = 0;
                return false;
            }
            result = NetBitWriter.ReadByte(m_data, 8, m_readPosition);
            m_readPosition += 8;
            return true;
        }

Same methods

NetBuffer::ReadByte ( ) : byte
NetBuffer::ReadByte ( int numberOfBits ) : byte

Usage Example

Ejemplo n.º 1
0
        private static void HandleMessage(NetMessageType type, NetConnection source, NetBuffer buffer)
        {
            switch (type)
            {
                case NetMessageType.DebugMessage:
                    WriteToConsole(buffer.ReadString());
                    break;
                case NetMessageType.StatusChanged:
                    WriteToConsole("New status: " + source.Status + " (" + buffer.ReadString() + ")");
                    UpdateStatisticsDisplay(source);
                    break;
                case NetMessageType.Data:
                    //System.IO.File.AppendAllText("C:\\receivedpackets.txt", s_userMessagesReceived.ToString() + ": " + msg.ReadString() + " (" + msg.m_sequenceNumber + ")" + Environment.NewLine);
                    s_userMessagesReceived++;

                    // simulate some processing of the message here
                    for (int i = 0; i < buffer.LengthBytes - 2; i++)
                        buffer.ReadByte();

                    // check checksum
                    ushort checksum = NetChecksum.Adler16(buffer.Data, 0, buffer.LengthBytes - 2);
                    ushort given = buffer.ReadUInt16();
                    if (checksum != given)
                        WriteToConsole("Wrong checksum! Expected " + checksum + " found given " + given);

                    double b = s_userMessagesReceived;
                    for (int i = 0; i < 1000; i++)
                        b += Math.Sqrt((double)i) / Math.Sin(s_tmp);
                    s_tmp += b / 10000.0;
                    break;
                default:
                    break;
            }
        }
All Usage Examples Of Lidgren.Network.NetBuffer::ReadByte