コード例 #1
0
 private void ReadWriteArray(ref byte[] data)
 {
     if (data == null && Serializing)
     {
         throw new ArgumentNullException("Impossible to serialize a null array");
     }
     if (Serializing)
     {
         var len = data == null ? 0 : (ulong)data.Length;
         if (len > (uint)MaxArraySize)
         {
             throw new ArgumentOutOfRangeException("Array size too big");
         }
         VarInt.StaticWrite(this, len);
         if (len == 0)
         {
             return;
         }
     }
     else
     {
         var len = VarInt.StaticRead(this);
         if (len > (uint)MaxArraySize)
         {
             throw new ArgumentOutOfRangeException("Array size too big");
         }
         data = new byte[len];
     }
     this.ReadWriteBytes(ref data);
 }
コード例 #2
0
 private void ReadWriteArray(ref ushort[] data)
 {
     if (data == null && Serializing)
     {
         throw new ArgumentNullException("Impossible to serialize a null array");
     }
     if (Serializing)
     {
         var len = data == null ? 0 : (ulong)data.Length;
         if (len > (uint)MaxArraySize)
         {
             throw new ArgumentOutOfRangeException("Array size too big");
         }
         VarInt.StaticWrite(this, len);
         if (len == 0)
         {
             return;
         }
     }
     else
     {
         var len = VarInt.StaticRead(this);
         if (len > (uint)MaxArraySize)
         {
             throw new ArgumentOutOfRangeException("Array size too big");
         }
         data = new ushort[len];
     }
     for (int i = 0; i < data.Length; i++)
     {
         ushort obj = data[i];
         ReadWrite(ref obj);
         data[i] = obj;
     }
 }
コード例 #3
0
 public void ReadWriteAsVarInt(ref ulong val)
 {
     if (Serializing)
     {
         VarInt.StaticWrite(this, val);
     }
     else
     {
         val = VarInt.StaticRead(this);
     }
 }
コード例 #4
0
 public void ReadWriteAsVarInt(ref uint val)
 {
     if (Serializing)
     {
         VarInt.StaticWrite(this, val);
     }
     else
     {
         val = (uint)Math.Min(uint.MaxValue, VarInt.StaticRead(this));
     }
 }
コード例 #5
0
        public void ReadWrite(ref TxOutList list)
        {
            int listLen = 0;

            if (Serializing)
            {
                var len = list == null ? 0 : (ulong)list.Count;
                if (len > (uint)MaxArraySize)
                {
                    throw new ArgumentOutOfRangeException("Array size too big");
                }
                VarInt.StaticWrite(this, len);
                if (len == 0)
                {
                    return;
                }
                listLen = (int)len;
                foreach (var obj in list)
                {
                    ReadWrite(obj);
                }
            }
            else
            {
                var len = VarInt.StaticRead(this);
                if (len > (uint)MaxArraySize)
                {
                    throw new ArgumentOutOfRangeException("Array size too big");
                }
                listLen = (int)len;
                list    = new TxOutList(listLen);
                for (int i = 0; i < listLen; i++)
                {
                    TxOut obj = default;
                    ReadWrite(ref obj);
                    list.Add(obj);
                }
            }
        }