コード例 #1
0
        /// <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));
        }
コード例 #2
0
        /// <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);
        }