Ejemplo n.º 1
0
        private void ReadWriteArray(ref uint[] data)
        {
            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 uint[length.ToLong()];
            }
            for (int i = 0; i < data.Length; i++)
            {
                uint obj = data[i];
                ReadWrite(ref obj);
                data[i] = obj;
            }
        }
Ejemplo n.º 2
0
        public virtual void ReadWrite(Serialize stream)
        {
            var len = new VarInt((ulong)_DestBytes.Length);

            stream.ReadWrite(ref len);
            if (!stream.Serializing)
            {
                if (len.ToLong() > (uint)stream.MaxArraySize)
                {
                    throw new ArgumentOutOfRangeException("Array size not big");
                }
                _DestBytes = new byte[len.ToLong()];
            }
            stream.ReadWrite(ref _DestBytes);
        }
Ejemplo n.º 3
0
#pragma warning disable CS0114 // '“UniversalContract.ReadWrite(Serialize)”隐藏继承的成员“SerializeObject.ReadWrite(Serialize)”。若要使当前成员重写该实现,请添加关键字 override。否则,添加关键字 new。
        public void ReadWrite(Serialize stream)
#pragma warning restore CS0114 // '“UniversalContract.ReadWrite(Serialize)”隐藏继承的成员“SerializeObject.ReadWrite(Serialize)”。若要使当前成员重写该实现,请添加关键字 override。否则,添加关键字 new。
        {
            var len = new VarInt((ulong)_DestBytes.Length);

            stream.ReadWrite(ref len);

            stream.ReadWrite(ref Upgradable);

            byte[] memo;
            byte[] abi;

            if (stream.Serializing)
            {
                stream.ReadWrite(new VarInt((ulong)Code.Length));
                stream.ReadWrite(ref Code);

                memo = Encoding.UTF8.GetBytes(Memo);
                stream.ReadWrite(new VarInt((ulong)memo.Length));
                stream.ReadWrite(ref memo);

                abi = Encoding.UTF8.GetBytes(Abi);
                stream.ReadWrite(new VarInt((ulong)abi.Length));
                stream.ReadWrite(ref abi);
            }
            else
            {
                var codeLen = new VarInt(0);
                stream.ReadWrite(ref codeLen);
                Code = new byte[codeLen.ToLong()];
                stream.ReadWrite(ref Code);

                var memoLen = new VarInt(0);
                stream.ReadWrite(ref memoLen);
                memo = new byte[codeLen.ToLong()];
                stream.ReadWrite(ref memo);

                var abiLen = new VarInt(0);
                stream.ReadWrite(ref abiLen);
                abi = new byte[codeLen.ToLong()];
                stream.ReadWrite(ref abi);

                Memo = Encoding.UTF8.GetString(memo);
                Abi  = Encoding.UTF8.GetString(abi);
            }
        }
Ejemplo n.º 4
0
        public void ReadWriteAsVarInt(ref ulong val)
        {
            var value = new VarInt(val);

            ReadWrite(ref value);
            if (!Serializing)
            {
                val = value.ToLong();
            }
        }
Ejemplo n.º 5
0
        public override void ReadWrite(Serialize stream)
        {
            var len = new VarInt((ulong)_DestBytes.Length);

            stream.ReadWrite(ref len);
            if (!stream.Serializing)
            {
                _DestBytes = new byte[len.ToLong()];
            }
            stream.ReadWrite(ref _DestBytes);
        }
Ejemplo n.º 6
0
#pragma warning disable CS0114 // '“UnsignedCharArray.ReadWrite(Serialize)”隐藏继承的成员“SerializeObject.ReadWrite(Serialize)”。若要使当前成员重写该实现,请添加关键字 override。否则,添加关键字 new。
        public void ReadWrite(Serialize stream)
#pragma warning restore CS0114 // '“UnsignedCharArray.ReadWrite(Serialize)”隐藏继承的成员“SerializeObject.ReadWrite(Serialize)”。若要使当前成员重写该实现,请添加关键字 override。否则,添加关键字 new。
        {
            var len = new VarInt((ulong)_DestBytes.Length);

            stream.ReadWrite(ref len);
            if (!stream.Serializing)
            {
                _DestBytes = new byte[len.ToLong()];
            }
            stream.ReadWrite(ref _DestBytes);
        }
