/// <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); }
/// <summary> /// Writes the class fields to the writer. /// </summary> /// <param name="obj">The object to be encoded</param> /// <param name="writer">The writer to which to write</param> /// <param name="token">Cancellation token</param> public async System.Threading.Tasks.Task WriteAsync(PipelineMessage <T> obj, IDataWriter writer, CancellationToken token) { await BaseCodec.WriteAsync(obj.Data, writer, token); await writer.WriteBooleanAsync(obj.IsLast, token); }
/// <summary> /// Writes the class fields to the writer. /// </summary> /// <param name="obj">The object to be encoded</param> /// <param name="writer">The writer to which to write</param> public void Write(PipelineMessage <T> obj, IDataWriter writer) { BaseCodec.Write(obj.Data, writer); writer.WriteBoolean(obj.IsLast); }