public virtual string ReadString() { Span <byte> buffer = new byte[VarInt.Read(this)]; Read(buffer); return(Encoding.UTF8.GetString(buffer)); }
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)); }
public virtual string[] ReadStringArray() { string[] buffer = new string[VarInt.Read(this)]; for (int i = 0; i < buffer.Length; i++) { buffer[i] = ReadString(); } return(buffer); }
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); } } }
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(); }
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); }
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); }
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(); }
public static ReadOnlySpan <byte> ReadVarInt(this ReadOnlySpan <byte> span, out int varInt) { varInt = VarInt.Read(span, out int offset); return(span.Slice(offset)); }
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)); }
public static int AsVarInt(this ReadOnlySpan <byte> span) => VarInt.Read(span);
/// <summary>获取数据包的长度</summary> public static int GetPacketLength(Socket tcp) => VarInt.Read(tcp);
public virtual byte[] ReadByteArray() { byte[] buffer = new byte[VarInt.Read(this)]; Read(buffer); return(buffer); }
public virtual int ReadVarInt() { return(VarInt.Read(this)); }