private static void ReadWriteArray(this BitcoinStream bitcoinStream, ref byte[] data) { if (data == null && bitcoinStream.Serializing) { throw new ArgumentNullException("Impossible to serialize a null array"); } if (bitcoinStream.Serializing) { var len = data == null ? 0 : (ulong)data.Length; if (len > (uint)bitcoinStream.MaxArraySize) { throw new ArgumentOutOfRangeException("Array size too big"); } VarInt.StaticWrite(bitcoinStream, len); if (len == 0) { return; } } else { var len = VarInt.StaticRead(bitcoinStream); if (len > (uint)bitcoinStream.MaxArraySize) { throw new ArgumentOutOfRangeException("Array size too big"); } data = new byte[len]; } bitcoinStream.ReadWriteBytes(ref data); }
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; } }
public void ReadWriteAsVarInt(ref ulong val) { if (Serializing) { VarInt.StaticWrite(this, val); } else { val = VarInt.StaticRead(this); } }
public void ReadWriteAsVarInt(ref uint val) { if (Serializing) { VarInt.StaticWrite(this, val); } else { val = (uint)Math.Min(uint.MaxValue, VarInt.StaticRead(this)); } }