public ThriftMethodHandler(ThriftMethodMetadata methodMetadata, ThriftCodecManager codecManager) { this.QualifiedName = methodMetadata.QualifiedName; this.Name = methodMetadata.Name; this._invokeAsynchronously = methodMetadata.IsAsync; this._oneway = !_invokeAsynchronously && methodMetadata.IsOneWay; ParameterHandler[] parameters = new ParameterHandler[methodMetadata.Parameters.Count()]; foreach (var fieldMetadata in methodMetadata.Parameters) { ThriftParameterInjection parameter = (ThriftParameterInjection)fieldMetadata.Injections.First(); ParameterHandler handler = new ParameterHandler( fieldMetadata.Id, fieldMetadata.Name, codecManager.GetCodec(fieldMetadata.ThriftType)); parameters[parameter.ParameterIndex] = handler; } this._parameterCodecs = parameters; var builder = ImmutableDictionary.CreateBuilder <short, IThriftCodec>(); foreach (var entry in methodMetadata.Exceptions) { builder.Add(entry.Key, codecManager.GetCodec(entry.Value)); } _exceptionCodecs = builder.ToImmutableDictionary(); // get the thrift codec for the return value _successCodec = codecManager.GetCodec(methodMetadata.ReturnType); }
public ThriftMethodProcessor( Func <IRequestContext, Object> service, String serviceName, ThriftMethodMetadata methodMetadata, ThriftCodecManager codecManager, ILoggerFactory loggerFactory = null) { Guard.ArgumentNotNull(service, nameof(service)); _logger = loggerFactory?.CreateLogger <ThriftMethodProcessor>() ?? (ILogger)NullLogger.Instance; this._serviceFactory = service; this.ServiceName = serviceName; this.Name = methodMetadata.Name; this.QualifiedName = methodMetadata.QualifiedName; this._resultStructName = $"{this.Name}_result"; this._method = methodMetadata.Method; this._oneway = methodMetadata.IsOneWay && !methodMetadata.IsAsync; this._parameters = methodMetadata.Parameters; var builder = ImmutableDictionary.CreateBuilder <short, IThriftCodec>(); foreach (ThriftFieldMetadata fieldMetadata in methodMetadata.Parameters) { builder.Add(fieldMetadata.Id, codecManager.GetCodec(fieldMetadata.ThriftType)); } this._parameterCodecs = builder.ToImmutableDictionary(); // Build a mapping from thrift parameter ID to a position in the formal argument list var parameterOrderingBuilder = ImmutableDictionary.CreateBuilder <short, short>(); short argumentPosition = 0; foreach (ThriftFieldMetadata fieldMetadata in methodMetadata.Parameters) { parameterOrderingBuilder.Add(fieldMetadata.Id, argumentPosition++); } _thriftParameterIdToCSharpArgument = parameterOrderingBuilder.ToImmutableDictionary(); var exceptions = ImmutableDictionary.CreateBuilder <Type, ExceptionProcessor>(); foreach (var entry in methodMetadata.Exceptions) { ExceptionProcessor processor = new ExceptionProcessor(entry.Key, codecManager.GetCodec(entry.Value)); exceptions.Add(entry.Value.CSharpType, processor); } this._exceptionCodecs = exceptions.ToImmutableDictionary(); this._successCodec = codecManager.GetCodec(methodMetadata.ReturnType); }
public byte[] Serialize <TObject>(TObject s) { byte[] objectBytes = null; var codec = _thriftCodecManager.GetCodec(typeof(TObject)) as IThriftCodec; using (var outs = new MemoryStream()) { using (var tt = new TStreamTransport(null, outs)) { using (var protocol = this.GetProtocol(tt)) { codec.WriteObject(s, protocol); objectBytes = outs.ToArray(); } } } return(objectBytes); }
protected AbstractReflectionThriftCodec(ThriftCodecManager manager, ThriftStructMetadata metadata) { Guard.ArgumentNotNull(manager, nameof(manager)); Guard.ArgumentNotNull(metadata, nameof(metadata)); this._metadata = metadata; _fields = new SortedDictionary <short, IThriftCodec>(); foreach (ThriftFieldMetadata fieldMetadata in metadata.GetFields(FieldKind.ThriftField)) { _fields.Add(fieldMetadata.Id, manager.GetCodec(fieldMetadata.ThriftType)); } }