Esempio n. 1
0
        private void ReadWriteArray <T>(ref T[] data) where T : IBitcoinSerializable
        {
            if (data == null && Serializing)
            {
                throw new ArgumentNullException("Impossible to serialize a null array");
            }
            var length = new VarInt(data == null ? 0 : (ulong)data.Length);

            ReadWrite(ref length);

            if (length.ToLong() > (uint)MaxArraySize)
            {
                throw new ArgumentOutOfRangeException("Array size not big");
            }
            if (!Serializing)
            {
                data = new T[length.ToLong()];
            }
            for (int i = 0; i < data.Length; i++)
            {
                T obj = data[i];
                ReadWrite(ref obj);
                data[i] = obj;
            }
        }
Esempio n. 2
0
 public void ReadWriteAsVarInt(ref ulong val)
 {
     var value = new VarInt(val);
     ReadWrite(ref value);
     if(!Serializing)
         val = value.ToLong();
 }
Esempio n. 3
0
 public void ReadWrite(BitcoinStream stream)
 {
     var len = new VarInt((ulong)_Bytes.Length);
      stream.ReadWrite(ref len);
     if(!stream.Serializing)
         _Bytes = new byte[len.ToLong()];
     stream.ReadWrite(ref _Bytes);
 }
Esempio n. 4
0
        public void ReadWrite(BitcoinStream stream)
        {
            var len = new VarInt((ulong)_Bytes.Length);

            stream.ReadWrite(ref len);
            if (!stream.Serializing)
            {
                _Bytes = new byte[len.ToLong()];
            }
            stream.ReadWrite(ref _Bytes);
        }
Esempio n. 5
0
        /// <summary>
        /// Creates a new Golomb-Rice filter from the data byte array which
        /// contains a serialized filter.
        /// </summary>
        /// <param name="data">A serialized Golomb-Rice filter.</param>
        /// <param name="p">The P value to use.</param>
        public GolombRiceFilter(byte[] data, byte p)
        {
            P = p;
            var n      = new VarInt();
            var stream = new BitcoinStream(data);

            stream.ReadWrite(ref n);
            N = (int)n.ToLong();
            var l = n.ToBytes().Length;

            Data = data.SafeSubarray(l);
        }