/// <summary>Decodes the given byte array into a PipelineMessage object</summary> /// <param name="data"></param> /// <returns>the decoded PipelineMessage object</returns> public PipelineMessage <T> Decode(byte[] data) { var message = BaseCodec.Decode(data.Take(data.Length - sizeof(bool)).ToArray()); var isLast = BitConverter.ToBoolean(data, data.Length - sizeof(bool)); return(new PipelineMessage <T>(message, isLast)); }
/// <summary>Encodes the given object into a Byte Array</summary> /// <param name="obj"></param> /// <returns>a byte[] representation of the object</returns> public byte[] Encode(PipelineMessage <T> obj) { var baseCoding = BaseCodec.Encode(obj.Data); var result = new byte[baseCoding.Length + sizeof(bool)]; Buffer.BlockCopy(baseCoding, 0, result, 0, baseCoding.Length); Buffer.BlockCopy(BitConverter.GetBytes(obj.IsLast), 0, result, baseCoding.Length, sizeof(bool)); return(result); }