Exemplo n.º 1
0
        public void WriteToStreamTest(byte[] data, int finalOffset, ulong val)
        {
            CompactInt ci     = new CompactInt(val);
            FastStream stream = new FastStream(10);

            ci.WriteToStream(stream);

            byte[] actual   = stream.ToByteArray();
            byte[] expected = new byte[finalOffset];
            Buffer.BlockCopy(data, 0, expected, 0, finalOffset);

            Assert.Equal(expected, actual);
        }
Exemplo n.º 2
0
        public void AddSerializedSizeTest(ulong val, int init, int expected)
        {
            var ci      = new CompactInt(val);
            var counter = new SizeCounter(init);

            ci.AddSerializedSize(counter);

            var stream = new FastStream(10);

            ci.WriteToStream(stream);
            Assert.Equal(expected, stream.GetSize() + init);

            Assert.Equal(expected, counter.Size);
        }
Exemplo n.º 3
0
        /// <inheritdoc/>
        public override void Serialize(FastStream stream)
        {
            CompactInt count = new CompactInt(Headers.Length);

            count.WriteToStream(stream);
            foreach (var hd in Headers)
            {
                hd.SerializeHeader(stream);
                // Block serialization of header doesn't add tx count since there is no need for it.
                // However, in a header payload (for unknown reason) one extra byte indicating zero tx count
                // is added to each block header.
                stream.Write((byte)0);
            }
        }
Exemplo n.º 4
0
        public void AddCompactIntCountTest(int init, int add)
        {
            var counter = new SizeCounter(init);

            counter.AddCompactIntCount(add);

            var ci     = new CompactInt(add);
            var stream = new FastStream(9);

            ci.WriteToStream(stream);
            int expected = stream.GetSize() + init;

            Assert.Equal(expected, counter.Size);
        }
Exemplo n.º 5
0
 /// <inheritdoc/>
 public void Serialize(FastStream stream)
 {
     if (Items == null || Items.Length == 0)
     {
         stream.Write((byte)0);
     }
     else
     {
         CompactInt count = new CompactInt(Items.Length);
         count.WriteToStream(stream);
         foreach (var item in Items)
         {
             item.WriteToWitnessStream(stream);
         }
     }
 }