Пример #1
0
        /// <summary>
        /// Read just this level from the stream.
        /// </summary>
        private static void ReadPacket(Stream stream, out NetworkMessageTypeCode typeCode, out Version version, out int length)
        {
            int rawTypeCode;

            BinarySerializer.DeserializeValue(stream, out rawTypeCode);
            typeCode = (NetworkMessageTypeCode)rawTypeCode;

            //we serialize version as major/minor
            int majorVer, minorVer;

            BinarySerializer.DeserializeValue(stream, out majorVer);
            BinarySerializer.DeserializeValue(stream, out minorVer);
            version = new Version(majorVer, minorVer);

            BinarySerializer.DeserializeValue(stream, out length);
        }
Пример #2
0
 /// <summary>
 /// Peek at the byte data and see if there's a full packet header
 /// </summary>
 /// <param name="stream">The raw data</param>
 /// <param name="packetLength">The length of the packet</param>
 /// <param name="typeCode">The type of the packet</param>
 /// <param name="version">The schema of the packet</param>
 /// <returns>True if the header could be read, false if there wasn't enough data</returns>
 public static bool ReadHeader(Stream stream, out int packetLength, out NetworkMessageTypeCode typeCode, out Version version)
 {
     if ((stream.Length - stream.Position) >= BasePacketLength)
     {
         long originalPosition = stream.Position;
         ReadPacket(stream, out typeCode, out version, out packetLength);
         stream.Position = originalPosition;
         return(true);
     }
     else
     {
         packetLength = 0;
         typeCode     = 0;
         version      = null;
         return(false);
     }
 }