public static Cell ReadFrom(Stream stream, int protocolVersion) { using (var reader = new BEBinaryReader(stream)) { var circuitId = (protocolVersion >= 4) ? (uint)reader.ReadUInt32() : (uint)reader.ReadUInt16(); var command = (CommandType)reader.ReadByte(); var cell = CreateFromCommand(circuitId, command); cell.ReadPayload(reader); return(cell); } }
protected override void ReadPayload(BinaryReader reader) { var payload = reader.ReadBytes(MaxPayloadSize); using var preader = new BEBinaryReader(new MemoryStream(payload)); Timestamp = DateTimeOffset.FromUnixTimeSeconds(preader.ReadUInt32()); MyIPAddress = preader.ReadIPAddress(); var numOfAddresses = preader.ReadByte(); for (var i = 0; i < numOfAddresses; i++) { var remote = preader.ReadIPAddress(); if (remote != null) { OtherIPs.Add(remote); } else { break; } } }