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); }
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()); }
protected abstract void ApplyToMessageContent(ref MessageContent content);
protected void ResetStateWorker() { _currentStateWorker = _initialStateFactory(); _content = new MessageContent(); }