Esempio n. 1
0
        /// <summary>
        ///     Initializes a new instance of the <see cref="Fingerprint"/> struct.
        /// </summary>
        public Fingerprint(int length, BinaryReader reader)
        {
            unchecked {
                _length = (byte)length;
            }

            _bytes = ReadOnlyFixedBytes.ReadFrom(reader, length);
        }
Esempio n. 2
0
        /// <summary>
        ///     Initializes a new instance of the <see cref="Fingerprint"/> struct.
        /// </summary>
        public static Fingerprint Deserialize(BinaryReader reader)
        {
            Contract.Requires(reader != null);
            var length = reader.ReadByte();
            var buffer = ReadOnlyFixedBytes.ReadFrom(reader, length);

            return(new Fingerprint(buffer, length));
        }
 public void FixedBytesShouldNotFailOnEmptyStream()
 {
     // The following code should not fail.
     using (var ms = new MemoryStream(new byte[0]))
     {
         using (var reader = new BinaryReader(ms))
         {
             var fb = ReadOnlyFixedBytes.ReadFrom(reader);
             Assert.Equal(fb[0], 0);
         }
     }
 }
        public void BinaryRoundtrip()
        {
            using (var ms = new MemoryStream())
            {
                using (var writer = new BinaryWriter(ms))
                {
                    var v1 = ReadOnlyFixedBytes.Random();
                    v1.Serialize(writer);
                    ms.Position = 0;

                    using (var reader = new BinaryReader(ms))
                    {
                        var v2 = ReadOnlyFixedBytes.ReadFrom(reader);
                        Assert.Equal(v1, v2);
                    }
                }
            }
        }
        public void RoundtripShortHashBinary(HashType hashType)
        {
            using (var ms = new MemoryStream())
            {
                using (var writer = new BinaryWriter(ms))
                {
                    var h1         = ContentHash.Random(hashType);
                    var shortHash1 = new ShortHash(h1);
                    shortHash1.Serialize(writer);
                    Assert.Equal(ShortHash.SerializedLength, ms.Length);
                    ms.Position = 0;

                    using (var reader = new BinaryReader(ms))
                    {
                        var shortHash2 = new ShortHash(ReadOnlyFixedBytes.ReadFrom(reader, ShortHash.SerializedLength));
                        Assert.Equal(hashType, shortHash2.HashType);
                        Assert.Equal(shortHash1.ToString(), shortHash2.ToString());
                    }
                }
            }
        }
Esempio n. 6
0
 /// <summary>
 ///     Initializes a new instance of the <see cref="Fingerprint"/> struct.
 /// </summary>
 public Fingerprint(BinaryReader reader)
 {
     Console.WriteLine(reader != null);
     _length = reader.ReadByte();
     _bytes  = ReadOnlyFixedBytes.ReadFrom(reader, _length);
 }