Ejemplo n.º 7
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>
        /// <param name="m">The M value to use.</param>
        public GolombRiceFilter(byte[] data, byte p, uint m)
        {
            P = p;
            M = m;
            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);
        }
Ejemplo n.º 8
0
#pragma warning disable CS0114 // '“LuaContract.ReadWrite(Serialize)”隐藏继承的成员“SerializeObject.ReadWrite(Serialize)”。若要使当前成员重写该实现,请添加关键字 override。否则,添加关键字 new。
        public void ReadWrite(Serialize stream)
#pragma warning restore CS0114 // '“LuaContract.ReadWrite(Serialize)”隐藏继承的成员“SerializeObject.ReadWrite(Serialize)”。若要使当前成员重写该实现,请添加关键字 override。否则,添加关键字 new。
        {
            var len = new VarInt((ulong)_DestBytes.Length);

            stream.ReadWrite(ref len);

            byte[] code;
            byte[] memo;

            if (stream.Serializing)
            {
                code = Encoding.UTF8.GetBytes(Code);
                stream.ReadWrite(new VarInt((ulong)code.Length));
                stream.ReadWrite(ref code);

                memo = Encoding.UTF8.GetBytes(Memo);
                stream.ReadWrite(new VarInt((ulong)memo.Length));
                stream.ReadWrite(ref memo);
            }
            else
            {
                var codeLen = new VarInt(0);
                stream.ReadWrite(ref codeLen);
                code = new byte[codeLen.ToLong()];
                stream.ReadWrite(ref code);

                var memoLen = new VarInt(0);
                stream.ReadWrite(ref memoLen);
                memo = new byte[codeLen.ToLong()];
                stream.ReadWrite(ref memo);

                Code = Encoding.UTF8.GetString(code);
                Memo = Encoding.UTF8.GetString(memo);
            }
        }
Ejemplo n.º 9
0
        public void ReadWrite(ref UserId userId)
        {
            if (this.Serializing)
            {
                this.ReadWrite(userId);
            }
            else
            {
                var typeFlag = new VarInt();
                this.ReadWrite(ref typeFlag);

                var len = typeFlag.ToLong();

                if (SerializeFlag.FlagRegIDMin <= len && len <= SerializeFlag.FlagRegIDMax)
                {
                    RegId uid = new RegId();
                    this.ReadWriteAsCompactVarInt(ref uid.Height);
                    this.ReadWriteAsCompactVarInt(ref uid.Index);
                    uid.CompactIntoDest();
                    userId = uid;
                }
                else if (len == SerializeFlag.FlagKeyID)
                {
                    uint160 key = new uint160(0);
                    this.ReadWrite(ref key);
                    userId = new Wicc.Entities.KeyId(key);
                }
                else if (len == SerializeFlag.FlagPubKey)
                {
                    var bytes = new byte[len];
                    this.ReadWrite(ref bytes);
                    userId = new PubKeyId(bytes);
                }
                else if (len == SerializeFlag.FlagNullType)
                {
                    userId = new NullId();
                }
                else
                {
                    //TODO
                    throw new NullReferenceException();
                }
            }
        }
Ejemplo n.º 10
0
        public void ReadWrite(Serialize stream)
        {
            var len = new VarInt((ulong)this.Count);

            stream.ReadWrite(ref len);

            if (stream.Serializing)
            {
                foreach (var item in this)
                {
                    stream.ReadWrite(item);
                }
            }
            else
            {
                for (var i = 0UL; i < len.ToLong(); i++)
                {
                    T t = new T();
                    stream.ReadWrite(t);
                    this.Add(t);
                }
            }
        }
Ejemplo n.º 11
0
        private void ReadWriteArray <T>(ref T[] data) where T : IBitcoinSerializable
        {
            if (data == null && Serializing)
            {
                throw new ArgumentNullException("Impossible to serialize a null array");
            }
            _VarInt.SetValue(data == null ? 0 : (ulong)data.Length);
            ReadWrite(ref _VarInt);

            if (_VarInt.ToLong() > (uint)MaxArraySize)
            {
                throw new ArgumentOutOfRangeException("Array size not big");
            }
            if (!Serializing)
            {
                data = new T[_VarInt.ToLong()];
            }
            for (int i = 0; i < data.Length; i++)
            {
                T obj = data[i];
                ReadWrite(ref obj);
                data[i] = obj;
            }
        }