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

            SleepingBag.DeserializeLength(stream, length, sleepingBag, false);
            return(sleepingBag);
        }
コード例 #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);
        }
コード例 #3
0
        public SleepingBag Copy()
        {
            SleepingBag sleepingBag = Pool.Get <SleepingBag>();

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

            SleepingBag.Deserialize(stream, sleepingBag, false);
            return(sleepingBag);
        }
コード例 #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);
 }
コード例 #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);
 }
コード例 #7
0
 public virtual void WriteToStreamDelta(Stream stream, SleepingBag previous)
 {
     if (previous == null)
     {
         SleepingBag.Serialize(stream, this);
         return;
     }
     SleepingBag.SerializeDelta(stream, this, previous);
 }
コード例 #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);
        }
コード例 #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);
 }
コード例 #10
0
 public static byte[] SerializeToBytes(SleepingBag instance)
 {
     byte[] array;
     using (MemoryStream memoryStream = new MemoryStream())
     {
         SleepingBag.Serialize(memoryStream, instance);
         array = memoryStream.ToArray();
     }
     return(array);
 }
コード例 #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);
        }
コード例 #12
0
 public void CopyTo(SleepingBag instance)
 {
     instance.name       = this.name;
     instance.deployerID = this.deployerID;
 }
コード例 #13
0
 public virtual void WriteToStream(Stream stream)
 {
     SleepingBag.Serialize(stream, this);
 }
コード例 #14
0
 public void FromProto(Stream stream, bool isDelta = false)
 {
     SleepingBag.Deserialize(stream, this, isDelta);
 }
コード例 #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);
 }
コード例 #16
0
 public void ResetToPool()
 {
     SleepingBag.ResetToPool(this);
 }
コード例 #17
0
 public byte[] ToProtoBytes()
 {
     return(SleepingBag.SerializeToBytes(this));
 }
コード例 #18
0
 public void ToProto(Stream stream)
 {
     SleepingBag.Serialize(stream, this);
 }
コード例 #19
0
 public virtual void ReadFromStream(Stream stream, int size, bool isDelta = false)
 {
     SleepingBag.DeserializeLength(stream, size, this, isDelta);
 }