Esempio n. 1
0
 private ByteBuffer(byte[] buffer, int offset, int count, int size, bool autoGrow, InternalBufferManager bufferManager)
 {
     this.buffer        = buffer;
     this.start         = offset;
     this.read          = offset;
     this.write         = offset + count;
     this.end           = offset + size;
     this.autoGrow      = autoGrow;
     this.bufferManager = bufferManager;
     this.references    = 1;
 }
Esempio n. 2
0
 private static ByteBuffer.ManagedBuffer AllocateBuffer(int size, InternalBufferManager bufferManager)
 {
     if (bufferManager != null)
     {
         byte[] numArray = bufferManager.TakeBuffer(size);
         if (numArray != null)
         {
             return(new ByteBuffer.ManagedBuffer(numArray, bufferManager));
         }
     }
     return(new ByteBuffer.ManagedBuffer(ByteBuffer.BufferManager.TakeBuffer(size), ByteBuffer.BufferManager));
 }
Esempio n. 3
0
 public void Reinitialize(int initialSize, int maxSizeQuota, int effectiveMaxSize, InternalBufferManager bufferManager)
 {
     this.maxSizeQuota     = maxSizeQuota;
     this.maxSize          = effectiveMaxSize;
     this.bufferManager    = bufferManager;
     this.currentChunk     = bufferManager.TakeBuffer(initialSize);
     this.currentChunkSize = 0;
     this.totalSize        = 0;
     this.chunkCount       = 1;
     this.chunks[0]        = this.currentChunk;
     this.initialized      = true;
 }
Esempio n. 4
0
 public static void InitBufferManagers()
 {
     if (ByteBuffer.TransportBufferManager == null)
     {
         lock (ByteBuffer.syncRoot)
         {
             if (ByteBuffer.TransportBufferManager == null)
             {
                 ByteBuffer.TransportBufferManager = InternalBufferManager.Create((long)50331648, 65536, true);
             }
         }
     }
 }
Esempio n. 5
0
        public static BufferManager CreateBufferManager(long maxBufferPoolSize, int maxBufferSize)
        {
            if (maxBufferPoolSize < 0)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException(nameof(maxBufferPoolSize),
                                                                                                          maxBufferPoolSize, SR.ValueMustBeNonNegative));
            }

            if (maxBufferSize < 0)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException(nameof(maxBufferSize),
                                                                                                          maxBufferSize, SR.ValueMustBeNonNegative));
            }

            return(new WrappingBufferManager(InternalBufferManager.Create(maxBufferPoolSize, maxBufferSize)));
        }
Esempio n. 6
0
        private static void DeserializeGroupState(SessionState messageGroupState, XmlReader reader)
        {
            int num;

            byte[] numArray = SessionState.ReadBytes(reader, 9);
            long   num1     = BitConverter.ToInt64(numArray, 1);

            if (num1 == (long)0)
            {
                return;
            }
            InternalBufferManager bufferManager = ThrottledBufferManager.GetBufferManager();

            using (BufferedOutputStream bufferedOutputStream = new BufferedOutputStream(1024, 2147483647, bufferManager))
            {
                byte[] numArray1 = bufferManager.TakeBuffer(1024);
                long   num2      = (long)0;
                try
                {
                    while (true)
                    {
                        int num3 = reader.ReadContentAsBase64(numArray1, 0, (int)numArray1.Length);
                        if (num3 == 0)
                        {
                            break;
                        }
                        num2 = num2 + (long)num3;
                        bufferedOutputStream.Write(numArray1, 0, num3);
                    }
                }
                finally
                {
                    bufferManager.ReturnBuffer(numArray1);
                }
                byte[] array = bufferedOutputStream.ToArray(out num);
                messageGroupState.Stream = new BufferedInputStream(array, num, bufferManager);
                if (num1 > (long)0 && num2 != num1)
                {
                    throw Fx.Exception.AsError(new InvalidOperationException(SRClient.FailedToDeSerializeEntireSessionStateStream), null);
                }
            }
        }
Esempio n. 7
0
        public void Validate(bool write, int dataSize)
        {
            ByteBuffer.ManagedBuffer managedBuffer;
            bool length = false;

            if (!write)
            {
                length = this.Length >= dataSize;
            }
            else
            {
                if (this.Size < dataSize && this.autoGrow)
                {
                    if (this.references != 1)
                    {
                        throw new InvalidOperationException("Cannot grow the current buffer because it has more than one references");
                    }
                    int num = Math.Max(this.Capacity * 2, this.Capacity + dataSize);
                    managedBuffer = (this.bufferManager == null ? new ByteBuffer.ManagedBuffer(new byte[num], null) : ByteBuffer.AllocateBuffer(num, this.bufferManager));
                    System.Buffer.BlockCopy(this.buffer, this.start, managedBuffer.Buffer, 0, this.Capacity);
                    int num1 = this.read - this.start;
                    int num2 = this.write - this.start;
                    this.start = 0;
                    this.read  = num1;
                    this.write = num2;
                    this.end   = num;
                    if (this.bufferManager != null)
                    {
                        this.bufferManager.ReturnBuffer(this.buffer);
                    }
                    this.buffer        = managedBuffer.Buffer;
                    this.bufferManager = managedBuffer.BufferManager;
                }
                length = this.Size >= dataSize;
            }
            if (!length)
            {
                throw new AmqpException(AmqpError.DecodeError, SRAmqp.AmqpInsufficientBufferSize(dataSize, (write ? this.Size : this.Length)));
            }
        }
Esempio n. 8
0
 public WrappingBufferManager(InternalBufferManager innerBufferManager)
 {
     InternalBufferManager = innerBufferManager;
 }
