public ClientStreamingResult(AsyncClientStreamingCall <byte[], byte[]> inner, IClientStreamWriter <TRequest> requestStream, MessagePackSerializerOptions serializerOptions) { this.hasRawValue = false; this.rawValue = default(TResponse); this.inner = inner; this.requestStream = requestStream; this.serializerOptions = serializerOptions; }
public Int16 Deserialize(ref MessagePackReader reader, MessagePackSerializerOptions options) { return(reader.ReadInt16()); }
public T[] Deserialize(ref MessagePackReader reader, MessagePackSerializerOptions options) { if (reader.TryReadNil()) { return(default);
public MessagePackInputFormatter(MessagePackSerializerOptions options) { this.options = options; SupportedMediaTypes.Add(ContentType); }
/// <summary> /// Initializes a new instance of the <see cref="MessagePackMediaTypeFormatter" /> class. /// </summary> /// <param name="options">Options for running serialization.</param> public MessagePackMediaTypeFormatter(MessagePackSerializerOptions options) { SerializerOptions = options ?? throw new ArgumentNullException(nameof(options)); SupportedMediaTypes.Add(MessagePackDefaults.MediaTypeHeaders.ApplicationXMessagePack); SupportedMediaTypes.Add(MessagePackDefaults.MediaTypeHeaders.ApplicationMessagePack); }
string IMessagePackFormatter <string> .Deserialize(ref MessagePackReader reader, MessagePackSerializerOptions options) { var str = reader.ReadString(); if (str == null) { return(null); } return(string.Intern(str)); }
public MessagePackSerializer(MessagePackSerializerOptions options = null) { _options = options; }
public void Serialize(ref MessagePackWriter writer, ExecutionId value, MessagePackSerializerOptions options) { options.Resolver.GetFormatterWithVerify <System.Guid>().Serialize(ref writer, value.value, options); }
public ExecutionId Deserialize(ref MessagePackReader reader, MessagePackSerializerOptions options) { return(new ExecutionId(options.Resolver.GetFormatterWithVerify <System.Guid>().Deserialize(ref reader, options))); }
public void Serialize(ref MessagePackWriter writer, PublicKey value, MessagePackSerializerOptions options) { writer.Write(value.Format(true)); }
static NativeDateTimeResolver() { Instance = new NativeDateTimeResolver(); Options = new MessagePackSerializerOptions(Instance); }
public void Serialize(ref MessagePackWriter writer, LevelEditorComponentData value, MessagePackSerializerOptions options) { if (value.type == null) { writer.WriteNil(); return; } writer.WriteArrayHeader(2); writer.WriteInt32(value.type.FullName.GetStableHashCode()); ((LevelEditorResolver)LevelEditorResolver.instance).SerializeWrapper(ref writer, value.wrapper, options); }
public Result <T> Deserialize(ref MessagePackReader reader, MessagePackSerializerOptions options) { if (reader.IsNil) { return(default);
public void Serialize(ref MessagePackWriter writer, FungibleAssetValue value, MessagePackSerializerOptions options) { writer.Write(new Codec().Encode(value.Serialize())); }
public MarshallingAsyncStreamReader(IAsyncStreamReader <byte[]> inner, MessagePackSerializerOptions options) { this.inner = inner; this.options = options; }
public void Serialize(ref MessagePackWriter writer, ImmutableArray <T> value, MessagePackSerializerOptions options) { if (value.IsDefault) { writer.WriteNil(); } else if (value.IsEmpty) { writer.WriteArrayHeader(0); } else { IMessagePackFormatter <T> formatter = options.Resolver.GetFormatterWithVerify <T>(); writer.WriteArrayHeader(value.Length); foreach (T item in value) { formatter.Serialize(ref writer, item, options); } } }
public MarshallingClientStreamWriter(IClientStreamWriter <byte[]> inner, MessagePackSerializerOptions options) { this.inner = inner; this.options = options; }
public ImmutableArray <T> Deserialize(ref MessagePackReader reader, MessagePackSerializerOptions options) { if (reader.TryReadNil()) { return(default);
void IMessagePackFormatter <string> .Serialize(ref MessagePackWriter writer, string value, MessagePackSerializerOptions options) { throw new NotImplementedException(); }
static ContractlessStandardResolverAllowPrivate() { Instance = new ContractlessStandardResolverAllowPrivate(); Options = new MessagePackSerializerOptions(Instance); }
public T[,,,] Deserialize(ref MessagePackReader reader, MessagePackSerializerOptions options) { if (reader.TryReadNil()) { return(null); } else { IMessagePackFormatter <T> formatter = options.Resolver.GetFormatterWithVerify <T>(); var len = reader.ReadArrayHeader(); if (len != ArrayLength) { throw new MessagePackSerializationException("Invalid T[,,,] format"); } var iLength = reader.ReadInt32(); var jLength = reader.ReadInt32(); var kLength = reader.ReadInt32(); var lLength = reader.ReadInt32(); var maxLen = reader.ReadArrayHeader(); var array = new T[iLength, jLength, kLength, lLength]; var i = 0; var j = 0; var k = 0; var l = -1; options.Security.DepthStep(ref reader); try { for (int loop = 0; loop < maxLen; loop++) { reader.CancellationToken.ThrowIfCancellationRequested(); if (l < lLength - 1) { l++; } else if (k < kLength - 1) { l = 0; k++; } else if (j < jLength - 1) { l = 0; k = 0; j++; } else { l = 0; k = 0; j = 0; i++; } array[i, j, k, l] = formatter.Deserialize(ref reader, options); } } finally { reader.Depth--; } return(array); } }
static StandardResolver() { Instance = new StandardResolver(); Options = new MessagePackSerializerOptions(Instance); }
public RawImporter(IServiceProvider services) : base(services) { _msgpackOpts = services.GetRequiredService <MessagePackSerializerOptions>(); _db = services.GetRequiredService <Database>(); }
public TransformSyncMessageHandler(IMessageHandler <TMessage> handler, MessagePackSerializerOptions options) { this.handler = handler; this.options = options; }
public void Serialize(ref MessagePackWriter writer, Int16 value, MessagePackSerializerOptions options) { writer.WriteInt16(value); }
public MethodHandler(Type classType, MethodInfo methodInfo, string methodName, MethodHandlerOptions handlerOptions) { this.methodHandlerId = Interlocked.Increment(ref methodHandlerIdBuild); var serviceInterfaceType = classType.GetInterfaces().First(x => x.GetTypeInfo().IsGenericType&& x.GetGenericTypeDefinition() == typeof(IService <>)).GetGenericArguments()[0]; this.ServiceType = classType; this.ServiceName = serviceInterfaceType.Name; this.MethodInfo = methodInfo; this.MethodName = methodName; MethodType mt; this.UnwrappedResponseType = UnwrapResponseType(methodInfo, out mt, out responseIsTask, out this.RequestType); this.MethodType = mt; this.serializerOptions = handlerOptions.SerializerOptions; var parameters = methodInfo.GetParameters(); if (RequestType == null) { var resolver = this.serializerOptions.Resolver; this.RequestType = MagicOnionMarshallers.CreateRequestTypeAndSetResolver(classType.Name + "/" + methodInfo.Name, parameters, ref resolver); this.serializerOptions = this.serializerOptions.WithResolver(resolver); } this.AttributeLookup = classType.GetCustomAttributes(true) .Concat(methodInfo.GetCustomAttributes(true)) .Cast <Attribute>() .ToLookup(x => x.GetType()); this.filters = handlerOptions.GlobalFilters .OfType <IMagicOnionFilterFactory <MagicOnionFilterAttribute> >() .Concat(classType.GetCustomAttributes <MagicOnionFilterAttribute>(true).Select(x => new MagicOnionServiceFilterDescriptor(x, x.Order))) .Concat(classType.GetCustomAttributes(true).OfType <IMagicOnionFilterFactory <MagicOnionFilterAttribute> >()) .Concat(methodInfo.GetCustomAttributes <MagicOnionFilterAttribute>(true).Select(x => new MagicOnionServiceFilterDescriptor(x, x.Order))) .Concat(methodInfo.GetCustomAttributes(true).OfType <IMagicOnionFilterFactory <MagicOnionFilterAttribute> >()) .OrderBy(x => x.Order) .ToArray(); // options this.isReturnExceptionStackTraceInErrorDetail = handlerOptions.IsReturnExceptionStackTraceInErrorDetail; this.logger = handlerOptions.Logger; this.enableCurrentContext = handlerOptions.EnableCurrentContext; this.serviceLocator = handlerOptions.ServiceLocator; this.serviceActivator = handlerOptions.ServiceActivator; // prepare lambda parameters var createServiceMethodInfo = createService.MakeGenericMethod(classType, serviceInterfaceType); var contextArg = Expression.Parameter(typeof(ServiceContext), "context"); var instance = Expression.Call(createServiceMethodInfo, contextArg); switch (MethodType) { case MethodType.Unary: case MethodType.ServerStreaming: // (ServiceContext context) => // { // var request = MessagePackSerializer.Deserialize<T>(context.Request, context.SerializerOptions, default); // var result = new FooService() { Context = context }.Bar(request.Item1, request.Item2); // return MethodHandlerResultHelper.SerializeUnaryResult(result, context); // }; try { var flags = BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic; var staticFlags = BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic; var requestArg = Expression.Parameter(RequestType, "request"); var getSerializerOptions = Expression.Property(contextArg, typeof(ServiceContext).GetProperty("SerializerOptions", flags)); var defaultToken = Expression.Default(typeof(CancellationToken)); var contextRequest = Expression.Property(contextArg, typeof(ServiceContext).GetProperty("Request", flags)); var callDeserialize = Expression.Call(messagePackDeserialize.MakeGenericMethod(RequestType), contextRequest, getSerializerOptions, defaultToken); var assignRequest = Expression.Assign(requestArg, callDeserialize); Expression[] arguments = new Expression[parameters.Length]; if (parameters.Length == 1) { arguments[0] = requestArg; } else { for (int i = 0; i < parameters.Length; i++) { arguments[i] = Expression.Field(requestArg, "Item" + (i + 1)); } } var callBody = Expression.Call(instance, methodInfo, arguments); if (MethodType == MethodType.Unary) { var finalMethod = (responseIsTask) ? typeof(MethodHandlerResultHelper).GetMethod("SerializeTaskUnaryResult", staticFlags).MakeGenericMethod(UnwrappedResponseType) : typeof(MethodHandlerResultHelper).GetMethod("SerializeUnaryResult", staticFlags).MakeGenericMethod(UnwrappedResponseType); callBody = Expression.Call(finalMethod, callBody, contextArg); } else { if (!responseIsTask) { callBody = Expression.Call(typeof(MethodHandlerResultHelper) .GetMethod(nameof(MethodHandlerResultHelper.NewEmptyValueTask), staticFlags) .MakeGenericMethod(MethodInfo.ReturnType), callBody); } else { callBody = Expression.Call(typeof(MethodHandlerResultHelper) .GetMethod(nameof(MethodHandlerResultHelper.TaskToEmptyValueTask), staticFlags) .MakeGenericMethod(MethodInfo.ReturnType.GetGenericArguments()[0]), callBody); } } var body = Expression.Block(new[] { requestArg }, assignRequest, callBody); var compiledBody = Expression.Lambda(body, contextArg).Compile(); this.methodBody = BuildMethodBodyWithFilter((Func <ServiceContext, ValueTask>)compiledBody); } catch (Exception ex) { throw new InvalidOperationException($"Can't create handler. Path:{ToString()}", ex); } break; case MethodType.ClientStreaming: case MethodType.DuplexStreaming: if (parameters.Length != 0) { throw new InvalidOperationException($"{MethodType} does not support method parameters. If you need to send initial parameter, use header instead. Path:{ToString()}"); } // (ServiceContext context) => new FooService() { Context = context }.Bar(); try { var body = Expression.Call(instance, methodInfo); var staticFlags = BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic; if (MethodType == MethodType.ClientStreaming) { var finalMethod = (responseIsTask) ? typeof(MethodHandlerResultHelper).GetMethod("SerializeTaskClientStreamingResult", staticFlags).MakeGenericMethod(RequestType, UnwrappedResponseType) : typeof(MethodHandlerResultHelper).GetMethod("SerializeClientStreamingResult", staticFlags).MakeGenericMethod(RequestType, UnwrappedResponseType); body = Expression.Call(finalMethod, body, contextArg); } else { if (!responseIsTask) { body = Expression.Call(typeof(MethodHandlerResultHelper) .GetMethod(nameof(MethodHandlerResultHelper.NewEmptyValueTask), staticFlags) .MakeGenericMethod(MethodInfo.ReturnType), body); } else { body = Expression.Call(typeof(MethodHandlerResultHelper) .GetMethod(nameof(MethodHandlerResultHelper.TaskToEmptyValueTask), staticFlags) .MakeGenericMethod(MethodInfo.ReturnType.GetGenericArguments()[0]), body); } } var compiledBody = Expression.Lambda(body, contextArg).Compile(); this.methodBody = BuildMethodBodyWithFilter((Func <ServiceContext, ValueTask>)compiledBody); } catch (Exception ex) { throw new InvalidOperationException($"Can't create handler. Path:{ToString()}", ex); } break; default: throw new InvalidOperationException("Unknown MethodType:" + MethodType + $"Path:{ToString()}"); } }
public void Serialize(ref MessagePackWriter writer, PackageSourceUpdateOptions?value, MessagePackSerializerOptions options) #pragma warning restore CS0618 // Type or member is obsolete { if (value == null) { writer.WriteNil(); return; } writer.WriteMapHeader(count: 2); writer.Write(UpdateCredentialsPropertyName); writer.Write(value.UpdateCredentials); writer.Write(UpdateEnabledPropertyName); writer.Write(value.UpdateEnabled); }
public static T Create <T>(GrpcChannel channel, MessagePackSerializerOptions serializerOptions) where T : IService <T> { return(Create <T>(channel.CreateCallInvoker(), serializerOptions, emptyFilters)); }
public void Serialize(ref MessagePackWriter writer, DateOnly value, MessagePackSerializerOptions options) => writer.Write(value.DayNumber);
public RgbaFloat Deserialize(ref MessagePackReader reader, MessagePackSerializerOptions options) { return(new RgbaFloat((float)reader.ReadDouble(), (float)reader.ReadDouble(), (float)reader.ReadDouble(), (float)reader.ReadDouble())); }