當前位置: 首頁>>代碼示例>>C#>>正文


C# TProtocol.ReadMessageBegin方法代碼示例

本文整理匯總了C#中Thrift.Protocol.TProtocol.ReadMessageBegin方法的典型用法代碼示例。如果您正苦於以下問題:C# TProtocol.ReadMessageBegin方法的具體用法?C# TProtocol.ReadMessageBegin怎麽用?C# TProtocol.ReadMessageBegin使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Thrift.Protocol.TProtocol的用法示例。


在下文中一共展示了TProtocol.ReadMessageBegin方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: Process

 public bool Process(TProtocol iprot, TProtocol oprot)
 {
     try
     {
         TMessage msg = iprot.ReadMessageBegin();
         ProcessFunction fn;
         processMap_.TryGetValue(msg.Name, out fn);
         if (fn == null)
         {
             TProtocolUtil.Skip(iprot, TType.Struct);
             iprot.ReadMessageEnd();
             TApplicationException x = new TApplicationException(TApplicationException.ExceptionType.UnknownMethod, "Invalid method name: '" + msg.Name + "'");
             oprot.WriteMessageBegin(new TMessage(msg.Name, TMessageType.Exception, msg.SeqID));
             x.Write(oprot);
             oprot.WriteMessageEnd();
             oprot.Transport.Flush();
             return true;
         }
         fn(msg.SeqID, iprot, oprot);
     }
     catch (IOException)
     {
         return false;
     }
     return true;
 }
開發者ID:tritao,項目名稱:thrift,代碼行數:26,代碼來源:TProcessor.cs

示例2: Process

        /**
         * This implementation of process performs the following steps:
         *
         * - Read the beginning of the message.
         * - Extract the service name from the message.
         * - Using the service name to locate the appropriate processor.
         * - Dispatch to the processor, with a decorated instance of TProtocol
         *    that allows readMessageBegin() to return the original TMessage.
         *
         * Throws an exception if
         * - the message type is not CALL or ONEWAY,
         * - the service name was not found in the message, or
         * - the service name has not been RegisterProcessor()ed.
         */
        public bool Process(TProtocol iprot, TProtocol oprot)
        {
            /*  Use the actual underlying protocol (e.g. TBinaryProtocol) to read the
                message header.  This pulls the message "off the wire", which we'll
                deal with at the end of this method. */

            TMessage message = iprot.ReadMessageBegin();

            if ((message.Type != TMessageType.Call) && (message.Type != TMessageType.Oneway))
            {
                Fail( oprot, message,
                      TApplicationException.ExceptionType.InvalidMessageType,
                      "Message type CALL or ONEWAY expected");
                return false;
            }

            // Extract the service name
            int index = message.Name.IndexOf(TMultiplexedProtocol.SEPARATOR);
            if (index < 0) {
                Fail( oprot, message,
                      TApplicationException.ExceptionType.InvalidProtocol,
                      "Service name not found in message name: " + message.Name + ". "+
                      "Did you forget to use a TMultiplexProtocol in your client?");
                return false;
            }

            // Create a new TMessage, something that can be consumed by any TProtocol
            string serviceName = message.Name.Substring(0, index);
            TProcessor actualProcessor;
            if( ! ServiceProcessorMap.TryGetValue(serviceName, out actualProcessor))
            {
                Fail( oprot, message,
                      TApplicationException.ExceptionType.InternalError,
                      "Service name not found: " + serviceName + ". "+
                      "Did you forget to call RegisterProcessor()?");
                return false;
            }

            // Create a new TMessage, removing the service name
            TMessage newMessage = new TMessage(
                    message.Name.Substring(serviceName.Length + TMultiplexedProtocol.SEPARATOR.Length),
                    message.Type,
                    message.SeqID);

            // Dispatch processing to the stored processor
            return actualProcessor.Process(new StoredMessageProtocol(iprot, newMessage), oprot);
        }
開發者ID:lxyu,項目名稱:thrift,代碼行數:61,代碼來源:TMultiplexedProcessor.cs


注:本文中的Thrift.Protocol.TProtocol.ReadMessageBegin方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。