Aegis.IO.StreamBuffer.GetUInt16 C# (CSharp) Method

GetUInt16() public method

public GetUInt16 ( ) : ushort
return ushort
        public ushort GetUInt16()
        {
            if (ReadBytes + sizeof(ushort) > WrittenBytes)
                throw new AegisException(AegisResult.BufferUnderflow, "No more readable buffer.");

            var val = BitConverter.ToUInt16(Buffer, ReadBytes);
            ReadBytes += sizeof(ushort);
            return val;
        }

Same methods

StreamBuffer::GetUInt16 ( StreamBuffer source, int readIndex ) : ushort
StreamBuffer::GetUInt16 ( int readIndex ) : ushort

Usage Example

Esempio n. 1
0
        /// <summary>
        /// 수신된 데이터가 유효한 패킷인지 여부를 확인합니다.
        /// 유효한 패킷으로 판단되면 packetSize에 이 패킷의 정확한 크기를 입력하고 true를 반환해야 합니다.
        /// </summary>
        /// <param name="buffer">수신된 데이터가 담긴 버퍼</param>
        /// <param name="packetSize">유효한 패킷의 크기</param>
        /// <returns>true를 반환하면 EventReceive 통해 수신된 데이터가 전달됩니다.</returns>
        public static bool IsValidPacket(StreamBuffer buffer, out int packetSize)
        {
            if (buffer.WrittenBytes < HeaderSize)
            {
                packetSize = 0;
                return false;
            }

            //  최초 2바이트를 수신할 패킷의 크기로 처리
            packetSize = buffer.GetUInt16(0);
            return (packetSize > 0 && buffer.WrittenBytes >= packetSize);
        }