예제 #1
0
        public static PlantEntity DeserializeLength(Stream stream, int length)
        {
            PlantEntity plantEntity = Pool.Get <PlantEntity>();

            PlantEntity.DeserializeLength(stream, length, plantEntity, false);
            return(plantEntity);
        }
예제 #2
0
        public static PlantEntity Deserialize(Stream stream)
        {
            PlantEntity plantEntity = Pool.Get <PlantEntity>();

            PlantEntity.Deserialize(stream, plantEntity, false);
            return(plantEntity);
        }
예제 #3
0
        public PlantEntity Copy()
        {
            PlantEntity plantEntity = Pool.Get <PlantEntity>();

            this.CopyTo(plantEntity);
            return(plantEntity);
        }
예제 #4
0
 public static PlantEntity Deserialize(byte[] buffer, PlantEntity instance, bool isDelta = false)
 {
     using (MemoryStream memoryStream = new MemoryStream(buffer))
     {
         PlantEntity.Deserialize(memoryStream, instance, isDelta);
     }
     return(instance);
 }
예제 #5
0
 public virtual void WriteToStreamDelta(Stream stream, PlantEntity previous)
 {
     if (previous == null)
     {
         PlantEntity.Serialize(stream, this);
         return;
     }
     PlantEntity.SerializeDelta(stream, this, previous);
 }
예제 #6
0
        public static PlantEntity Deserialize(byte[] buffer)
        {
            PlantEntity plantEntity = Pool.Get <PlantEntity>();

            using (MemoryStream memoryStream = new MemoryStream(buffer))
            {
                PlantEntity.Deserialize(memoryStream, plantEntity, false);
            }
            return(plantEntity);
        }
예제 #7
0
 public static byte[] SerializeToBytes(PlantEntity instance)
 {
     byte[] array;
     using (MemoryStream memoryStream = new MemoryStream())
     {
         PlantEntity.Serialize(memoryStream, instance);
         array = memoryStream.ToArray();
     }
     return(array);
 }
예제 #8
0
 public void CopyTo(PlantEntity instance)
 {
     instance.state         = this.state;
     instance.age           = this.age;
     instance.genetics      = this.genetics;
     instance.water         = this.water;
     instance.healthy       = this.healthy;
     instance.totalAge      = this.totalAge;
     instance.growthAge     = this.growthAge;
     instance.yieldFraction = this.yieldFraction;
     instance.stageAge      = this.stageAge;
 }
예제 #9
0
        public static void SerializeDelta(Stream stream, PlantEntity instance, PlantEntity previous)
        {
            MemoryStream memoryStream = Pool.Get <MemoryStream>();

            if (instance.state != previous.state)
            {
                stream.WriteByte(8);
                ProtocolParser.WriteUInt64(stream, (ulong)instance.state);
            }
            if (instance.age != previous.age)
            {
                stream.WriteByte(21);
                ProtocolParser.WriteSingle(stream, instance.age);
            }
            if (instance.genetics != previous.genetics)
            {
                stream.WriteByte(24);
                ProtocolParser.WriteUInt64(stream, (ulong)instance.genetics);
            }
            if (instance.water != previous.water)
            {
                stream.WriteByte(32);
                ProtocolParser.WriteUInt64(stream, (ulong)instance.water);
            }
            if (instance.healthy != previous.healthy)
            {
                stream.WriteByte(45);
                ProtocolParser.WriteSingle(stream, instance.healthy);
            }
            if (instance.totalAge != previous.totalAge)
            {
                stream.WriteByte(53);
                ProtocolParser.WriteSingle(stream, instance.totalAge);
            }
            if (instance.growthAge != previous.growthAge)
            {
                stream.WriteByte(61);
                ProtocolParser.WriteSingle(stream, instance.growthAge);
            }
            if (instance.yieldFraction != previous.yieldFraction)
            {
                stream.WriteByte(69);
                ProtocolParser.WriteSingle(stream, instance.yieldFraction);
            }
            if (instance.stageAge != previous.stageAge)
            {
                stream.WriteByte(77);
                ProtocolParser.WriteSingle(stream, instance.stageAge);
            }
            Pool.FreeMemoryStream(ref memoryStream);
        }
예제 #10
0
 public static void ResetToPool(PlantEntity instance)
 {
     if (!instance.ShouldPool)
     {
         return;
     }
     instance.state         = 0;
     instance.age           = 0f;
     instance.genetics      = 0;
     instance.water         = 0;
     instance.healthy       = 0f;
     instance.totalAge      = 0f;
     instance.growthAge     = 0f;
     instance.yieldFraction = 0f;
     instance.stageAge      = 0f;
     Pool.Free <PlantEntity>(ref instance);
 }
예제 #11
0
 public virtual void WriteToStream(Stream stream)
 {
     PlantEntity.Serialize(stream, this);
 }
예제 #12
0
 public byte[] ToProtoBytes()
 {
     return(PlantEntity.SerializeToBytes(this));
 }
예제 #13
0
 public void FromProto(Stream stream, bool isDelta = false)
 {
     PlantEntity.Deserialize(stream, this, isDelta);
 }
예제 #14
0
 public static void SerializeLengthDelimited(Stream stream, PlantEntity instance)
 {
     byte[] bytes = PlantEntity.SerializeToBytes(instance);
     ProtocolParser.WriteUInt32(stream, (uint)bytes.Length);
     stream.Write(bytes, 0, (int)bytes.Length);
 }
예제 #15
0
 public void ResetToPool()
 {
     PlantEntity.ResetToPool(this);
 }
예제 #16
0
 public virtual void ReadFromStream(Stream stream, int size, bool isDelta = false)
 {
     PlantEntity.DeserializeLength(stream, size, this, isDelta);
 }
예제 #17
0
 public static PlantEntity Deserialize(Stream stream, PlantEntity instance, bool isDelta)
 {
     while (true)
     {
         int num = stream.ReadByte();
         if (num == -1)
         {
             break;
         }
         if (num <= 32)
         {
             if (num <= 21)
             {
                 if (num == 8)
                 {
                     instance.state = (int)ProtocolParser.ReadUInt64(stream);
                     continue;
                 }
                 else if (num == 21)
                 {
                     instance.age = ProtocolParser.ReadSingle(stream);
                     continue;
                 }
             }
             else if (num == 24)
             {
                 instance.genetics = (int)ProtocolParser.ReadUInt64(stream);
                 continue;
             }
             else if (num == 32)
             {
                 instance.water = (int)ProtocolParser.ReadUInt64(stream);
                 continue;
             }
         }
         else if (num <= 53)
         {
             if (num == 45)
             {
                 instance.healthy = ProtocolParser.ReadSingle(stream);
                 continue;
             }
             else if (num == 53)
             {
                 instance.totalAge = ProtocolParser.ReadSingle(stream);
                 continue;
             }
         }
         else if (num == 61)
         {
             instance.growthAge = ProtocolParser.ReadSingle(stream);
             continue;
         }
         else if (num == 69)
         {
             instance.yieldFraction = ProtocolParser.ReadSingle(stream);
             continue;
         }
         else if (num == 77)
         {
             instance.stageAge = ProtocolParser.ReadSingle(stream);
             continue;
         }
         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);
 }
예제 #18
0
 public void ToProto(Stream stream)
 {
     PlantEntity.Serialize(stream, this);
 }