Exemple #1
0
        public static SleepingBag DeserializeLength(Stream stream, int length)
        {
            SleepingBag sleepingBag = Pool.Get <SleepingBag>();

            SleepingBag.DeserializeLength(stream, length, sleepingBag, false);
            return(sleepingBag);
        }
Exemple #2
0
        public static SleepingBag DeserializeLength(Stream stream, int length, SleepingBag instance, bool isDelta)
        {
            long position = stream.Position + (long)length;

            while (stream.Position < position)
            {
                int num = stream.ReadByte();
                if (num == -1)
                {
                    throw new EndOfStreamException();
                }
                if (num == 10)
                {
                    instance.name = ProtocolParser.ReadString(stream);
                }
                else if (num == 24)
                {
                    instance.deployerID = ProtocolParser.ReadUInt64(stream);
                }
                else
                {
                    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);
                }
            }
            if (stream.Position != position)
            {
                throw new ProtocolBufferException("Read past max limit");
            }
            return(instance);
        }
Exemple #3
0
        public SleepingBag Copy()
        {
            SleepingBag sleepingBag = Pool.Get <SleepingBag>();

            this.CopyTo(sleepingBag);
            return(sleepingBag);
        }
Exemple #4
0
        public static SleepingBag Deserialize(Stream stream)
        {
            SleepingBag sleepingBag = Pool.Get <SleepingBag>();

            SleepingBag.Deserialize(stream, sleepingBag, false);
            return(sleepingBag);
        }
Exemple #5
0
 public static SleepingBag Deserialize(Stream stream, SleepingBag instance, bool isDelta)
 {
     while (true)
     {
         int num = stream.ReadByte();
         if (num == -1)
         {
             break;
         }
         if (num == 10)
         {
             instance.name = ProtocolParser.ReadString(stream);
         }
         else if (num == 24)
         {
             instance.deployerID = ProtocolParser.ReadUInt64(stream);
         }
         else
         {
             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);
 }
Exemple #6
0
 public static SleepingBag Deserialize(byte[] buffer, SleepingBag instance, bool isDelta = false)
 {
     using (MemoryStream memoryStream = new MemoryStream(buffer))
     {
         SleepingBag.Deserialize(memoryStream, instance, isDelta);
     }
     return(instance);
 }
Exemple #7
0
 public virtual void WriteToStreamDelta(Stream stream, SleepingBag previous)
 {
     if (previous == null)
     {
         SleepingBag.Serialize(stream, this);
         return;
     }
     SleepingBag.SerializeDelta(stream, this, previous);
 }
Exemple #8
0
        public static SleepingBag Deserialize(byte[] buffer)
        {
            SleepingBag sleepingBag = Pool.Get <SleepingBag>();

            using (MemoryStream memoryStream = new MemoryStream(buffer))
            {
                SleepingBag.Deserialize(memoryStream, sleepingBag, false);
            }
            return(sleepingBag);
        }
Exemple #9
0
 public static void ResetToPool(SleepingBag instance)
 {
     if (!instance.ShouldPool)
     {
         return;
     }
     instance.name       = string.Empty;
     instance.deployerID = (ulong)0;
     Pool.Free <SleepingBag>(ref instance);
 }
Exemple #10
0
 public static byte[] SerializeToBytes(SleepingBag instance)
 {
     byte[] array;
     using (MemoryStream memoryStream = new MemoryStream())
     {
         SleepingBag.Serialize(memoryStream, instance);
         array = memoryStream.ToArray();
     }
     return(array);
 }
Exemple #11
0
        public static void Serialize(Stream stream, SleepingBag instance)
        {
            MemoryStream memoryStream = Pool.Get <MemoryStream>();

            if (instance.name != null)
            {
                stream.WriteByte(10);
                ProtocolParser.WriteString(stream, instance.name);
            }
            stream.WriteByte(24);
            ProtocolParser.WriteUInt64(stream, instance.deployerID);
            Pool.FreeMemoryStream(ref memoryStream);
        }
Exemple #12
0
 public void CopyTo(SleepingBag instance)
 {
     instance.name       = this.name;
     instance.deployerID = this.deployerID;
 }
Exemple #13
0
 public virtual void WriteToStream(Stream stream)
 {
     SleepingBag.Serialize(stream, this);
 }
Exemple #14
0
 public void FromProto(Stream stream, bool isDelta = false)
 {
     SleepingBag.Deserialize(stream, this, isDelta);
 }
Exemple #15
0
 public static void SerializeLengthDelimited(Stream stream, SleepingBag instance)
 {
     byte[] bytes = SleepingBag.SerializeToBytes(instance);
     ProtocolParser.WriteUInt32(stream, (uint)bytes.Length);
     stream.Write(bytes, 0, (int)bytes.Length);
 }
Exemple #16
0
 public void ResetToPool()
 {
     SleepingBag.ResetToPool(this);
 }
Exemple #17
0
 public byte[] ToProtoBytes()
 {
     return(SleepingBag.SerializeToBytes(this));
 }
Exemple #18
0
 public void ToProto(Stream stream)
 {
     SleepingBag.Serialize(stream, this);
 }
Exemple #19
0
 public virtual void ReadFromStream(Stream stream, int size, bool isDelta = false)
 {
     SleepingBag.DeserializeLength(stream, size, this, isDelta);
 }