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