public static VersionPayload DecodeVersionPayload(Stream stream, int payloadLength) { using (var reader = new BinaryReader(stream, Encoding.ASCII, leaveOpen: true)) { var position = stream.Position; var versionPayload = new VersionPayload ( ProtocolVersion: reader.Read4Bytes(), ServicesBitfield: reader.Read8Bytes(), UnixTime: reader.Read8Bytes(), RemoteAddress: DecodeNetworkAddress(stream), LocalAddress: DecodeNetworkAddress(stream), Nonce: reader.Read8Bytes(), UserAgent: reader.ReadVarString(), StartBlockHeight: reader.Read4Bytes(), Relay: false ); var readCount = stream.Position - position; if (versionPayload.ProtocolVersion >= VersionPayload.RELAY_VERSION && payloadLength - readCount == 1) { versionPayload = versionPayload.With(Relay: reader.ReadBool()); } return(versionPayload); } }
public static VersionPayload DecodeVersionPayload(BinaryReader reader, int payloadLength) { var position = reader.BaseStream.Position; var versionPayload = new VersionPayload ( ProtocolVersion: reader.ReadUInt32(), ServicesBitfield: reader.ReadUInt64(), Time: DateTimeOffset.FromUnixTimeSeconds((long)reader.ReadUInt64()), RemoteAddress: DecodeNetworkAddress(reader), LocalAddress: DecodeNetworkAddress(reader), Nonce: reader.ReadUInt64(), UserAgent: reader.ReadVarString(), StartBlockHeight: reader.ReadUInt32(), Relay: false ); var readCount = reader.BaseStream.Position - position; if (versionPayload.ProtocolVersion >= VersionPayload.RELAY_VERSION && payloadLength - readCount == 1) { versionPayload = versionPayload.With(Relay: reader.ReadBool()); } return(versionPayload); }
public static VersionPayload DecodeVersionPayload(Stream stream, int payloadLength) { using (var reader = new BinaryReader(stream, Encoding.ASCII, leaveOpen: true)) { var position = stream.Position; var versionPayload = new VersionPayload ( ProtocolVersion: reader.Read4Bytes(), ServicesBitfield: reader.Read8Bytes(), UnixTime: reader.Read8Bytes(), RemoteAddress: DecodeNetworkAddress(stream), LocalAddress: DecodeNetworkAddress(stream), Nonce: reader.Read8Bytes(), UserAgent: reader.ReadVarString(), StartBlockHeight: reader.Read4Bytes(), Relay: false ); var readCount = stream.Position - position; if (versionPayload.ProtocolVersion >= VersionPayload.RELAY_VERSION && payloadLength - readCount == 1) versionPayload = versionPayload.With(Relay: reader.ReadBool()); return versionPayload; } }