Exemplo n.º 1
0
 public static DecayEntity Deserialize(Stream stream, DecayEntity instance, bool isDelta)
 {
     while (true)
     {
         int num = stream.ReadByte();
         if (num == -1)
         {
             break;
         }
         if (num == 13)
         {
             instance.decayTimer = ProtocolParser.ReadSingle(stream);
         }
         else if (num == 16)
         {
             instance.buildingID = ProtocolParser.ReadUInt32(stream);
         }
         else if (num == 29)
         {
             instance.upkeepTimer = ProtocolParser.ReadSingle(stream);
         }
         else
         {
             Key key = ProtocolParser.ReadKey((byte)num, stream);
             if (key.Field == 0)
             {
                 throw new ProtocolBufferException("Invalid field id: 0, something went wrong in the stream");
             }
             ProtocolParser.SkipKey(stream, key);
         }
     }
     return(instance);
 }
Exemplo n.º 2
0
        public static DecayEntity DeserializeLength(Stream stream, int length)
        {
            DecayEntity decayEntity = Pool.Get <DecayEntity>();

            DecayEntity.DeserializeLength(stream, length, decayEntity, false);
            return(decayEntity);
        }
Exemplo n.º 3
0
        public DecayEntity Copy()
        {
            DecayEntity decayEntity = Pool.Get <DecayEntity>();

            this.CopyTo(decayEntity);
            return(decayEntity);
        }
Exemplo n.º 4
0
        public static DecayEntity Deserialize(Stream stream)
        {
            DecayEntity decayEntity = Pool.Get <DecayEntity>();

            DecayEntity.Deserialize(stream, decayEntity, false);
            return(decayEntity);
        }
Exemplo n.º 5
0
 public static DecayEntity Deserialize(byte[] buffer, DecayEntity instance, bool isDelta = false)
 {
     using (MemoryStream memoryStream = new MemoryStream(buffer))
     {
         DecayEntity.Deserialize(memoryStream, instance, isDelta);
     }
     return(instance);
 }
Exemplo n.º 6
0
 public virtual void WriteToStreamDelta(Stream stream, DecayEntity previous)
 {
     if (previous == null)
     {
         DecayEntity.Serialize(stream, this);
         return;
     }
     DecayEntity.SerializeDelta(stream, this, previous);
 }
Exemplo n.º 7
0
        public static DecayEntity Deserialize(byte[] buffer)
        {
            DecayEntity decayEntity = Pool.Get <DecayEntity>();

            using (MemoryStream memoryStream = new MemoryStream(buffer))
            {
                DecayEntity.Deserialize(memoryStream, decayEntity, false);
            }
            return(decayEntity);
        }
Exemplo n.º 8
0
 public static byte[] SerializeToBytes(DecayEntity instance)
 {
     byte[] array;
     using (MemoryStream memoryStream = new MemoryStream())
     {
         DecayEntity.Serialize(memoryStream, instance);
         array = memoryStream.ToArray();
     }
     return(array);
 }
Exemplo n.º 9
0
 public static void ResetToPool(DecayEntity instance)
 {
     if (!instance.ShouldPool)
     {
         return;
     }
     instance.decayTimer  = 0f;
     instance.buildingID  = 0;
     instance.upkeepTimer = 0f;
     Pool.Free <DecayEntity>(ref instance);
 }
Exemplo n.º 10
0
        public static void Serialize(Stream stream, DecayEntity instance)
        {
            MemoryStream memoryStream = Pool.Get <MemoryStream>();

            stream.WriteByte(13);
            ProtocolParser.WriteSingle(stream, instance.decayTimer);
            stream.WriteByte(16);
            ProtocolParser.WriteUInt32(stream, instance.buildingID);
            stream.WriteByte(29);
            ProtocolParser.WriteSingle(stream, instance.upkeepTimer);
            Pool.FreeMemoryStream(ref memoryStream);
        }
Exemplo n.º 11
0
        public static void SerializeDelta(Stream stream, DecayEntity instance, DecayEntity previous)
        {
            MemoryStream memoryStream = Pool.Get <MemoryStream>();

            if (instance.decayTimer != previous.decayTimer)
            {
                stream.WriteByte(13);
                ProtocolParser.WriteSingle(stream, instance.decayTimer);
            }
            if (instance.buildingID != previous.buildingID)
            {
                stream.WriteByte(16);
                ProtocolParser.WriteUInt32(stream, instance.buildingID);
            }
            if (instance.upkeepTimer != previous.upkeepTimer)
            {
                stream.WriteByte(29);
                ProtocolParser.WriteSingle(stream, instance.upkeepTimer);
            }
            Pool.FreeMemoryStream(ref memoryStream);
        }
Exemplo n.º 12
0
        public static DecayEntity DeserializeLengthDelimited(Stream stream, DecayEntity instance, bool isDelta)
        {
            long position = (long)ProtocolParser.ReadUInt32(stream);

            position += stream.Position;
            while (stream.Position < position)
            {
                int num = stream.ReadByte();
                if (num == -1)
                {
                    throw new EndOfStreamException();
                }
                if (num == 13)
                {
                    instance.decayTimer = ProtocolParser.ReadSingle(stream);
                }
                else if (num == 16)
                {
                    instance.buildingID = ProtocolParser.ReadUInt32(stream);
                }
                else if (num == 29)
                {
                    instance.upkeepTimer = ProtocolParser.ReadSingle(stream);
                }
                else
                {
                    Key key = ProtocolParser.ReadKey((byte)num, stream);
                    if (key.Field == 0)
                    {
                        throw new ProtocolBufferException("Invalid field id: 0, something went wrong in the stream");
                    }
                    ProtocolParser.SkipKey(stream, key);
                }
            }
            if (stream.Position != position)
            {
                throw new ProtocolBufferException("Read past max limit");
            }
            return(instance);
        }
Exemplo n.º 13
0
 public void CopyTo(DecayEntity instance)
 {
     instance.decayTimer  = this.decayTimer;
     instance.buildingID  = this.buildingID;
     instance.upkeepTimer = this.upkeepTimer;
 }
Exemplo n.º 14
0
 public virtual void WriteToStream(Stream stream)
 {
     DecayEntity.Serialize(stream, this);
 }
Exemplo n.º 15
0
 public byte[] ToProtoBytes()
 {
     return(DecayEntity.SerializeToBytes(this));
 }
Exemplo n.º 16
0
 public virtual void ReadFromStream(Stream stream, int size, bool isDelta = false)
 {
     DecayEntity.DeserializeLength(stream, size, this, isDelta);
 }
Exemplo n.º 17
0
 public static void SerializeLengthDelimited(Stream stream, DecayEntity instance)
 {
     byte[] bytes = DecayEntity.SerializeToBytes(instance);
     ProtocolParser.WriteUInt32(stream, (uint)bytes.Length);
     stream.Write(bytes, 0, (int)bytes.Length);
 }
Exemplo n.º 18
0
 public void ResetToPool()
 {
     DecayEntity.ResetToPool(this);
 }
Exemplo n.º 19
0
 public void ToProto(Stream stream)
 {
     DecayEntity.Serialize(stream, this);
 }
Exemplo n.º 20
0
 public void FromProto(Stream stream, bool isDelta = false)
 {
     DecayEntity.Deserialize(stream, this, isDelta);
 }