Exemplo n.º 1
0
        public void Deserialize(MemoryEndianBinaryReader reader)
        {
            FieldMark fm = new FieldMark(1);

            reader.Read(fm.GetData(), 0, fm.GetData().Length);
            if (fm.ReadMark())
            {
                entityId = reader.ReadUInt32();
            }
            if (fm.ReadMark())
            {
                timestamp = reader.ReadUInt32();
            }
            if (fm.ReadMark())
            {
                idleTime = reader.ReadUInt16();
            }
            if (fm.ReadMark())
            {
                int __1__ = SerializationUtil.ReadVariableLength(reader);
                fields = new UInt32[__1__];
                for (int i = 0; i < __1__; i++)
                {
                    fields[i] = reader.ReadUInt32();
                }
            }
            if (fm.ReadMark())
            {
                int __2__ = SerializationUtil.ReadVariableLength(reader);
                values = new Single[__2__];
                for (int i = 0; i < __2__; i++)
                {
                    values[i] = reader.ReadSingle();
                }
            }
        }
Exemplo n.º 2
0
        public void read(Stream stream)
        {
            // read as mch as possible
            int bytesRead = stream.Read(buf.GetBuffer(), (int)buf.Length, (int)(buf.Capacity - buf.Length));

            //		buf.Write (buf.GetBuffer(), (int)buf.Length, (int)(bytesRead));
            //		DEBUG.Info("old length="+buf.Length+" bytesRead="+bytesRead+" new length=" + (buf.Length + bytesRead));


            buf.SetLength(buf.Length + bytesRead);

            //		if (bytesRead > 0) {
            //			DEBUG.Info ("read = " + bytesRead + " pos = " + buf.Position + " len=" + buf.Length + " remaining=" + (buf.Capacity - buf.Length));
            //		}

            buf.Position = 0;

            //		DEBUG.Info (BitConverter.ToString(buf.GetBuffer(), (int)buf.Position, (int)buf.Length));
//			bool messageRead = false;
            while (true)
            {
                if (buf.Length - buf.Position < 2)
                {
                    //no message avilable now
                    break;
                }

                UInt16 length = binaryReader.GetUInt16((int)buf.Position);
                if (buf.Length - buf.Position < length + 2)
                {
                    break;
                }

                // skip the length field
                UInt16 lengthRead = binaryReader.ReadUInt16();

                int pid = binaryReader.GetByte((int)buf.Position);
                //			DEBUG.Info ("pid=" + pid + " length=" + lengthRead + " expected=" + length);
                MemoryStream tmpStream = new MemoryStream(length);
                buf.Read(tmpStream.GetBuffer(), 0, (int)(length));
                tmpStream.SetLength(length);

                //			MemoryEndianBinaryReader tmpReader = new MemoryEndianBinaryReader (EndianBitConverter.Big, tmpStream);

                if (listener != null)
                {
                    Message message = new Message(tmpStream);
                    listener.OnMessage(message);
                }

                //			BattleToPlayerDispatcher.Dispatch(tmpReader, proxy);
            }

            MemoryStream newBuf = new MemoryStream(64 * 1024);

            if (buf.Length - buf.Position > 0)
            {
                newBuf.Write(buf.GetBuffer(), (int)buf.Position, (int)(buf.Length - buf.Position));
            }

            buf          = newBuf;
            binaryReader = new MemoryEndianBinaryReader(EndianBitConverter.Big, buf);
        }