示例#1
0
        public static EggHunt DeserializeLength(Stream stream, int length)
        {
            EggHunt eggHunt = Pool.Get <EggHunt>();

            EggHunt.DeserializeLength(stream, length, eggHunt, false);
            return(eggHunt);
        }
示例#2
0
        public static EggHunt DeserializeLength(Stream stream, int length, EggHunt instance, bool isDelta)
        {
            if (!isDelta && instance.hunters == null)
            {
                instance.hunters = Pool.Get <List <EggHunt.EggHunter> >();
            }
            long position = stream.Position + (long)length;

            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
                {
                    instance.hunters.Add(EggHunt.EggHunter.DeserializeLengthDelimited(stream));
                }
            }
            if (stream.Position != position)
            {
                throw new ProtocolBufferException("Read past max limit");
            }
            return(instance);
        }
示例#3
0
 public static EggHunt Deserialize(Stream stream, EggHunt instance, bool isDelta)
 {
     if (!isDelta && instance.hunters == null)
     {
         instance.hunters = Pool.Get <List <EggHunt.EggHunter> >();
     }
     while (true)
     {
         int num = stream.ReadByte();
         if (num == -1)
         {
             break;
         }
         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
         {
             instance.hunters.Add(EggHunt.EggHunter.DeserializeLengthDelimited(stream));
         }
     }
     return(instance);
 }
示例#4
0
        public static EggHunt Deserialize(Stream stream)
        {
            EggHunt eggHunt = Pool.Get <EggHunt>();

            EggHunt.Deserialize(stream, eggHunt, false);
            return(eggHunt);
        }
示例#5
0
        public EggHunt Copy()
        {
            EggHunt eggHunt = Pool.Get <EggHunt>();

            this.CopyTo(eggHunt);
            return(eggHunt);
        }
示例#6
0
 public static EggHunt Deserialize(byte[] buffer, EggHunt instance, bool isDelta = false)
 {
     using (MemoryStream memoryStream = new MemoryStream(buffer))
     {
         EggHunt.Deserialize(memoryStream, instance, isDelta);
     }
     return(instance);
 }
示例#7
0
 public virtual void WriteToStreamDelta(Stream stream, EggHunt previous)
 {
     if (previous == null)
     {
         EggHunt.Serialize(stream, this);
         return;
     }
     EggHunt.SerializeDelta(stream, this, previous);
 }
示例#8
0
        public static EggHunt Deserialize(byte[] buffer)
        {
            EggHunt eggHunt = Pool.Get <EggHunt>();

            using (MemoryStream memoryStream = new MemoryStream(buffer))
            {
                EggHunt.Deserialize(memoryStream, eggHunt, false);
            }
            return(eggHunt);
        }
示例#9
0
 public static byte[] SerializeToBytes(EggHunt instance)
 {
     byte[] array;
     using (MemoryStream memoryStream = new MemoryStream())
     {
         EggHunt.Serialize(memoryStream, instance);
         array = memoryStream.ToArray();
     }
     return(array);
 }
示例#10
0
        public static void SerializeDelta(Stream stream, EggHunt instance, EggHunt previous)
        {
            MemoryStream memoryStream = Pool.Get <MemoryStream>();

            if (instance.hunters != null)
            {
                for (int i = 0; i < instance.hunters.Count; i++)
                {
                    EggHunt.EggHunter item = instance.hunters[i];
                    stream.WriteByte(10);
                    memoryStream.SetLength((long)0);
                    EggHunt.EggHunter.SerializeDelta(memoryStream, item, item);
                    uint length = (uint)memoryStream.Length;
                    ProtocolParser.WriteUInt32(stream, length);
                    stream.Write(memoryStream.GetBuffer(), 0, (int)length);
                }
            }
            Pool.FreeMemoryStream(ref memoryStream);
        }
示例#11
0
 public static void ResetToPool(EggHunt instance)
 {
     if (!instance.ShouldPool)
     {
         return;
     }
     if (instance.hunters != null)
     {
         for (int i = 0; i < instance.hunters.Count; i++)
         {
             if (instance.hunters[i] != null)
             {
                 instance.hunters[i].ResetToPool();
                 instance.hunters[i] = null;
             }
         }
         List <EggHunt.EggHunter> eggHunters = instance.hunters;
         Pool.FreeList <EggHunt.EggHunter>(ref eggHunters);
         instance.hunters = eggHunters;
     }
     Pool.Free <EggHunt>(ref instance);
 }
示例#12
0
 public virtual void WriteToStream(Stream stream)
 {
     EggHunt.Serialize(stream, this);
 }
示例#13
0
 public byte[] ToProtoBytes()
 {
     return(EggHunt.SerializeToBytes(this));
 }
示例#14
0
 public void FromProto(Stream stream, bool isDelta = false)
 {
     EggHunt.Deserialize(stream, this, isDelta);
 }
示例#15
0
 public static void SerializeLengthDelimited(Stream stream, EggHunt instance)
 {
     byte[] bytes = EggHunt.SerializeToBytes(instance);
     ProtocolParser.WriteUInt32(stream, (uint)bytes.Length);
     stream.Write(bytes, 0, (int)bytes.Length);
 }
示例#16
0
 public void ResetToPool()
 {
     EggHunt.ResetToPool(this);
 }
示例#17
0
 public void ToProto(Stream stream)
 {
     EggHunt.Serialize(stream, this);
 }
示例#18
0
 public void CopyTo(EggHunt instance)
 {
     throw new NotImplementedException();
 }
示例#19
0
 public virtual void ReadFromStream(Stream stream, int size, bool isDelta = false)
 {
     EggHunt.DeserializeLength(stream, size, this, isDelta);
 }