public override Task <InputFormatterResult> ReadRequestBodyAsync(InputFormatterContext context) { IServiceProvider serviceProvider = context.HttpContext.RequestServices; MessagePackOptions options = serviceProvider.GetService(typeof(MessagePackOptions)) as MessagePackOptions; MessagePack.IFormatterResolver resolver = options?.Resolver; if (resolver == null) { return(InputFormatterResult.FailureAsync()); } Type actionModelType = context.ModelType; var serializerType = typeof(MessagePackSerializer); var deserializeMethod = serializerType.GetMethod("Deserialize", BindingFlags.Public | BindingFlags.Static, null, new Type[] { typeof(Stream), typeof(IFormatterResolver) }, null); deserializeMethod = deserializeMethod?.MakeGenericMethod(actionModelType); var streamParameter = Expression.Parameter(typeof(Stream), "stream"); var formatterResolver = Expression.Parameter(typeof(IFormatterResolver), "resolver"); var deserializationExpression = Expression.Call(deserializeMethod, streamParameter, formatterResolver); var lambda = Expression.Lambda <DeserializeMethod>(deserializationExpression, new ParameterExpression[] { streamParameter, formatterResolver }).Compile(); var request = context.HttpContext.Request; object instance = lambda(request.Body, resolver); return(InputFormatterResult.SuccessAsync(instance)); }
public override async Task WriteToStreamAsync(Type type, object value, Stream writeStream, HttpContent content, TransportContext transportContext) { MessagePack.IFormatterResolver resolver = options?.Resolver; MethodInfo genericMethod = this.GetType().GetMethod("Serialize").MakeGenericMethod(new Type[] { type }); byte[] responseBytes = genericMethod.Invoke(this, new object[] { value, resolver }) as byte[]; await writeStream.WriteAsync(responseBytes, 0, responseBytes.Length); }
public override Task WriteResponseBodyAsync(OutputFormatterWriteContext context) { IServiceProvider serviceProvider = context.HttpContext.RequestServices; MessagePackOptions options = serviceProvider.GetService(typeof(MessagePackOptions)) as MessagePackOptions; MessagePack.IFormatterResolver resolver = options?.Resolver; var response = context.HttpContext.Response; byte[] responseBytes = MessagePackSerializer.Serialize(context.Object, resolver); return(response.Body.WriteAsync(responseBytes, 0, responseBytes.Count())); }
public MemoryDatabase(byte[] databaseBinary, bool internString = true, MessagePack.IFormatterResolver formatterResolver = null) : base(databaseBinary, internString, formatterResolver) { }
public MemoryDatabase(byte[] databaseBinary, bool internString = true, MessagePack.IFormatterResolver formatterResolver = null, int maxDegreeOfParallelism = 1) : base(databaseBinary, internString, formatterResolver, maxDegreeOfParallelism) { }
public DatabaseBuilder(MessagePack.IFormatterResolver resolver) : base(resolver) { }
public RpcRequestMessage Deserialize(byte[] bytes, int offset, MsgPack.IFormatterResolver formatterResolver, out int readSize) { throw new NotImplementedException(); }
public int Serialize(ref byte[] bytes, int offset, RpcRequestMessage value, MsgPack.IFormatterResolver formatterResolver) { throw new NotImplementedException(); }
public byte[] Serialize <T>(T instance, MessagePack.IFormatterResolver resolver) { byte[] responseBytes = MessagePackSerializer.Serialize <T>(instance, resolver); return(responseBytes); }