本文整理汇总了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;
}
示例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);
}