Beispiel #1
0
        public StorageBox Copy()
        {
            StorageBox storageBox = Pool.Get <StorageBox>();

            this.CopyTo(storageBox);
            return(storageBox);
        }
Beispiel #2
0
 public static StorageBox Deserialize(Stream stream, StorageBox instance, bool isDelta)
 {
     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 if (instance.contents != null)
         {
             ItemContainer.DeserializeLengthDelimited(stream, instance.contents, isDelta);
         }
         else
         {
             instance.contents = ItemContainer.DeserializeLengthDelimited(stream);
         }
     }
     return(instance);
 }
Beispiel #3
0
        public static StorageBox DeserializeLength(Stream stream, int length)
        {
            StorageBox storageBox = Pool.Get <StorageBox>();

            StorageBox.DeserializeLength(stream, length, storageBox, false);
            return(storageBox);
        }
Beispiel #4
0
        public static StorageBox DeserializeLength(Stream stream, int length, StorageBox 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)
                {
                    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.contents != null)
                {
                    ItemContainer.DeserializeLengthDelimited(stream, instance.contents, isDelta);
                }
                else
                {
                    instance.contents = ItemContainer.DeserializeLengthDelimited(stream);
                }
            }
            if (stream.Position != position)
            {
                throw new ProtocolBufferException("Read past max limit");
            }
            return(instance);
        }
Beispiel #5
0
        public static StorageBox Deserialize(Stream stream)
        {
            StorageBox storageBox = Pool.Get <StorageBox>();

            StorageBox.Deserialize(stream, storageBox, false);
            return(storageBox);
        }
Beispiel #6
0
 public static StorageBox Deserialize(byte[] buffer, StorageBox instance, bool isDelta = false)
 {
     using (MemoryStream memoryStream = new MemoryStream(buffer))
     {
         StorageBox.Deserialize(memoryStream, instance, isDelta);
     }
     return(instance);
 }
Beispiel #7
0
 public virtual void WriteToStreamDelta(Stream stream, StorageBox previous)
 {
     if (previous == null)
     {
         StorageBox.Serialize(stream, this);
         return;
     }
     StorageBox.SerializeDelta(stream, this, previous);
 }
Beispiel #8
0
 public static byte[] SerializeToBytes(StorageBox instance)
 {
     byte[] array;
     using (MemoryStream memoryStream = new MemoryStream())
     {
         StorageBox.Serialize(memoryStream, instance);
         array = memoryStream.ToArray();
     }
     return(array);
 }
Beispiel #9
0
        public static StorageBox Deserialize(byte[] buffer)
        {
            StorageBox storageBox = Pool.Get <StorageBox>();

            using (MemoryStream memoryStream = new MemoryStream(buffer))
            {
                StorageBox.Deserialize(memoryStream, storageBox, false);
            }
            return(storageBox);
        }
Beispiel #10
0
 public static void ResetToPool(StorageBox instance)
 {
     if (!instance.ShouldPool)
     {
         return;
     }
     if (instance.contents != null)
     {
         instance.contents.ResetToPool();
         instance.contents = null;
     }
     Pool.Free <StorageBox>(ref instance);
 }
Beispiel #11
0
 public void CopyTo(StorageBox instance)
 {
     if (this.contents == null)
     {
         instance.contents = null;
         return;
     }
     if (instance.contents == null)
     {
         instance.contents = this.contents.Copy();
         return;
     }
     this.contents.CopyTo(instance.contents);
 }
Beispiel #12
0
        public static void SerializeDelta(Stream stream, StorageBox instance, StorageBox previous)
        {
            MemoryStream memoryStream = Pool.Get <MemoryStream>();

            if (instance.contents != null)
            {
                stream.WriteByte(10);
                memoryStream.SetLength((long)0);
                ItemContainer.SerializeDelta(memoryStream, instance.contents, previous.contents);
                uint length = (uint)memoryStream.Length;
                ProtocolParser.WriteUInt32(stream, length);
                stream.Write(memoryStream.GetBuffer(), 0, (int)length);
            }
            Pool.FreeMemoryStream(ref memoryStream);
        }
Beispiel #13
0
 public virtual void WriteToStream(Stream stream)
 {
     StorageBox.Serialize(stream, this);
 }
Beispiel #14
0
 public byte[] ToProtoBytes()
 {
     return(StorageBox.SerializeToBytes(this));
 }
Beispiel #15
0
 public void ToProto(Stream stream)
 {
     StorageBox.Serialize(stream, this);
 }
Beispiel #16
0
 public static void SerializeLengthDelimited(Stream stream, StorageBox instance)
 {
     byte[] bytes = StorageBox.SerializeToBytes(instance);
     ProtocolParser.WriteUInt32(stream, (uint)bytes.Length);
     stream.Write(bytes, 0, (int)bytes.Length);
 }
Beispiel #17
0
 public void ResetToPool()
 {
     StorageBox.ResetToPool(this);
 }
Beispiel #18
0
 public virtual void ReadFromStream(Stream stream, int size, bool isDelta = false)
 {
     StorageBox.DeserializeLength(stream, size, this, isDelta);
 }
Beispiel #19
0
 public void FromProto(Stream stream, bool isDelta = false)
 {
     StorageBox.Deserialize(stream, this, isDelta);
 }