Пример #1
0
        public virtual string ReadString()
        {
            Span <byte> buffer = new byte[VarInt.Read(this)];

            Read(buffer);
            return(Encoding.UTF8.GetString(buffer));
        }
Пример #2
0
        public static int AsVarInt(this ReadOnlySpan <byte> span, out ReadOnlySpan <byte> outSpan)
        {
            int result = VarInt.Read(span, out int offset);

            outSpan = span.Slice(offset);
            return(result);
        }
Пример #3
0
            protected void ReadPayload(BinaryReader reader)
            {
                Value = new Money(reader.ReadInt64(), "BTC");

                UInt64 scriptLength = VarInt.Read(reader).Value;

                ScriptPubKey = new Script(reader.ReadBytes((int)scriptLength));
            }
Пример #4
0
 public virtual string[] ReadStringArray()
 {
     string[] buffer = new string[VarInt.Read(this)];
     for (int i = 0; i < buffer.Length; i++)
     {
         buffer[i] = ReadString();
     }
     return(buffer);
 }
Пример #5
0
 public void Read()
 {
     foreach (var number in Numbers)
     {
         using (BinaryReader reader = new BinaryReader(new MemoryStream(number.Item1))) {
             Assert.AreEqual(number.Item2, VarInt.Read(reader).Value);
         }
     }
 }
Пример #6
0
        public static int ReadVarInt(List <byte> cache, int offset, out int count, bool readOnly = false)
        {
            int result = VarInt.Read(cache, offset, out int length);

            count = length + offset;
            if (!readOnly)
            {
                cache.RemoveRange(offset, length);
            }
            return(result);
        }
Пример #7
0
            protected void ReadPayload(BinaryReader reader)
            {
                PrevTransactionHashBytes = reader.ReadBytes(32);
                OutpointIndex            = reader.ReadUInt32();

                UInt64 scriptLength = VarInt.Read(reader).Value;

                ScriptSig = new Script(reader.ReadBytes((int)scriptLength));

                Sequence = reader.ReadUInt32();
            }
Пример #8
0
        public static int[] AsVarIntArray(this ReadOnlySpan <byte> span, out ReadOnlySpan <byte> outSpan, int arrayLength)
        {
            int[] array  = new int[arrayLength];
            int   offset = 0;

            for (int i = 0; i < array.Length; i++)
            {
                array[i] = VarInt.Read(span.Slice(offset), out offset);
            }
            outSpan = span.Slice(offset);
            return(array);
        }
Пример #9
0
        public static Packet ReceivePacket(Socket tcp, int compressionThreshold)
        {
            Packet recPacket    = new Packet();
            int    PacketLength = VarInt.Read(tcp);

            recPacket.WriteBytes(ReceiveData(0, PacketLength, tcp));
            if (compressionThreshold > 0)
            {
                int DataLength = ReadVarInt(recPacket.Data);
                if (DataLength != 0) //如果是0的话就代表这个数据包没有被压缩
                {
                    byte[] uncompressed = ZlibUtils.Decompress(recPacket.Data.ToArray(), DataLength);
                    recPacket.Data.Clear();
                    recPacket.Data.AddRange(uncompressed);
                }
            }
            recPacket.ID = ReadVarInt(recPacket.Data);
            return(recPacket);
        }
Пример #10
0
        public override void ReadPayload(BinaryReader reader)
        {
            Version = reader.ReadUInt32();

            UInt64 inputCount = VarInt.Read(reader).Value;

            for (ulong i = 0; i < inputCount; i++)
            {
                Inputs.Add(Input.Read(reader, this, (UInt32)i));
            }

            UInt64 outputCount = VarInt.Read(reader).Value;

            for (ulong i = 0; i < outputCount; i++)
            {
                Outputs.Add(Output.Read(reader, this, (UInt32)i));
            }

            LockTime = reader.ReadUInt32();
        }
Пример #11
0
 public static ReadOnlySpan <byte> ReadVarInt(this ReadOnlySpan <byte> span, out int varInt)
 {
     varInt = VarInt.Read(span, out int offset);
     return(span.Slice(offset));
 }
Пример #12
0
        public static byte[] AsByteArray(this ReadOnlySpan <byte> span, out ReadOnlySpan <byte> outSpan)
        {
            int length = VarInt.Read(span, out int offset);

            return(AsByteArray(span.Slice(offset, length), out outSpan, length));
        }
Пример #13
0
 public static int AsVarInt(this ReadOnlySpan <byte> span) => VarInt.Read(span);
Пример #14
0
 /// <summary>获取数据包的长度</summary>
 public static int GetPacketLength(Socket tcp) => VarInt.Read(tcp);
Пример #15
0
 public virtual byte[] ReadByteArray()
 {
     byte[] buffer = new byte[VarInt.Read(this)];
     Read(buffer);
     return(buffer);
 }
Пример #16
0
 public virtual int ReadVarInt()
 {
     return(VarInt.Read(this));
 }