public override Message ReadMessage(ArraySegment <byte> buffer, BufferManager bufferManager, string contentType)
            {
                if (bufferManager == null)
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException("bufferManager"));
                }

                if (WebTD.JsonMessageDecodingStartIsEnabled())
                {
                    WebTD.JsonMessageDecodingStart();
                }

                Message message;

                JsonBufferedMessageData messageData = TakeBufferedReader();

                messageData.Encoding = TextMessageEncoderFactory.GetEncodingFromContentType(contentType, JsonMessageEncoderFactory.ApplicationJsonContentEncoding);
                messageData.Open(buffer, bufferManager);
                RecycledMessageState messageState = messageData.TakeMessageState();

                if (messageState == null)
                {
                    messageState = new RecycledMessageState();
                }
                message = new BufferedMessage(messageData, messageState);

                message.Properties.Encoder = this;

                if (SMTD.MessageReadByEncoderIsEnabled() && buffer != null)
                {
                    SMTD.MessageReadByEncoder(
                        EventTraceActivityHelper.TryExtractActivity(message, true),
                        buffer.Count,
                        this);
                }

                if (MessageLogger.LogMessagesAtTransportLevel)
                {
                    MessageLogger.LogMessage(ref message, MessageLoggingSource.TransportReceive);
                }

                return(message);
            }
            JsonBufferedMessageData TakeBufferedReader()
            {
                if (bufferedReaderPool == null)
                {
                    lock (ThisLock)
                    {
                        if (bufferedReaderPool == null)
                        {
                            bufferedReaderPool = new SynchronizedPool <JsonBufferedMessageData>(maxReadPoolSize);
                        }
                    }
                }
                JsonBufferedMessageData messageData = bufferedReaderPool.Take();

                if (messageData == null)
                {
                    messageData = new JsonBufferedMessageData(this, maxPooledXmlReadersPerMessage);
                }
                return(messageData);
            }
 void ReturnBufferedData(JsonBufferedMessageData messageData)
 {
     bufferedReaderPool.Return(messageData);
 }
 JsonBufferedMessageData TakeBufferedReader()
 {
     if (bufferedReaderPool == null)
     {
         lock (ThisLock)
         {
             if (bufferedReaderPool == null)
             {
                 bufferedReaderPool = new SynchronizedPool<JsonBufferedMessageData>(maxReadPoolSize);
             }
         }
     }
     JsonBufferedMessageData messageData = bufferedReaderPool.Take();
     if (messageData == null)
     {
         messageData = new JsonBufferedMessageData(this, maxPooledXmlReadersPerMessage);
     }
     return messageData;
 }
 void ReturnBufferedData(JsonBufferedMessageData messageData)
 {
     bufferedReaderPool.Return(messageData);
 }