Ejemplo n.º 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);
 }
Ejemplo n.º 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);
 }
Ejemplo n.º 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);
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 5
0
 public virtual void WriteToStream(Stream stream)
 {
     WorldItem.Serialize(stream, this);
 }
Ejemplo n.º 6
0
 public byte[] ToProtoBytes()
 {
     return(WorldItem.SerializeToBytes(this));
 }
Ejemplo n.º 7
0
 public void ToProto(Stream stream)
 {
     WorldItem.Serialize(stream, this);
 }
Ejemplo n.º 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);
 }
Ejemplo n.º 9
0
 public void ResetToPool()
 {
     WorldItem.ResetToPool(this);
 }
Ejemplo n.º 10
0
 public virtual void ReadFromStream(Stream stream, int size, bool isDelta = false)
 {
     WorldItem.DeserializeLength(stream, size, this, isDelta);
 }
Ejemplo n.º 11
0
 public void FromProto(Stream stream, bool isDelta = false)
 {
     WorldItem.Deserialize(stream, this, isDelta);
 }