Esempio n. 1
0
        public MessageContent Serialize(IMessage message)
        {
            var content = new MessageContent();

            var messageType = message.GetType();

            if (!_idBindings.ContainsKey(messageType))
            {
                throw new ArgumentException("Unknown message type");
            }

            var type = _idBindings[messageType];
            var body = message.GetBody();

            content.Type = type;
            content.Body = body;

            return(content);
        }
Esempio n. 2
0
        public byte[] ToBytes(MessageContent messageContent)
        {
            var written = 0;
            var stream  = new MemoryStream();

            var preparedBytes = PrepareStream(stream);

            written += preparedBytes;

            stream.WriteByte(messageContent.Type);
            written += 1;

            var body = messageContent.Body;

            written += PreBodyStream(stream, ref body);

            stream.Write(body, 0, body.Length);
            written += body.Length;

            written += AfterStream(stream);

            stream.Capacity = written;
            return(stream.GetBuffer());
        }
Esempio n. 3
0
 protected abstract void ApplyToMessageContent(ref MessageContent content);
Esempio n. 4
0
 protected void ResetStateWorker()
 {
     _currentStateWorker = _initialStateFactory();
     _content            = new MessageContent();
 }