public static byte[] Serialize(object obj, IPayloadSerializer serializer)
 {
     using (var ms = MemoryManager.Instance.GetStream())
     {
         serializer.Serialize(obj, ms, out _);
         return(ms.ToArray());
     }
 }
        /// <summary>
        /// Serializes the request to a byte buffer.
        /// </summary>
        /// <returns></returns>
        byte[] PrepareRequestBuffer()
        {
            using (var ms = new MemoryStream())
            {
                serializer.Serialize(ms, request);

                return(WireFormat.GetBytes(method, ms));
            }
        }
Esempio n. 3
0
        public async Task SendAsync(IEventMessage message)
        {
            ISubscriber subscriber = _connection
                                     .GetSubscriber();

            string channel = message.Event.ToString();

            byte[] payload = _serializer.Serialize(message.Payload);

            await subscriber.PublishAsync(channel, payload)
            .ConfigureAwait(false);
        }
Esempio n. 4
0
        /// <summary>
        ///     Message have been queued etc and are now OK for delivery
        /// </summary>
        /// <param name="frame"></param>
        private void DeliverMessage(MessageFrame frame)
        {
            //_extensionService.Prepare(frame, _connection);
            if (frame.Payload != null && _payloadDotNetType != frame.Payload.GetType())
            {
                _payloadDotNetType = frame.Payload.GetType();
                var dotNetFrame = _extensionService.CreateFrame("dotnet", _payloadDotNetType);
                _connection.SendMore(dotNetFrame);
            }
            if (_payloadSerializer != null)
            {
                _payloadSerializer.Serialize(frame);
            }

            _connection.Send(frame);
        }
Esempio n. 5
0
        private void ProducerLoop()
        {
            while (true)
            {
                var dto = PayloadDto.Create();
                lock (_lock)
                {
                    var serialized = _serializer.Serialize(dto);

                    Console.WriteLine("Original data:");
                    Console.WriteLine("{0}", dto);

                    _queue.Enqueue(serialized);
                    Monitor.Pulse(_lock);
                }
                Thread.Sleep(5000);
            }
        }
Esempio n. 6
0
        public Task Raise <TEvent>(TEvent evt) where TEvent : IEvent
        {
            if (evt == null)
            {
                throw new ArgumentNullException(nameof(evt));
            }

            var publishableAttr = evt.GetPublishableAttributes();

            var messageId = Guid.Empty.Equals(CorrelationIdAccessor.CorrelationId)
                ? Guid.NewGuid()
                : CorrelationIdAccessor.CorrelationId;

            var payload = _serializer.Serialize(evt);

            var message = new Message(messageId, publishableAttr.Label, publishableAttr.Version, evt.GetType().AssemblyQualifiedName, payload);

            return(_messagePublisher.Publish(publishableAttr.DestName, publishableAttr.Type, message));
        }
Esempio n. 7
0
 public void PreSerialize(IPayloadSerializer serializer, Stream stream)
 {
     lock (Event)
     {
         if ((Objects?.Length ?? 0) > 0)
         {
             Arguments = new byte[Objects.Length][];
             using (var mm = MemoryManager.Instance.GetStream())
             {
                 int i = 0;
                 foreach (var a in Objects)
                 {
                     mm.SetLength(0);
                     serializer.Serialize(a, mm, out _);
                     Arguments[i++] = mm.ToArray();
                 }
             }
         }
     }
 }
Esempio n. 8
0
        private void DeliverMessage(MessageFrame frame)
        {
            frame.SequenceNumber = ++_sequenceCounter;
            if (_sequenceCounter == ushort.MaxValue)
            {
                _sequenceCounter = 0;
            }

            if (frame.Payload != null && _payloadSerializer != null)
            {
                _payloadSerializer.Serialize(frame);
                if (_dotNetExtension != null && _outboundDotNetType != frame.Payload.GetType())
                {
                    _outboundDotNetType = frame.Payload.GetType();
                    var dotNetFrame = _extensionService.CreateFrame("dotnet", _outboundDotNetType);
                    _connection.SendMore(dotNetFrame);
                }
            }
            _connection.Send(frame);
        }
Esempio n. 9
0
 public ChainItem(TPayload payload)
     : base(Serializer.Serialize(payload))
 {
 }
 public ArraySegment <byte> Serialize(T message)
 {
     return(_serializer.Serialize(message, message));
 }