private void Fail( TProtocol oprot, TMessage message, TApplicationException.ExceptionType extype, string etxt) { TApplicationException appex = new TApplicationException( extype, etxt); TMessage newMessage = new TMessage(message.Name, TMessageType.Exception, message.SeqID); oprot.WriteMessageBegin(newMessage); appex.Write( oprot); oprot.WriteMessageEnd(); oprot.Transport.Flush(); }
public override void WriteMessageBegin(TMessage message) { if (StrictWrite) { var version = Version1 | (uint)message.Type; WriteI32((int)version); WriteString(message.Name); WriteI32(message.SeqID); } else { WriteString(message.Name); WriteByte((sbyte)message.Type); WriteI32(message.SeqID); } }
public override void WriteMessageBegin(TMessage message) { if (strictWrite_) { var version = VERSION_1 | (UInt32)(message.Type); WriteI32((Int32)version); WriteString(message.Name); WriteI32(message.SeqID); } else { WriteString(message.Name); WriteByte((SByte)message.Type); WriteI32(message.SeqID); } }
public override void WriteMessageBegin(TMessage message) { if (strictWrite_) { uint version = VERSION_1 | (uint)(message.Type); WriteI32((int)version); WriteString(message.Name); WriteI32(message.SeqID); } else { WriteString(message.Name); WriteByte((byte)message.Type); WriteI32(message.SeqID); } }
public override async Task WriteMessageBeginAsync(TMessage message, CancellationToken cancellationToken) { switch (message.Type) { case TMessageType.Call: case TMessageType.Oneway: await base.WriteMessageBeginAsync(new TMessage($"{_serviceName}{Separator}{message.Name}", message.Type, message.SeqID), cancellationToken); break; default: await base.WriteMessageBeginAsync(message, cancellationToken); break; } }
public override TMessage ReadMessageBegin() { TMessage message = new TMessage(); ReadJSONArrayStart(); if (ReadJSONInteger() != VERSION) { throw new TProtocolException(TProtocolException.BAD_VERSION, "Message contained bad version."); } message.Name = utf8Encoding.GetString(ReadJSONString(false)); message.Type = (TMessageType)ReadJSONInteger(); message.SeqID = (int)ReadJSONInteger(); return(message); }
/** * Prepends the service name to the function name, separated by TMultiplexedProtocol.SEPARATOR. * Args: * tMessage The original message. */ public override void WriteMessageBegin(TMessage tMessage) { switch (tMessage.Type) { case TMessageType.Call: case TMessageType.Oneway: base.WriteMessageBegin(new TMessage( ServiceName + SEPARATOR + tMessage.Name, tMessage.Type, tMessage.SeqID)); break; default: base.WriteMessageBegin(tMessage); break; } }
/** * Prepends the service name to the function name, separated by TMultiplexedProtocol.SEPARATOR. * Args: * tMessage The original message. */ public override void WriteMessageBegin(TMessage tMessage) { switch(tMessage.Type) { case TMessageType.Call: case TMessageType.Oneway: base.WriteMessageBegin(new TMessage( ServiceName + SEPARATOR + tMessage.Name, tMessage.Type, tMessage.SeqID)); break; default: base.WriteMessageBegin(tMessage); break; } }
public override void WriteMessageBegin(TMessage message, out int seqIdPosition) { if (StrictWrite) { var version = Version1 | (uint)message.Type; WriteI32((int)version); WriteString(message.Name); seqIdPosition = (int)Transport.Position; WriteI32(message.SeqID); } else { WriteString(message.Name); WriteByte((sbyte)message.Type); seqIdPosition = (int)Transport.Position; WriteI32(message.SeqID); } }
public override async Task WriteMessageBeginAsync(TMessage message, CancellationToken cancellationToken) { cancellationToken.ThrowIfCancellationRequested(); if (StrictWrite) { var version = Version1 | (uint)message.Type; await WriteI32Async((int)version, cancellationToken); await WriteStringAsync(message.Name, cancellationToken); await WriteI32Async(message.SeqID, cancellationToken); } else { await WriteStringAsync(message.Name, cancellationToken); await WriteByteAsync((sbyte)message.Type, cancellationToken); await WriteI32Async(message.SeqID, cancellationToken); } }
public override async Task WriteMessageBeginAsync(TMessage message, CancellationToken cancellationToken) { if (cancellationToken.IsCancellationRequested) { return; } await Trans.WriteAsync(new[] { ProtocolId }, cancellationToken); await Trans.WriteAsync( new[] { (byte)((Version & VersionMask) | (((uint)message.Type << TypeShiftAmount) & TypeMask)) }, cancellationToken); var bufferTuple = CreateWriteVarInt32((uint)message.SeqID); await Trans.WriteAsync(bufferTuple.Item1, 0, bufferTuple.Item2, cancellationToken); await WriteStringAsync(message.Name, cancellationToken); }
public bool Process(TProtocol iprot, TProtocol oprot) { TProcessor tProcessor; bool flag; try { TMessage tMessage = iprot.ReadMessageBegin(); if (tMessage.Type == TMessageType.Call || tMessage.Type == TMessageType.Oneway) { int num = tMessage.Name.IndexOf(TMultiplexedProtocol.SEPARATOR); if (num >= 0) { string str = tMessage.Name.Substring(0, num); if (this.ServiceProcessorMap.TryGetValue(str, out tProcessor)) { TMessage tMessage1 = new TMessage(tMessage.Name.Substring(str.Length + TMultiplexedProtocol.SEPARATOR.Length), tMessage.Type, tMessage.SeqID); flag = tProcessor.Process(new TMultiplexedProcessor.StoredMessageProtocol(iprot, tMessage1), oprot); } else { this.Fail(oprot, tMessage, TApplicationException.ExceptionType.InternalError, string.Concat("Service name not found: ", str, ". Did you forget to call RegisterProcessor()?")); flag = false; } } else { this.Fail(oprot, tMessage, TApplicationException.ExceptionType.InvalidProtocol, string.Concat("Service name not found in message name: ", tMessage.Name, ". Did you forget to use a TMultiplexProtocol in your client?")); flag = false; } } else { this.Fail(oprot, tMessage, TApplicationException.ExceptionType.InvalidMessageType, "Message type CALL or ONEWAY expected"); flag = false; } } catch (IOException oException) { flag = false; } return(flag); }
public override async ValueTask <TMessage> ReadMessageBeginAsync(CancellationToken cancellationToken) { var message = new TMessage(); await ReadJsonArrayStartAsync(cancellationToken); if (await ReadJsonIntegerAsync(cancellationToken) != Version) { throw new TProtocolException(TProtocolException.BAD_VERSION, "Message contained bad version."); } var buf = await ReadJsonStringAsync(false, cancellationToken); message.Name = Utf8Encoding.GetString(buf, 0, buf.Length); message.Type = (TMessageType) await ReadJsonIntegerAsync(cancellationToken); message.SeqID = (int) await ReadJsonIntegerAsync(cancellationToken); return(message); }
public override async ValueTask <TMessage> ReadMessageBeginAsync(CancellationToken cancellationToken) { if (cancellationToken.IsCancellationRequested) { return(await Task.FromCanceled <TMessage>(cancellationToken)); } var message = new TMessage(); var size = await ReadI32Async(cancellationToken); if (size < 0) { var version = (uint)size & VersionMask; if (version != Version1) { throw new TProtocolException(TProtocolException.BAD_VERSION, $"Bad version in ReadMessageBegin: {version}"); } message.Type = (TMessageType)(size & 0x000000ff); message.Name = await ReadStringAsync(cancellationToken); message.SeqID = await ReadI32Async(cancellationToken); } else { if (StrictRead) { throw new TProtocolException(TProtocolException.BAD_VERSION, "Missing version in ReadMessageBegin, old client?"); } message.Name = (size > 0) ? await ReadStringBodyAsync(size, cancellationToken) : string.Empty; message.Type = (TMessageType) await ReadByteAsync(cancellationToken); message.SeqID = await ReadI32Async(cancellationToken); } return(message); }
public abstract Task WriteMessageBeginAsync(TMessage message, CancellationToken cancellationToken);
public virtual async Task WriteMessageBeginAsync(TMessage message) { await WriteMessageBeginAsync(message, CancellationToken.None); }
public virtual async ValueTask <TMessage> ReadMessageBeginAsync(TMessage original_message, CancellationToken cancellationToken) { return(await ReadMessageBeginAsync(cancellationToken)); }
public override void WriteMessageBegin(TMessage message) { WriteBasicString("v="); WriteBasicNumber(VERSION); WriteBasicString("&p="); // short-circuit the pseudo-DAPI wrapper if performing a raw DAPI call if (message.ServiceName == "DAPI") { this.startedDAPIRequest = true; return; } // Since most components in the DAPI protocol are // not ordered, just pass in basic data TField field = new TField(); field.Type = TType.Void; field.ID = -1; TStruct tstruct = new TStruct(); this.startedWrite = true; this.WriteStructBegin(tstruct); // DAPIRequest { // userToken : { ... }, if (this.userToken != null) { field.Name = "userToken"; this.WriteFieldBegin(field); //TODO: Map out the Dictionary<string, object> in the userToken field of this class. this.WriteFieldEnd(); } // appToken : { ... }, if (this.appToken != null) { field.Name = "appToken"; this.WriteFieldBegin(field); this.WriteStructBegin(tstruct); foreach (KeyValuePair<String,String> entry in this.appToken as Dictionary<string, string>) { field.Name = entry.Key; WriteFieldBegin(field); WriteString(entry.Value); WriteFieldEnd(); } this.WriteStructEnd(); this.WriteFieldEnd(); } // stringToken : "...", if (this.stringToken != null) { field.Name = "stringToken"; this.WriteFieldBegin(field); this.WriteString(this.stringToken); this.WriteFieldEnd(); } // calls : [ ... field.Name = "calls"; this.WriteFieldBegin(field); TList list = new TList(); this.WriteListBegin(list); // { 'method' : name, this.WriteStructBegin(tstruct); field.Name = "method"; this.WriteFieldBegin(field); this.WriteString(message.ServiceName.ToLower() + "." + message.Name); this.WriteFieldEnd(); // 'args', { ... field.Name = "argz"; this.WriteFieldBegin(field); this.startedArguments = true; }
/** * Write a message header to the wire. Compact Protocol messages contain the * protocol version so we can migrate forwards in the future if need be. */ public override void WriteMessageBegin(TMessage message) { WriteByteDirect(PROTOCOL_ID); WriteByteDirect((byte)((VERSION & VERSION_MASK) | ((((uint)message.Type) << TYPE_SHIFT_AMOUNT) & TYPE_MASK))); WriteVarint32((uint)message.SeqID); WriteString(message.Name); }
public abstract void WriteMessageBegin(TMessage message);
public override TMessage ReadMessageBegin() { TMessage message = new TMessage(); ReadJSONArrayStart(); if (ReadJSONInteger() != VERSION) { throw new TProtocolException(TProtocolException.BAD_VERSION, "Message contained bad version."); } var buf = ReadJSONString(false); message.Name = utf8Encoding.GetString(buf,0,buf.Length); message.Type = (TMessageType)ReadJSONInteger(); message.SeqID = (int)ReadJSONInteger(); return message; }
public override async Task WriteMessageBeginAsync(TMessage message, CancellationToken cancellationToken) { await _wrappedProtocol.WriteMessageBeginAsync(message, cancellationToken); }
public abstract Task WriteMessageBeginAsync(TMessage message);
public override TMessage ReadMessageBegin() { TMessage message = new TMessage(); int size = ReadI32(); if (size < 0) { uint version = (uint)size & VERSION_MASK; if (version != VERSION_1) { throw new TProtocolException(TProtocolException.BAD_VERSION, "Bad version in ReadMessageBegin: " + version); } message.Type = (TMessageType)(size & 0x000000ff); message.Name = ReadString(); message.SeqID = ReadI32(); } else { if (strictRead_) { throw new TProtocolException(TProtocolException.BAD_VERSION, "Missing version in readMessageBegin, old client?"); } message.Name = ReadStringBody(size); message.Type = (TMessageType)ReadByte(); message.SeqID = ReadI32(); } return message; }
public StoredMessageProtocol(TProtocol protocol, TMessage messageBegin) :base(protocol) { this.MsgBegin = messageBegin; }
public override TMessage ReadMessageBegin() { TMessage message = new TMessage(); message.Name = null; message.Type = 0; message.SeqID = 0; return message; }
} private void GetUser_Process(TMessage message, TProtocol iproto, Action<byte[]> callback) { var args = new Service1.GetUser_args(); try { args.Read(iproto); } catch (System.Exception ex) { iproto.Transport.Close(); callback(ThriftMarshaller.Serialize(new TMessage(message.Name, TMessageType.Exception, message.SeqID), new TApplicationException(TApplicationException.ExceptionType.Unknown, ex.Message))); return; } iproto.Transport.Close(); int seqID = message.SeqID; try { this._face.GetUser(args.UserId, (result) => { callback(ThriftMarshaller.Serialize(new TMessage("GetUser", TMessageType.Reply, seqID), new Service1.GetUser_result { Success = result })); }); } catch (System.Exception ex) { if (ex is Example.Service.Thrift.IllegalityUserIdException) { callback(ThriftMarshaller.Serialize(new TMessage("GetUser", TMessageType.Reply, seqID), new Service1.GetUser_result{ Ex = ex as Example.Service.Thrift.IllegalityUserIdException })); return;} callback(ThriftMarshaller.Serialize(new TMessage(message.Name, TMessageType.Exception, message.SeqID), new TApplicationException(TApplicationException.ExceptionType.Unknown, ex.ToString()))); } }
public override TMessage ReadMessageBegin() { this.startedParse = false; TMessage message = new TMessage(); message.Name = null; message.Type = 0; message.SeqID = 0; return message; }
public override void WriteMessageBegin(TMessage message) { WriteJSONArrayStart(); WriteJSONInteger(VERSION); byte[] b = utf8Encoding.GetBytes(message.Name); WriteJSONString(b); WriteJSONInteger((long)message.Type); WriteJSONInteger(message.SeqID); }
public StoredMessageProtocol(TProtocol protocol, TMessage messageBegin) : base(protocol) { this.MsgBegin = messageBegin; }
public override void WriteMessageBegin(TMessage message) { WriteString("v="); WriteNumber(VERSION); WriteString("&p="); }
public override void WriteMessageBegin(TMessage tMessage) { WrappedProtocol.WriteMessageBegin(tMessage); }
public override void WriteMessageBegin(TMessage tMessage) { this.WrappedProtocol.WriteMessageBegin(tMessage); }
/** * 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. */ try { 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); } catch (IOException) { return false; // similar to all other processors } }
/** * Write a message header to the wire. Compact Protocol messages contain the * protocol version so we can migrate forwards in the future if need be. */ public override async Task WriteMessageBeginAsync(TMessage message) { await WriteByteDirectAsync(PROTOCOL_ID); await WriteByteDirectAsync((byte)((VERSION & VERSION_MASK) | ((((uint)message.Type) << TYPE_SHIFT_AMOUNT) & TYPE_MASK))); await WriteVarint32Async((uint)message.SeqID); await WriteStringAsync(message.Name); }