Equivalent of System.BitConverter, but with either endianness.
Exemplo n.º 1
0
        /// <summary>
        /// Constructs a new binary reader with the given bit converter, reading
        /// to the given stream, using the given encoding.
        /// </summary>
        /// <param name="bitConverter">Converter to use when reading data</param>
        /// <param name="stream">Stream to read data from</param>
        /// <param name="encoding">Encoding to use when reading character data</param>
        public EndianBinaryReader(EndianBitConverter bitConverter, Stream stream, Encoding encoding)
        {
            if (bitConverter == null)
            {
                throw new ArgumentNullException("bitConverter");
            }
            if (stream == null)
            {
                throw new ArgumentNullException("stream");
            }
            if (encoding == null)
            {
                throw new ArgumentNullException("encoding");
            }
            if (!stream.CanRead)
            {
                throw new ArgumentException("Stream isn't writable", "stream");
            }
            this.stream = stream;
            this.bitConverter = bitConverter;
            this.encoding = encoding;
            this.decoder = encoding.GetDecoder();
            this.minBytesPerChar = 1;

            if (encoding is UnicodeEncoding)
            {
                minBytesPerChar = 2;
            }
        }
Exemplo n.º 2
0
 /// <summary>
 /// Constructs a new binary writer with the given bit converter, writing
 /// to the given stream, using the given encoding.
 /// </summary>
 /// <param name="bitConverter">Converter to use when writing data</param>
 /// <param name="stream">Stream to write data to</param>
 /// <param name="encoding">Encoding to use when writing character data</param>
 public EndianBinaryWriter(EndianBitConverter bitConverter, Stream stream, Encoding encoding)
 {
     if (bitConverter == null)
     {
         throw new ArgumentNullException("bitConverter");
     }
     if (stream == null)
     {
         throw new ArgumentNullException("stream");
     }
     if (encoding == null)
     {
         throw new ArgumentNullException("encoding");
     }
     if (!stream.CanWrite)
     {
         throw new ArgumentException("Stream isn't writable", "stream");
     }
     this.stream = stream;
     this.bitConverter = bitConverter;
     this.encoding = encoding;
 }
Exemplo n.º 3
0
 /// <summary>
 /// Constructs a new binary writer with the given bit converter, writing
 /// to the given stream, using UTF-8 encoding.
 /// </summary>
 /// <param name="bitConverter">Converter to use when writing data</param>
 /// <param name="stream">Stream to write data to</param>
 public EndianBinaryWriter(EndianBitConverter bitConverter,
     Stream stream)
     : this(bitConverter, stream, Encoding.UTF8)
 {
 }