示例#1
0
        public static void WriteObject <T> (this PipeStream pipeStream, T obj)
        {
            var stream = ObjectStreamer.SerializeToStream(obj);

            byte[] msgBuff = stream.ToArray();
            pipeStream.Write(msgBuff, 0, msgBuff.Length);
        }
示例#2
0
        public static T ReadObject <T>(this PipeStream pipeStream) where T : class
        {
            int BUFFSIZE    = 1024;
            int byteCount   = 0;
            var msgBuff     = new byte[BUFFSIZE];
            var fullMessage = new List <byte>();

            do
            {
                byteCount = pipeStream.Read(msgBuff, 0, BUFFSIZE);
                fullMessage.AddRange(msgBuff);
            } while (!(pipeStream.IsMessageComplete));


            MemoryStream stream = new MemoryStream(fullMessage.ToArray());

            return(ObjectStreamer.DeserializeFromStream(stream) as T);
        }