当前位置: 首页>>代码示例>>C#>>正文


C# Message.DeserializeBodyObject方法代码示例

本文整理汇总了C#中Orleans.Runtime.Message.DeserializeBodyObject方法的典型用法代码示例。如果您正苦于以下问题:C# Message.DeserializeBodyObject方法的具体用法?C# Message.DeserializeBodyObject怎么用?C# Message.DeserializeBodyObject使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Orleans.Runtime.Message的用法示例。


在下文中一共展示了Message.DeserializeBodyObject方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: TryDecodeMessage

        public bool TryDecodeMessage(out Message msg)
        {
            msg = null;

            // Is there enough read into the buffer to continue (at least read the lengths?)
            if (receiveOffset - decodeOffset < CalculateKnownMessageSize())
                return false;

            // parse lengths if needed
            if (headerLength == 0 || bodyLength == 0)
            {
                // get length segments
                List<ArraySegment<byte>> lenghts = ByteArrayBuilder.BuildSegmentListWithLengthLimit(readBuffer, decodeOffset, Message.LENGTH_HEADER_SIZE);

                // copy length segment to buffer
                int lengthBufferoffset = 0;
                foreach (ArraySegment<byte> seg in lenghts)
                {
                    Buffer.BlockCopy(seg.Array, seg.Offset, lengthBuffer, lengthBufferoffset, seg.Count);
                    lengthBufferoffset += seg.Count;
                }

                // read lengths
                headerLength = BitConverter.ToInt32(lengthBuffer, 0);
                bodyLength = BitConverter.ToInt32(lengthBuffer, 4);
            }

            // If message is too big for current buffer size, grow
            while (decodeOffset + CalculateKnownMessageSize() > currentBufferSize)
            {
                GrowBuffer();
            }

            // Is there enough read into the buffer to read full message
            if (receiveOffset - decodeOffset < CalculateKnownMessageSize())
                return false;

            // decode header
            int headerOffset = decodeOffset + Message.LENGTH_HEADER_SIZE;
            List<ArraySegment<byte>> header = ByteArrayBuilder.BuildSegmentListWithLengthLimit(readBuffer, headerOffset, headerLength);

            // decode body
            int bodyOffset = headerOffset + headerLength;
            List<ArraySegment<byte>> body = ByteArrayBuilder.BuildSegmentListWithLengthLimit(readBuffer, bodyOffset, bodyLength);
            
            // build message
            msg = new Message(header);
            try
            {
                if (this.supportForwarding)
                {
                    // If forwarding is supported, then deserialization will be deferred until the body value is needed.
                    // Need to maintain ownership of buffer, so we need to duplicate the body buffer.
                    msg.SetBodyBytes(this.DuplicateBuffer(body));
                }
                else
                {
                    // Attempt to deserialize the body immediately.
                    msg.DeserializeBodyObject(body);
                }
            }
            finally
            {
                MessagingStatisticsGroup.OnMessageReceive(msg, headerLength, bodyLength);

                if (headerLength + bodyLength > Message.LargeMessageSizeThreshold)
                {
                    Log.Info(
                        ErrorCode.Messaging_LargeMsg_Incoming,
                        "Receiving large message Size={0} HeaderLength={1} BodyLength={2}. Msg={3}",
                        headerLength + bodyLength,
                        headerLength,
                        bodyLength,
                        msg.ToString());
                    if (Log.IsVerbose3) Log.Verbose3("Received large message {0}", msg.ToLongString());
                }

                // update parse receiveOffset and clear lengths
                decodeOffset = bodyOffset + bodyLength;
                headerLength = 0;
                bodyLength = 0;

                AdjustBuffer();
            }

            return true;
        }
开发者ID:jdom,项目名称:orleans,代码行数:87,代码来源:IncomingMessageBuffer.cs


注:本文中的Orleans.Runtime.Message.DeserializeBodyObject方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。