Ejemplo n.º 1
0
        /// <summary>Decode a byte array into an object.</summary>
        /// <param name="bytes">The byte array.</param>
        /// <returns>The newly created object</returns>
        public static object DecodeData(byte[] bytes)
        {
            MemoryStream memStream = new MemoryStream(bytes);

            memStream.Seek(4, SeekOrigin.Begin);
            return(ReflectionUtilities.BinaryDeserialise(memStream));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Get an object from the specified anonymous in pipe.
        /// </summary>
        /// <param name="pipeReader">The pipe to read from.</param>
        /// <returns>The object or null if no object read.</returns>
        public static object GetObjectFromPipe(AnonymousPipeServerStream pipeReader)
        {
            // Read number of bytes.
            var intBuffer = new byte[4];

            pipeReader.Read(intBuffer, 0, 4);
            var numBytes = BitConverter.ToInt32(intBuffer, 0);

            if (numBytes > 0)
            {
                // Read bytes for object.
                var buffer = new byte[numBytes];
                pipeReader.Read(buffer, 0, numBytes);

                // Convert bytes to object.
                return(ReflectionUtilities.BinaryDeserialise(new MemoryStream(buffer)));
            }
            return(null);
        }
Ejemplo n.º 3
0
 private static object DeserialiseFrom(Stream stream)
 {
     // Decode from base64, then deserialise the result.
     using (Stream cryptoStream = new CryptoStream(stream, new FromBase64Transform(), CryptoStreamMode.Read, leaveOpen: true))
         return(ReflectionUtilities.BinaryDeserialise(cryptoStream));
 }