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

            Read(buffer);
            return(Encoding.UTF8.GetString(buffer));
        }
Example #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);
        }
            protected void ReadPayload(BinaryReader reader)
            {
                Value = new Money(reader.ReadInt64(), "BTC");

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

                ScriptPubKey = new Script(reader.ReadBytes((int)scriptLength));
            }
Example #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);
 }
Example #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);
         }
     }
 }
Example #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);
        }
            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();
            }
Example #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);
        }
Example #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);
        }
Example #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();
        }
Example #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));
 }
Example #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));
        }
Example #13
0
 public static int AsVarInt(this ReadOnlySpan <byte> span) => VarInt.Read(span);
Example #14
0
 /// <summary>获取数据包的长度</summary>
 public static int GetPacketLength(Socket tcp) => VarInt.Read(tcp);
Example #15
0
 public virtual byte[] ReadByteArray()
 {
     byte[] buffer = new byte[VarInt.Read(this)];
     Read(buffer);
     return(buffer);
 }
Example #16
0
 public virtual int ReadVarInt()
 {
     return(VarInt.Read(this));
 }