public IMessage Deserialize(byte[] message) { var dict = BasicDictionarySerializer.Deserialize(message); var type = this.GetType().Assembly.GetTypes().Where(x => x.AssemblyQualifiedName == dict.Keys.First()).Single(); return(Newtonsoft.Json.JsonConvert.DeserializeObject(dict.Values.First(), type) as IMessage); }
public IEnumerable <BasicMessage> ToMessage(IEnumerable <Frame> frames) { foreach (var frame in frames) { if (frame.Type == FrameType.BodyFrame) { Dictionary <string, string> headers = new Dictionary <string, string>(); if (collectedFrames.Count > 0) { var frameHeader = collectedFrames.Dequeue(); headers = BasicDictionarySerializer.Deserialize(frameHeader.ReadPayload()); } yield return(new BasicMessage(frame.ReadPayload(), headers)); collectedFrames.Clear();//If there are errored messages where there are only headers and no body. We expect the body frame to be the last frame } else { collectedFrames.Enqueue(frame); } } }