Beispiel #1
0
 public static void ResetToPool(WorldItem instance)
 {
     if (!instance.ShouldPool)
     {
         return;
     }
     if (instance.item != null)
     {
         instance.item.ResetToPool();
         instance.item = null;
     }
     Pool.Free <WorldItem>(ref instance);
 }
Beispiel #2
0
 public void CopyTo(WorldItem instance)
 {
     if (this.item == null)
     {
         instance.item = null;
         return;
     }
     if (instance.item == null)
     {
         instance.item = this.item.Copy();
         return;
     }
     this.item.CopyTo(instance.item);
 }
Beispiel #3
0
        public static void SerializeDelta(Stream stream, WorldItem instance, WorldItem previous)
        {
            MemoryStream memoryStream = Pool.Get <MemoryStream>();

            if (instance.item != null)
            {
                stream.WriteByte(10);
                memoryStream.SetLength((long)0);
                Item.SerializeDelta(memoryStream, instance.item, previous.item);
                uint length = (uint)memoryStream.Length;
                ProtocolParser.WriteUInt32(stream, length);
                stream.Write(memoryStream.GetBuffer(), 0, (int)length);
            }
            Pool.FreeMemoryStream(ref memoryStream);
        }
Beispiel #4
0
        public static WorldItem DeserializeLengthDelimited(Stream stream, WorldItem 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 != 10)
                {
                    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);
                }
                else if (instance.item != null)
                {
                    Item.DeserializeLengthDelimited(stream, instance.item, isDelta);
                }
                else
                {
                    instance.item = Item.DeserializeLengthDelimited(stream);
                }
            }
            if (stream.Position != position)
            {
                throw new ProtocolBufferException("Read past max limit");
            }
            return(instance);
        }
Beispiel #5
0
 public virtual void WriteToStream(Stream stream)
 {
     WorldItem.Serialize(stream, this);
 }
Beispiel #6
0
 public byte[] ToProtoBytes()
 {
     return(WorldItem.SerializeToBytes(this));
 }
Beispiel #7
0
 public void ToProto(Stream stream)
 {
     WorldItem.Serialize(stream, this);
 }
Beispiel #8
0
 public static void SerializeLengthDelimited(Stream stream, WorldItem instance)
 {
     byte[] bytes = WorldItem.SerializeToBytes(instance);
     ProtocolParser.WriteUInt32(stream, (uint)bytes.Length);
     stream.Write(bytes, 0, (int)bytes.Length);
 }
Beispiel #9
0
 public void ResetToPool()
 {
     WorldItem.ResetToPool(this);
 }
Beispiel #10
0
 public virtual void ReadFromStream(Stream stream, int size, bool isDelta = false)
 {
     WorldItem.DeserializeLength(stream, size, this, isDelta);
 }
Beispiel #11
0
 public void FromProto(Stream stream, bool isDelta = false)
 {
     WorldItem.Deserialize(stream, this, isDelta);
 }