public ValueTask <Stream?> SerializeAsync( object?message, MessageHeaderCollection messageHeaders, MessageSerializationContext context) { throw new NotSupportedException(); }
public ValueTask <Stream?> SerializeAsync( object?message, MessageHeaderCollection messageHeaders, MessageSerializationContext context) { Check.NotNull(messageHeaders, nameof(messageHeaders)); if (message == null) { return(ValueTaskFactory.FromResult <Stream?>(null)); } if (message is Stream inputStream) { return(ValueTaskFactory.FromResult <Stream?>(inputStream)); } if (message is byte[] inputBytes) { return(ValueTaskFactory.FromResult <Stream?>(new MemoryStream(inputBytes))); } var binaryFileMessage = message as IBinaryFileMessage; if (binaryFileMessage == null) { throw new ArgumentException( "The message is not implementing the IBinaryFileMessage interface.", nameof(message)); } return(ValueTaskFactory.FromResult(binaryFileMessage.Content)); }
public byte[]? Serialize( object?message, MessageHeaderCollection messageHeaders, MessageSerializationContext context) => new byte[] { 0, 1, 2, 3, 4 };
public ValueTask <(object?Message, Type MessageType)> DeserializeAsync( Stream?messageStream, MessageHeaderCollection messageHeaders, MessageSerializationContext context) { var binaryFileMessage = new TModel { Content = messageStream }; return(ValueTaskFactory.FromResult <(object?, Type)>((binaryFileMessage, _type))); }
public (object?, Type) Deserialize( byte[]?message, MessageHeaderCollection messageHeaders, MessageSerializationContext context) { var deserialized = message != null ? JsonConvert.DeserializeObject <LegacyMessage>(Encoding.ASCII.GetString(message)) : null; return(deserialized, typeof(LegacyMessage)); }
public ValueTask <(object?Message, Type MessageType)> DeserializeAsync( Stream?messageStream, MessageHeaderCollection messageHeaders, MessageSerializationContext context) { var wrapper = new RawMessage { Content = messageStream.ReadAll() }; return(ValueTask.FromResult(((object?)wrapper, typeof(RawMessage)))); }
public ValueTask <(object?Message, Type MessageType)> DeserializeAsync( Stream?messageStream, MessageHeaderCollection messageHeaders, MessageSerializationContext context) { if (MustFailCount > FailCount) { FailCount++; throw new InvalidOperationException("Test failure"); } return(new JsonMessageSerializer().DeserializeAsync(messageStream, messageHeaders, context)); }
public ValueTask <(object?, Type)> DeserializeAsync( Stream?messageStream, MessageHeaderCollection messageHeaders, MessageSerializationContext context) { Check.NotNull(messageHeaders, nameof(messageHeaders)); var type = SerializationHelper.GetTypeFromHeaders(messageHeaders, false) ?? typeof(BinaryFileMessage); var messageModel = (IBinaryFileMessage)Activator.CreateInstance(type); messageModel.Content = messageStream; return(ValueTaskFactory.FromResult <(object?, Type)>((messageModel, type))); }
public Task <(object?, Type)> DeserializeAsync( byte[]?message, MessageHeaderCollection messageHeaders, MessageSerializationContext context) =>
public Task <byte[]?> SerializeAsync( object?message, MessageHeaderCollection messageHeaders, MessageSerializationContext context) => Task.FromResult(Serialize(message, messageHeaders, context));
public byte[]? Serialize( object?message, MessageHeaderCollection messageHeaders, MessageSerializationContext context) => Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(message, _settings));
public Task <(object?, Type)> DeserializeAsync( byte[]?message, MessageHeaderCollection messageHeaders, MessageSerializationContext context) => throw new NotImplementedException();