Esempio n. 9
0
 static ByteBuffer()
 {
     ByteBuffer.BufferManager = InternalBufferManager.Create((long)52428800, 2147483647, false);
     ByteBuffer.syncRoot      = new object();
 }
Esempio n. 10
0
 public ManagedBuffer(byte[] buffer, InternalBufferManager bufferManager)
 {
     this.Buffer        = buffer;
     this.BufferManager = bufferManager;
 }
 public BufferedInputStream(byte[] bytes, int bufferSize, InternalBufferManager bufferManager)
 {
     this.data        = new BufferedInputStream.BufferManagerByteArray(bytes, bufferManager);
     this.innerStream = new MemoryStream(bytes, 0, bufferSize);
 }
 public BufferManagerByteArray(byte[] bytes, InternalBufferManager bufferManager)
 {
     this.Bytes         = bytes;
     this.BufferManager = bufferManager;
     this.references    = 1;
 }
Esempio n. 13
0
 private ThrottledBufferManager(int maxSize)
 {
     this.bufferManager      = InternalBufferManager.Create((long)maxSize, 2147483647, false);
     this.ProxyBufferManager = new ThrottledBufferManager.WrappedBufferManager(this);
 }
Esempio n. 14
0
 public BufferedOutputStream(int initialSize, int maxSize, InternalBufferManager bufferManager) : this()
 {
     this.Reinitialize(initialSize, maxSize, bufferManager);
 }
Esempio n. 15
0
 public void Reinitialize(int initialSize, int maxSizeQuota, InternalBufferManager bufferManager)
 {
     this.Reinitialize(initialSize, maxSizeQuota, maxSizeQuota, bufferManager);
 }
        public static object ConvertByteArrayToNativeValue(int messageVersion, PropertyValueType propertyTypeId, byte[] bytes)
        {
            switch (propertyTypeId)
            {
            case PropertyValueType.Null:
            {
                return(null);
            }

            case PropertyValueType.Byte:
            {
                return(bytes[0]);
            }

            case PropertyValueType.SByte:
            {
                return((sbyte)bytes[0]);
            }

            case PropertyValueType.Char:
            {
                return(BitConverter.ToChar(bytes, 0));
            }

            case PropertyValueType.Int16:
            {
                return(BitConverter.ToInt16(bytes, 0));
            }

            case PropertyValueType.UInt16:
            {
                return(BitConverter.ToUInt16(bytes, 0));
            }

            case PropertyValueType.Int32:
            {
                return(BitConverter.ToInt32(bytes, 0));
            }

            case PropertyValueType.UInt32:
            {
                return(BitConverter.ToUInt32(bytes, 0));
            }

            case PropertyValueType.Int64:
            {
                return(BitConverter.ToInt64(bytes, 0));
            }

            case PropertyValueType.UInt64:
            {
                return(BitConverter.ToUInt64(bytes, 0));
            }

            case PropertyValueType.Single:
            {
                return(BitConverter.ToSingle(bytes, 0));
            }

            case PropertyValueType.Double:
            {
                return(BitConverter.ToDouble(bytes, 0));
            }

            case PropertyValueType.Decimal:
            {
                if (messageVersion < BrokeredMessage.MessageVersion3)
                {
                    return(XmlConvert.ToDecimal(Encoding.UTF8.GetString(bytes)));
                }
                int[] num = new int[] { BitConverter.ToInt32(bytes, 0), BitConverter.ToInt32(bytes, 4), BitConverter.ToInt32(bytes, 8), BitConverter.ToInt32(bytes, 12) };
                return(new decimal(num));
            }

            case PropertyValueType.Boolean:
            {
                return(BitConverter.ToBoolean(bytes, 0));
            }

            case PropertyValueType.Guid:
            {
                return(new Guid(bytes));
            }

            case PropertyValueType.String:
            {
                return(Encoding.UTF8.GetString(bytes));
            }

            case PropertyValueType.Uri:
            {
                return(new Uri(Encoding.UTF8.GetString(bytes)));
            }

            case PropertyValueType.DateTime:
            {
                return(DateTime.FromBinary(BitConverter.ToInt64(bytes, 0)));
            }

            case PropertyValueType.DateTimeOffset:
            {
                if (messageVersion < BrokeredMessage.MessageVersion3)
                {
                    return(XmlConvert.ToDateTimeOffset(Encoding.UTF8.GetString(bytes)));
                }
                long num1 = BitConverter.ToInt64(bytes, 0);
                long num2 = BitConverter.ToInt64(bytes, 8);
                return(new DateTimeOffset(num1, TimeSpan.FromTicks(num2)));
            }

            case PropertyValueType.TimeSpan:
            {
                if (messageVersion >= BrokeredMessage.MessageVersion3)
                {
                    return(TimeSpan.FromTicks(BitConverter.ToInt64(bytes, 0)));
                }
                double num3 = BitConverter.ToDouble(bytes, 0);
                if (num3.CompareTo(TimeSpan.MaxValue.TotalMilliseconds) == 0)
                {
                    return(TimeSpan.MaxValue);
                }
                return(TimeSpan.FromMilliseconds(num3));
            }

            case PropertyValueType.Stream:
            {
                InternalBufferManager bufferManager = ThrottledBufferManager.GetBufferManager();
                int    length   = (int)bytes.Length;
                byte[] numArray = bufferManager.TakeBuffer(length);
                Buffer.BlockCopy(bytes, 0, numArray, 0, length);
                return(new BufferedInputStream(numArray, length, bufferManager));
            }
            }
            throw Fx.Exception.AsError(new SerializationException(SRClient.FailedToDeserializeUnsupportedProperty(propertyTypeId.ToString())), null);
        }